Scheme Toggle
A sun/moon control that flips the active light/dark scheme.
Live demo
Scheme Toggle is the dark/light switch, and it is an icon-only <xtyle-button> — it composes the button rather than reinventing a control, so it inherits its variants, sizes, focus ring, hover, and mods for free. Inside an <xtyle-theme-scope> it drives the scope, which re-derives the active theme through the engine's inversion so every surface lands where the algorithm places it for the opposite mode.
Standalone, with no scope in sight, it flips :root[data-scheme], persists the choice to localStorage (key storage-key, default xtyle.scheme), and fires an xtyle:scheme-change event. The glyph follows the convention of showing the mode you'd switch to — a sun while dark, a moon while light. light-icon and dark-icon swap either glyph for any named xtyle icon, and reverse flips the convention to show the mode you're currently in (for the contrarians).
When to use
How this component composes with the rest of the set.
Props
8 props, straight from the manifest.
| Prop | Type | Default | Bindings | Description |
|---|---|---|---|---|
Appearance
States
dark
The scheme is dark; the light-face glyph shows (or the dark one under reverse).
light
The scheme is light; the dark-face glyph shows (or the light one under reverse).
reverse
The display is flipped to show the current mode rather than the switch-to mode.
Anatomy
The named parts that make up the component, with their selectors.
control
The composed icon-only <xtyle-button> that flips the scheme on click.
light
The light-face glyph (default a sun), shown while dark unless reverse is set.
dark
The dark-face glyph (default a moon), shown while light unless reverse is set.
Tokens & coverage
What the component consumes, checked live against what the algorithm produces.
Live coverage check against the xtyle-default register
(derive(xtyleDefault, { anchors }) →
coverComponent(manifest, register)). Every token this component
consumes must be a key the algorithm produces.
Accessibility
Code
Standalone, custom icons, and reversed
A bare toggle that flips the document scheme, one with custom glyphs and a reversed display, and one inside a theme scope.
<!-- Standalone: flips :root[data-scheme] and persists the choice -->
<xtyle-scheme-toggle></xtyle-scheme-toggle>
<!-- Custom glyphs (any named xtyle icon) and a reversed display -->
<xtyle-scheme-toggle
light-icon="light-theme--sun-c3--circle-s65-ko--circle-s55-c3---ps-skittles"
dark-icon="dark-theme--circle-c3--circle-x20-y-10-s80-ko---ps-skittles"
reverse
></xtyle-scheme-toggle>
<!-- A toolbar icon: no chrome of its own, so the glyph owns the box -->
<xtyle-scheme-toggle variant="link" icon-size="lg"></xtyle-scheme-toggle>
<!-- Inside a theme scope: drives the scope, which re-derives the active theme -->
<xtyle-theme-scope>
<xtyle-scheme-toggle variant="subtle" label="Switch theme mode"></xtyle-scheme-toggle>
</xtyle-theme-scope>
<script lang="ts">
import { SchemeToggle } from "@xtyle/svelte";
</script>
<SchemeToggle label="Switch theme mode" />
<!-- reversed display on a subtle-variant button -->
<SchemeToggle reverse variant="subtle" />
<!-- custom glyphs: any named xtyle icon -->
<SchemeToggle lightIcon="palette" darkIcon="bookmark" />
<!-- a toolbar icon: chrome-free, so the glyph owns the box -->
<SchemeToggle variant="link" iconSize="lg" />
---
import SchemeToggle from "@xtyle/astro/SchemeToggle.astro";
---
<SchemeToggle label="Switch theme mode" />
<!-- reversed display on a subtle-variant button -->
<SchemeToggle reverse variant="subtle" />
<!-- custom glyphs: any named xtyle icon -->
<SchemeToggle lightIcon="palette" darkIcon="bookmark" />
<!-- a toolbar icon: chrome-free, so the glyph owns the box -->
<SchemeToggle variant="link" iconSize="lg" />