Skip to content
Focsd homeFocsd homeFocsd
Forms

Theme picker

Lets people choose one of the theme presets, each shown by name with a swatch of its colors.

  • Tag: focsd-theme-picker
  • Pattern: Radio group of preset swatch cards
  • Category: Utility

Example

This panel gets the chosen data-focsd-brand. Load @focsd-dev/tokens/presets.css for its colors, type and corners to change.

Save
HTML
<focsd-theme-picker
target="#theme-picker-demo"
storage-key-prefix="docs-demo-"
presets="harbor signal mineral"></focsd-theme-picker>
<focsd-card id="theme-picker-demo">
<p>
This panel gets the chosen <code>data-focsd-brand</code>. Load
<code>@focsd-dev/tokens/presets.css</code> for its colors, type and corners to change.
</p>
<focsd-button variant="action">Save</focsd-button>
</focsd-card>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-theme-picker.js';
</script>
<focsd-theme-picker target="#theme-picker-demo" storage-key-prefix="docs-demo-" presets="harbor signal mineral"></focsd-theme-picker>

API

Attributes

AttributePropertyTypeDefault
valuevaluestring—
presetspresetsstring[] | nullnull
targettargetstring—
storage-key-prefixstorageKeyPrefixstringfocsd-
labellabelstring—

Methods

MethodDescription
options()The options, in order.
readTarget(target)The value a target shows now.
applyTo(value, target)Apply a value to the target.
storedValue(value)The value to store for a choice (null removes the key).

Events

EventDescription
changeFired when the user picks a preset; read value (empty for the default).

CSS parts

Style the inside of the component with ::part(), for example focsd-theme-picker::part(group).

PartDescription
groupThe radio group.
optionEach option.
option-checkedThe checked option.
swatchThe three colors of each option.
nameThe name of each option.
checkThe check mark of the chosen option.

Accessibility

  • It is a radio group named "Theme preset" (or label). Each card is a radio named by its text ("Harbor"); the first is "Wayfinding (default)", which removes the preset.
  • The swatch (action, route and surface colors, in the current light or dark scheme) is decorative and hidden from assistive technology. The chosen card has a check mark and a heavier border, so the choice never depends on color.
  • The group is one Tab stop; the arrow keys move between the cards and choose them, Home and End go to the first and last, and Left moves forward in right-to-left text.
  • High contrast always wins: under data-focsd-theme="contrast" or prefers-contrast: more a preset keeps its type and corners but not its colors.
  • The choice is stored as focsd-brand in localStorage; storage that is blocked is ignored.

Keyboard

KeyAction
TabMove to the chosen card
Arrow keysMove to the next or previous card and choose it
Home / EndChoose the first or last card