Theme picker
Lets people choose one of the theme presets, each shown by name with a swatch of its colors.
Example
This panel gets the chosen data-focsd-brand. Load @focsd-dev/tokens/presets.css for its colors, type and corners to change.
<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>import { ThemePicker } from '@focsd-dev/react';
export function Example() { return <ThemePicker onChange={(e) => console.log(e.target)} target="#theme-picker-demo" storage-key-prefix="docs-demo-" presets="harbor signal mineral"></ThemePicker>;}<script setup>import '@focsd-dev/components/focsd-theme-picker.js';</script>
<template> <focsd-theme-picker @change="onChange" target="#theme-picker-demo" storage-key-prefix="docs-demo-" presets="harbor signal mineral"></focsd-theme-picker></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-theme-picker.js';
// template<focsd-theme-picker (change)="onChange($event)" target="#theme-picker-demo" storage-key-prefix="docs-demo-" presets="harbor signal mineral"></focsd-theme-picker><script> import '@focsd-dev/components/focsd-theme-picker.js';</script>
<focsd-theme-picker onchange={(e) => console.log(e.target)} target="#theme-picker-demo" storage-key-prefix="docs-demo-" presets="harbor signal mineral"></focsd-theme-picker>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
value | value | string | — |
presets | presets | string[] | null | null |
target | target | string | — |
storage-key-prefix | storageKeyPrefix | string | focsd- |
label | label | string | — |
Methods
| Method | Description |
|---|---|
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
| Event | Description |
|---|---|
change | Fired 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).
| Part | Description |
|---|---|
group | The radio group. |
option | Each option. |
option-checked | The checked option. |
swatch | The three colors of each option. |
name | The name of each option. |
check | The 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"orprefers-contrast: morea preset keeps its type and corners but not its colors. - The choice is stored as
focsd-brandinlocalStorage; storage that is blocked is ignored.
Keyboard
| Key | Action |
|---|---|
| Tab | Move to the chosen card |
| Arrow keys | Move to the next or previous card and choose it |
| Home / End | Choose the first or last card |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.