https://github.com/molecule-js/moleculejs
A library for creating fast and reactive Custom Elements
https://github.com/molecule-js/moleculejs
custom-elements declarative frontend lit-html molecule ui webcomponents
Last synced: 6 months ago
JSON representation
A library for creating fast and reactive Custom Elements
- Host: GitHub
- URL: https://github.com/molecule-js/moleculejs
- Owner: Molecule-JS
- License: apache-2.0
- Archived: true
- Created: 2018-05-11T21:23:09.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-02T18:12:01.000Z (about 5 years ago)
- Last Synced: 2025-01-22T12:35:30.729Z (6 months ago)
- Topics: custom-elements, declarative, frontend, lit-html, molecule, ui, webcomponents
- Language: TypeScript
- Homepage: https://moleculejs.org
- Size: 1.22 MB
- Stars: 38
- Watchers: 4
- Forks: 3
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Molecule · [](https://github.com/Molecule-JS/MoleculeJS/blob/master/LICENSE) [](https://codecov.io/gh/Molecule-JS/MoleculeJS) [](https://badge.fury.io/js/%40moleculejs%2Fmolecule) [](https://travis-ci.org/Molecule-JS/MoleculeJS) [](https://greenkeeper.io/) [](https://app.codacy.com/app/DerDrodt/MoleculeJS?utm_source=github.com&utm_medium=referral&utm_content=Molecule-JS/MoleculeJS&utm_campaign=Badge_Grade_Dashboard)
## Overview
Molecule is a JavaScript library for building user interfaces using web components.
It provides several classes from which you can build your Custom Elements
- The Molecule base class. It is agnostic about your actual templatization and rendering function.
- MoleculeLit class which uses the standard functions from [lit-html](https://github.com/PolymerLabs/lit-html) by the Polymer team.
- MoleculeLitExtended uses the extended rendering functions of `lit-html`.## Installation
The `@moleculejs/molecule` package can be installed using npm or yarn:
```bash
npm install --save @moleculejs/molecule
``````bash
yarn add @moleculejs/molecule
```## Documentation
See the full documentation at [MoleculeJS.org](https://moleculejs.org).
## Examples
Let's start with a simple Example:
```js
class HelloWorld extends MoleculeLit.Element {
static get properties() {
return {
name: { type: String, attribute: true, value: 'John Doe' },
};
}
render({ name }) {
html`
Hello ${name}
`;
}
}customElements.define('hello-world', HelloWorld);
```This creates a new Custom Element called `hello-world`, which can now be used anywhere in your application using ``.
This new element will also keep the _property_ `name` in sync with the _attribute_ `name`, meaning that the element will look like this in the DOM:
```html
```
If you change the attribute or the property, both will be kept in sync and the element will be rerendered.
## Contributing
Coming soon!