JSPM

  • Created
  • Published
  • Downloads 2493756
  • Score
    100M100P100Q192379F
  • License MIT

Implements lit-html via a LitElement class. Made for custom Elements.

Package Exports

  • lit-element
  • lit-element/lit-element
  • lit-element/lit-element.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lit-element) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lit-element

Implements lit-html via a LitElement class. Made for custom Elements.

Build Status

Installation

You can get it through npm or yarn

npm install lit-element
yarn add lit-element

Default Usage

// import html from lit-html
import {html} from '../node-modules/lit-html/lit-html.js'

// import lit-element
import {LitElement} from '../node_modules/lit-element/lit-element.min.js'

// define Custom Element
class MyElement extends LitElement(HTMLElement) {

    // define properties similiar to Polymer 2/3
    static get properties() {
        return {
            title: String,
            body: {
                type: String,
                value: 'That is a cool LitElement',
                observer: '_bodyChanged',
                reflectToAttribute: true
            }
        }
    }
    
    // define your template in render
    render() {
        this.title = 'This is lit';
        return html`
            <h1 id="title">${this.title}</h1>
            <p>${this.body}</h1>
        `;
    }

    // observer callback
    _bodyChanged(newValue) {
        console.log(`Body updated to ${newValue}`);
    }

    // If you want work done after the first render, like accessing elements with ids, do it here
    afterFirstRender() {
        
        // access the element with id 'title'
        this.$.title.classList.add('title--main')
    }
}

Notes

  • This Element does not use Polymer, just Polymer-like syntax for properties.
  • Currently only type, reflectToAttribute, observer and value are supported for properties.