Stencil is a compiler for building fast web apps using Web Components.
Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.
Stencil components are just Web Components, so they work in any major framework or with no framework at all.
The following documentation is inspired by this official guide.
To create a new StencilJS component go in the web docker container and in the tinduicomponents folder:
docker exec -it invenio_web_1 bash
cd /code/invenio/tinduicomponents/
and run:
npx stencil generate
It will be asked for the component name (please look the next section) and other option that you can set all as enabled.
At this point the auto-reload should build the component and make it usable (look the proper section below).
If for some reason it is not the case you can build manually with (still in the tinduicomponents folder):
npm run build
All component uses the dash-case and should be prefixed with the tindui-
prefix.
Then it should follow with a category name in order to group all component with a similar purpose e.g.: tindui-button-
Conclude it with the component specific name to distinguish it among all other component in the same cat e.g.: tindui-button-generic
or tindui-button-dropdown
If the component is planned to be used in a specific module or situation please indicate it like: tindui-table-result-globallist
In order to use the tinduicomponents in your html is required to add the following imports:
<script type="module" src="/js/tinduicomponents/tinduicomponents/tinduicomponents.esm.js"></script>
At this point you can refer to the component using its tag name (that you can find in the auto-generate .tsx file):
<alert-box alert-type="success" message="Component successfully created."></alert-box>
From the modules/tinduicomponents folder:
npm install <yourpackage> --save
Stencil component official guide.
Using bootstrap css inside components: guide
Please read this article before writing a new component: guide
- Inline styles needs to be provided as an object:
let styles = {
width: "45%",
minWidth: "2em",
};
<div style={styles}></div>;
- Do not set State variables in the render() method.
- For arrays, the standard mutable array operations such as push() and unshift() won't work.
- Define onEvent handler function with the syntax
onEvent = () => {}
. In this way the componentthis
would be bound automatically.