Repository with examples and design patterns for building web components using the LitElement base class, and rendering templates using lit-html.
This repository is intended as a starting point for all people who want to write web components with LitElement. Some special sections are added for people migrating from PolymerElement.
You can view the code of the examples by browsing through the src folder on github. The examples are divided into categories of complexity, and are ordered. Concepts are introduced one by one, so that you only see one new concept per example.
All the examples are working code, so you can clone the repository and run npm install
+ npm start
.
People starting with LitElement, especially those coming from PolymerElement, often have these questions:
- How to set default properties:
- How to handle conditional logic (dom-if from PolymerElement):
- How to repeat templates (dom-repeat from PolymerElement):
- How to compute properties (computed properties from PolymerElement)
- How to observe property changes (property observers from PolymerElement)
- How to render templates from external sources, such as a back-end API or html files imported through webpack
- How to separate CSS, HTML and JS in different files:
- How to reflect properties to attributes:
- Use https://github.com/web-padawan/awesome-lit-html as a starting pointer for further documentation.
- Use https://github.com/thepassle/create-lit-app as a reference for building a lit-html app with preset and ready to use Redux and Webpack configurations.
This project is a community effort. The authors of this repository are not affiliated with Google or the Polymer team. Because LitElement and lit-html are still in early stages of development, best practices and examples will change and evolve over time.
Contributions are appreciated, feel free to submit issues and PRs.