Skip to content

Latest commit

 

History

History
52 lines (30 loc) · 3.81 KB

README.md

File metadata and controls

52 lines (30 loc) · 3.81 KB

Storybook Built With Stencil

@stencila/components

Stencil

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.

Naming Components

Web Component tags may not be CamelCased and they must include a hyphen (-) in the name. Please follow the pattern of <stencila-(component-type)>, for example <stencila-tab-list>.

Using these components

Add to your project

There are two ways to load these components into your project, a script tag in an HTML file, or as a Node module.

Script tag

  • Put the following script tags in the head of your HTML document:
<script type="module" src="https://unpkg.com/@stencila/components@latest/dist/stencila-components/stencila-components.esm.js"></script>
<script type="text/javascript" nomodule="true" src="https://unpkg.com/@stencila/components@latest/dist/stencila-components/stencila-components.js"></script>
  • Then you can use the element anywhere in your HTML, HTML template, JSX, etc.

In modern browsers supporting the module attribute, only the components used on the page will be requested and lazy-loaded, keeping the page size low.

Node module

  • Run npm install @stencila/components --save
  • Import the package in your main/top-level file: import '@stencila/components'
  • Stencil will automatically setup the lazy-loading capabilities for the Stencil library. Then you can use the element anywhere in your template, JSX, HTML etc.

Using and customizing components

The best reference for how to use and combine these components is our component library. The source code for the stories is written using simple lit-html syntax and can be found here.

For general overview of working with WebComponents using plain JavaScript, the StencilJS website provides a good introduction.

Integrating with other web frameworks

Please visit the StencilJS documentation for up to date documentation.