1 | # lit-element
|
2 | Implements [lit-html](https://github.com/PolymerLabs/lit-html) via a LitElement class. Made for custom Elements.
|
3 |
|
4 | ## Installation
|
5 |
|
6 | You can get it through npm or yarn
|
7 |
|
8 | ```
|
9 | npm install lit-element
|
10 | ```
|
11 | ```
|
12 | yarn add lit-element
|
13 | ```
|
14 |
|
15 | ## Default Usage
|
16 |
|
17 | ```javascript
|
18 | // import html from lit-html
|
19 | import {html} from '../node-modules/lit-html/lit-html.js'
|
20 |
|
21 | // import lit-element
|
22 | import {LitElement} from '../node_modules/lit-element/lit-element.min.js'
|
23 |
|
24 | // define Custom Element
|
25 | class MyElement extends LitElement(HTMLElement) {
|
26 |
|
27 | // define properties similiar to Polymer 2/3
|
28 | static get properties() {
|
29 | return {
|
30 | title: String,
|
31 | body: {
|
32 | type: String,
|
33 | value: 'That is a cool LitElement'
|
34 | }
|
35 | }
|
36 | }
|
37 |
|
38 | // define your template in render
|
39 | render() {
|
40 | this.title = 'This is lit';
|
41 | return html`
|
42 | <h1 id="title">${this.title}</h1>
|
43 | <p>${this.body}</h1>
|
44 | `;
|
45 | }
|
46 |
|
47 | // If you want work done after the first render, like accessing elements with ids, do it here
|
48 | afterFirstRender() {
|
49 |
|
50 | // access the element with id 'title'
|
51 | this.$.title.classList.add('title--main')
|
52 | }
|
53 | }
|
54 | ```
|
55 |
|
56 | ## Notes
|
57 |
|
58 | - This Element does not use Polymer, just Polymer-like syntax for properties.
|
59 | - Currently only `reflectToAttribute` and `value` are supported for properties. |
\ | No newline at end of file |