Socket
Socket
Sign inDemoInstall

lit

Package Overview
Dependencies
5
Maintainers
9
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lit

A library for building fast, lightweight web components


Version published
Weekly downloads
1.7M
increased by8.11%
Maintainers
9
Install size
2.66 MB
Created
Weekly downloads
 

Package description

What is lit?

The lit npm package is a simple and fast library for building web components and web applications. It allows developers to create reusable, encapsulated, and interactive elements using modern JavaScript and Web Component standards. Lit is designed to be lightweight and efficient, focusing on speed and minimal overhead.

What are lit's main functionalities?

Creating Web Components

This feature allows developers to create custom web components using the LitElement base class. The example demonstrates defining a new element with a simple style and rendering method.

import { LitElement, html, css } from 'lit';

class MyElement extends LitElement {
  static styles = css`p { color: blue; }`;

  render() {
    return html`<p>Hello, world!</p>`;
  }
}
customElements.define('my-element', MyElement);

Reactive Properties

This feature showcases Lit's reactive property system. The example includes a counter component that updates its display whenever the 'count' property changes.

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

class MyCounter extends LitElement {
  @property({ type: Number }) count = 0;

  render() {
    return html`
      <button @click=${this._increment}>Increment</button>
      <span>${this.count}</span>
    `;
  }

  _increment() {
    this.count++;
  }
}
customElements.define('my-counter', MyCounter);

Styling Components

This feature demonstrates how to apply CSS styles to a Lit component. The example shows defining styles for the component itself and its internal elements.

import { LitElement, html, css } from 'lit';

class StyledElement extends LitElement {
  static styles = css`
    :host {
      display: block;
      border: 1px solid black;
      padding: 16px;
      max-width: 200px;
    }
    .highlight {
      color: red;
    }
  `;

  render() {
    return html`<div class='highlight'>Styled Content</div>`;
  }
}
customElements.define('styled-element', StyledElement);

Other packages similar to lit

Readme

Source
Lit

Simple. Fast. Web Components.

Build Status Published on npm Join our Discord Mentioned in Awesome Lit

Lit is a simple library for building fast, lightweight web components.

At Lit's core is a boilerplate-killing component base class that provides reactive state, scoped styles, and a declarative template system that's tiny, fast and expressive.

About this release

Lit 3.0 has very few breaking changes from Lit 2.0:

  • Drops support for IE11
  • Published as ES2021
  • Removes a couple of deprecated Lit 1.x APIs

Lit 3.0 should require no changes to upgrade from Lit 2.0 for the vast majority of users. Most apps and libraries will be able to extend their npm version ranges to include both 2.x and 3.x, like "^2.7.0 || ^3.0.0".

Lit 2.x and 3.0 are interoperable: templates, base classes, directives, decorators, etc., from one version of Lit will work with those from another.

Please file any issues you find on our issue tracker.

Documentation

See the full documentation for Lit at lit.dev

Overview

Lit provides developers with just the right tools to build fast web components:

  • A fast declarative HTML template system
  • Reactive property declarations
  • A customizable reactive update lifecycle
  • Easy to use scoped CSS styling

Lit builds on top of standard web components, and makes them easier to write:

import {LitElement, html, css} from 'lit';
import {customElement, property} from 'lit/decorators.js';

// Registers the element
@customElement('my-element')
export class MyElement extends LitElement {
  // Styles are applied to the shadow root and scoped to this element
  static styles = css`
    span {
      color: green;
    }
  `;

  // Creates a reactive property that triggers rendering
  @property()
  mood = 'great';

  // Render the component's DOM by returning a Lit template
  render() {
    return html`Web Components are <span>${this.mood}</span>!`;
  }
}

Once you've defined your component, you can use it anywhere you use HTML:

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

Contributing

Please see CONTRIBUTING.md.

FAQs

Last updated on 15 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc