Color Scheme

Light / dark / system colour-scheme switch for lit-material: a toggle, a persisted setter, and a no-flash boot snippet.

  • 4.2 KB gzipped
  • @lit-material/color-scheme 0.1.3
  • Renders on the server

Example

Install

npm install @lit-material/color-scheme @lit-material/tokens
import "@lit-material/color-scheme";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-color-scheme-toggle>

A button that switches the page between light and dark, built on lit-material-icon-button. It sets the color-scheme attribute on <html> (which @lit-material/tokens reads), remembers the choice in localStorage, and keeps every toggle on the page in sync.

Properties

PropertyAttributeTypeDefaultDescription
cyclecyclebooleanfalseStep light → dark → system instead of toggling light ↔ dark.
storageKeystorage-keynoneDEFAULT_STORAGE_KEYlocalStorage key for the choice.

Events

EventDescription
changeAfter the visitor picks a scheme; detail.scheme is light, dark or auto.

Slots

SlotDescription
light-iconIcon shown while light (default: a sun).
dark-iconIcon shown while dark (default: a moon).
auto-iconIcon shown while following the system, with cycle (default: a half-filled circle).

Source on GitHub npm