Giter Site home page Giter Site logo

yangxin1994 / lit-element Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lit/lit-element

0.0 0.0 0.0 5.88 MB

LEGACY REPO. This repository is for maintenance of the legacy LitElement library. The LitElement base class is now part of the Lit library, which is developed in the lit monorepo.

Home Page: https://lit-element.polymer-project.org

License: BSD 3-Clause "New" or "Revised" License

TypeScript 70.98% HTML 1.57% JavaScript 27.45%

lit-element's Introduction

LitElement

LitElement is simple base class for creating fast, lightweight web components with lit-html.

Build Status Published on npm Join our Slack Mentioned in Awesome lit-html

Looking for Lit?

LitElement is now part of the Lit library monorepo. Lit 2 includes lit-html 2.x and LitElement 3.x.

This repo contains the code for LitElement 2.x.

Documentation

For LitElement 2.x documentation, see the legacy documentation site.

For Lit 2, the next version of LitElement and lit-html, see the Lit site.

Overview

LitElement uses lit-html to render into the element's Shadow DOM and adds API to help manage element properties and attributes. LitElement reacts to changes in properties and renders declaratively using lit-html. See the lit-html guide for additional information on how to create templates for lit-element.

import {LitElement, html, css, customElement, property} from 'lit-element';

// This decorator defines the element.
@customElement('my-element')
export class MyElement extends LitElement {

  // This decorator creates a property accessor that triggers rendering and
  // an observed attribute.
  @property()
  mood = 'great';

  static styles = css`
    span {
      color: green;
    }`;

  // Render element DOM by returning a `lit-html` template.
  render() {
    return html`Web Components are <span>${this.mood}</span>!`;
  }

}
<my-element mood="awesome"></my-element>

Note, this example uses decorators to create properties. Decorators are a proposed standard currently available in TypeScript or Babel. LitElement also supports a vanilla JavaScript method of declaring reactive properties.

Examples

Installation

From inside your project folder, run:

$ npm install lit-element

To install the web components polyfills needed for older browsers:

$ npm i -D @webcomponents/webcomponentsjs

Supported Browsers

The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also supported.

Edge and Internet Explorer 11 require the web components polyfills.

Forward Compatibility With Lit 2

Lit 2 (LitElement 3.0) has a few breaking changes and deprecations that have been back-ported to LitElement 2.5 in order to ease upgrading.

To prepare for Lit 2, update these APIs:

LitElement 2.4 LitElement 2.5/Lit 2
Decorator imports:
import {customElement} from 'lit-element';
import {customElement} from 'lit-element/decorators.js';
@internalProperty() foo; @state() foo;
Override _getUpdateComplete() Override getUpdateComplete()
Shadow root options:
Override createRenderRoot().
Add static shadowRootOptions.
import {UpdatingElement} from 'lit-element'; import {ReactiveElement} from 'lit-element';

Contributing

Please see CONTRIBUTING.md.

lit-element's People

Contributors

abdonrd avatar abraham avatar aomarks avatar bicknellr avatar christian24 avatar dakmor avatar danielbarion avatar dependabot[bot] avatar dfreedm avatar djlauk avatar e111077 avatar felixschusi avatar graynorton avatar jordanaustin avatar justinfagnani avatar keanulee avatar kevinpschaaf avatar larsdenbakker avatar ljmerza avatar lostinbrittany avatar nicolejadeyee avatar rictic avatar samthor avatar sorvell avatar timvdlippe avatar toddpress avatar usergenic avatar web-padawan avatar westbrook avatar yuinchien avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.