Counter with History - Lit Typing CST Test
Loading…
Counter with History — Lit Code
Tracks increment/decrement history.
import { LitElement, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
@customElement('lit-history-counter')
export class LitHistoryCounter extends LitElement {
@state() count = 0;
@state() history = [];
render() {
return html`<div>
<h2>Counter: ${this.count}</h2>
<div>History: ${this.history.join(', ')}</div>
<button @click=${() => { this.count++; this.history = [...this.history, 'Increment']; }}>+</button>
<button @click=${() => { this.count--; this.history = [...this.history, 'Decrement']; }}>-</button>
<button @click=${() => { this.count = 0; this.history = [...this.history, 'Reset']; }}>Reset</button>
</div>`;
}
}Lit Language Guide
Lit is a lightweight, fast, web-component-focused library for building reactive and declarative UI using standard web platform features. It emphasizes interoperability, small bundle sizes, and declarative templating with lit-html.
Primary Use Cases
- ▸Reusable web components
- ▸Design systems
- ▸Embeddable widgets for websites
- ▸Progressive enhancement projects
- ▸Small, high-performance UI components
Notable Features
- ▸Reactive properties
- ▸Declarative templates via lit-html
- ▸Scoped styles with CSS
- ▸Lightweight & fast
- ▸Full standards-compliant Web Components
Origin & Creator
Created by Google’s Polymer team, originally derived from lit-html and Polymer projects. First public release in 2019 as a modern, lightweight web component library.
Industrial Note
Lit excels in projects where web standards, framework interoperability, or lightweight, fast UI components are required, such as design systems, component libraries, and embeddable widgets.