Bay.js
An easy to use, lightweight library for web-components.
README
bay.js
An easy to use, lightweight library for web-components. It doesn't need a build step but can be included in a build step if you want to. It's a great way to create reusable components for your projects. It's available as a NPM package and doesn't use any dependencies and is 4kb minified + gzipped. It also doesn't use eval or new Function so can be used in strict CSP polices without a build step. For documentation and demos go to Bayjs.org.
If you wish to support this project please buy me a coffee. ☕
Installation
Bay.js can be used via a script tag or importing as a module.
Script tag:
- ```html
- <script src="//unpkg.com/@dunks1980/bay.js/bay.min.js"></script>
- ```
Module Script tag:
- ```html
- <script type="module" src="main.js"></script>
- ```
- ```javascript
- // In main.js
- import bay from '//unpkg.com/@dunks1980/bay.js/bay.mjs';
- bay();
- ```
Module NPM:
- ```javascript
- npm i @dunks1980/bay.js
- import bay from '@dunks1980/bay.js';
- bay();
- ```
Usage
- ```html
- <template id="my-template">
- <h1>${this.message}</h1>
- </template>
- <my-component bay="#my-template" message="Hello world!"></my-component>
- ```
- ```html
- <my-component bay="/url/to/my/components.html" message="Hello world!"></my-component>
- !-- or -->
- <my-component bay="/url/to/my/components.php" message="Hello world!"></my-component>
- ```
- ```html
- !-- in component file -->
- <h1>${this.message}</h1>
- ```
- ```js
- import my_component from "./../component_imports/my_component.html?raw";
- import bay from "@dunks1980/bay.js";
- bay();
- bay.create("my-component", my_component, ["message"]);
- ```
- ```html
- !-- Anywhere in the HTML including other components -->
- <my-component message="Hello world!"></my-component>
- ```