1. Home
  2. /
  3. Lit
  4. /
  5. Full Featured Counter

Full Featured Counter - Lit Typing CST Test

Loading…

Full Featured Counter — Lit Code

Combines step increment, max limit, auto-reset, history, auto-increment, and theme toggle.

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

@customElement('lit-full-counter')
export class LitFullCounter extends LitElement {
	@state() count = 0;
	@state() history = [];
	@state() isDark = false;
	step = 2;
	max = 10;
	connectedCallback() { super.connectedCallback(); this.interval = setInterval(()=>{ let c=this.count+this.step; if(c>this.max)c=0; this.count=c; this.history=[...this.history,'Auto Increment']; },1000); }
	disconnectedCallback() { clearInterval(this.interval); super.disconnectedCallback(); }
	static styles = css`.dark-theme{background:#222;color:#eee}.light-theme{background:#fff;color:#000}`;
	render() { return html`<div class=${this.isDark?'dark-theme':'light-theme'}>
	<h2>Counter: ${this.count}</h2>
	<div>History: ${this.history.join(', ')}</div>
	<button @click=${()=>{ this.count+=this.step; this.history=[...this.history,'Increment']; }}>+</button>
	<button @click=${()=>{ this.count-=this.step; this.history=[...this.history,'Decrement']; }}>-</button>
	<button @click=${()=>{ this.count=0; this.history=[...this.history,'Reset']; }}>Reset</button>
	<button @click=${()=>this.isDark=!this.isDark}>Toggle Theme</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.

More Lit Typing Exercises

Lit Counter ComponentLit Counter with Step IncrementLit Counter with Max LimitLit Counter with Auto-ResetLit Counter with HistoryLit Counter with Dark Mode OnlyLit Counter with Auto-IncrementLit Counter with Conditional Theme

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher