Skip to content

hd-toggle

Live preview

<hd-toggle bind="{{ cap.onoff }}" label="{{ device.name }}"></hd-toggle>

Attributes and example

hd-toggle

on change

An on/off switch bound to a boolean capability with bind (or the explicit form: value with data-hd-on-change).

AttributeWhat it is
bindThe capability it is bound to, e.g. {{ settings.light.cap.dim }} (the whole capability, no .value): it shows its value, takes min, max and step from it, and sends changes back (shown at once, sprung back if refused, range checked). A device that is unavailable shows its last value, disabled.
valueThe explicit form instead of bind: what it shows, e.g. {{ cap.onoff.value }} (or a live capability, followed); a change only goes to data-hd-on-change, which decides what it does. Without a handler it can’t be changed.
toneColour when on.One of lit, accent. Default lit.
labelAccessible label.
<hd-toggle bind="{{ cap.onoff }}" label="{{ device.name }}"></hd-toggle>

Styling

Set CSS variables on the component element. Its internal elements live in Shadow DOM; only the exposed named parts can be styled with ::part.

--hd-accent
The theme’s accent: active controls, links, highlights.
--hd-border
Lines round tiles and between parts.
--hd-border-width
How thick borders are.
--hd-control-radius
The corners of switches, sliders, pills and badges (999px for pills).
--hd-control-round
The corners of round buttons (50% for circles).
--hd-ease-out
The easing of most movement.
--hd-ease-spring
A springy easing, for things that bounce into place.
--hd-focus
The outline round what has keyboard focus.
--hd-lit
The warm colour of a device that is on.
--hd-motion-base
An ordinary change, like a value sliding.
--hd-motion-slow
A slow change, like a theme switching.
--hd-text
Text and big numbers.
--hd-track
The empty part of a slider, bar or ring.

Style the host

hd-toggle {  --hd-accent: #2563eb;  max-width: 100%;}
Theme variables