|
1 |
| -# stencil-container |
2 |
| -A stencil component that dispalys child element with conditional data. |
| 1 | +# Stencil Container |
| 2 | +A stencil component that displays child elements with conditional data. |
| 3 | + |
| 4 | +## Using this component |
| 5 | + |
| 6 | +### Script tag |
| 7 | + |
| 8 | +- Put `<script src='https://unpkg.com/stencil-container@latest/dist/stencil-container.js'></script>` in the head of your index.html |
| 9 | +- Then you can use the element `<st-container>` anywhere in your template, JSX, html etc |
| 10 | + |
| 11 | +### Node Modules |
| 12 | +- Run `npm install stencil-container --save` |
| 13 | +- Put a script tag similar to this `<script src='node_modules/stencil-container/dist/stencil-container.js'></script>` in the head of your index.html |
| 14 | +- Then you can use the element `<st-container>` anywhere in your template, JSX, html etc |
| 15 | + |
| 16 | +### In a stencil-starter app |
| 17 | +- Run `npm install stencil-container --save` |
| 18 | +- You might need to import the npm package in a tsx file with `import { } from 'stencil-container';` |
| 19 | +- Then you can use the element `<st-container>` anywhere in your template, JSX, html etc |
| 20 | + |
| 21 | +## Parameters |
| 22 | + |
| 23 | +### ng-if |
| 24 | + |
| 25 | +An expression that is either true or false. |
| 26 | + |
| 27 | +## Examples |
| 28 | + |
| 29 | +### Plain html |
| 30 | + |
| 31 | +`<st-container st-if="false"><div>false?</div></st-container>` |
| 32 | +Will not show the child elements content. |
| 33 | + |
| 34 | +`<st-container st-if="true"><div>true?</div></st-container>` |
| 35 | +Will show the child elements content. |
| 36 | + |
| 37 | +`<st-container><div>container test?</div></st-container>` |
| 38 | +Without the st-if parameter it assumes the content should be shown. |
| 39 | + |
| 40 | +### Javascript variables |
| 41 | + |
| 42 | +```html |
| 43 | +<script> |
| 44 | + var numberOne = 1; |
| 45 | + var numberTwo = 2; |
| 46 | + var booleanTrue = true; |
| 47 | + var booleanFalse = false; |
| 48 | +</script> |
| 49 | + |
| 50 | +<st-container st-if="booleanTrue"><div>Will be shown!</div></st-container> |
| 51 | +<st-container st-if="booleanFalse"><div>Will not be shown!</div></st-container> |
| 52 | +<st-container st-if="numberOne"><div>Will be shown!</div></st-container> |
| 53 | +<st-container st-if="numberTwo"><div>Will be shown!</div></st-container> |
| 54 | +<st-container st-if="numberOne == numberOne"><div>Will be shown!</div></st-container> |
| 55 | +<st-container st-if="numberOne == numberTwo"><div>Will not be shown!</div></st-container> |
| 56 | +``` |
| 57 | + |
| 58 | +### JSX variables |
| 59 | + |
| 60 | +```jsx |
| 61 | +export class MyApp { |
| 62 | + private expression1 = '1 == 1'; |
| 63 | + private expression2 = '1 == 2'; |
| 64 | + |
| 65 | + render() { |
| 66 | + return ( |
| 67 | + <div> |
| 68 | + <st-container st-if={this.expression1}><div>Will be shown!</div></st-container> |
| 69 | + <st-container st-if={this.expression2}><div>Will not be shown!</div></st-container> |
| 70 | + </div> |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### Angular bindings |
| 77 | + |
| 78 | +Let me know if it works! :) |
| 79 | + |
| 80 | +## Development |
| 81 | + |
| 82 | +Installation: |
| 83 | +```bash |
| 84 | +git clone https://github.com/nerdic-coder/stencil-container.git stencil-container |
| 85 | +cd stencil-container |
| 86 | +npm install |
| 87 | +``` |
| 88 | + |
| 89 | +Running: |
| 90 | +```bash |
| 91 | +npm start |
| 92 | +``` |
| 93 | + |
| 94 | +Tests: |
| 95 | +```bash |
| 96 | +npm run test |
| 97 | +``` |
| 98 | + |
| 99 | +Watchable tests: |
| 100 | +```bash |
| 101 | +npm run test.watch |
| 102 | +``` |
| 103 | + |
| 104 | +All feedback are welcome! |
0 commit comments