This page as markdown: /theme-selector.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

ThemeSelector

Status: stable

A presentational radiogroup for choosing a Sable design theme from theme manifests — tiles that draw each theme as a miniature of its own interface (its colours, type and corner shape) for a settings page, or compact rows for tool chrome. Pair it with useSableTheme().themeId and setThemeId when the app uses SableThemeProvider.

Keywords: theme selector, theme, appearance, skin, design theme, preset

Usage

Use ThemeSelector wherever a person picks a theme. The default cards layout is page-register furniture: a miniature of each theme's interface (its background, "Aa" in its display face, a card, and a primary button in its own corner shape), with the name and a caption only where one distinguishes it (the default theme, or a single-mode theme). Use layout="list" in tool chrome, a popover, or any docked panel — five cards is the wrong object for a 256px surface, however it is sized. For colour mode (light/dark/system) use ThemeSwitcher, which is a segmented control and belongs in chrome as-is.

Best practices

Anatomy

Part Required Description
ThemeSelector yes The radiogroup of themes, as cards or list rows.
ThemePreview no The tile each option draws, exported for showing a theme outside the picker — the row naming the current theme, or the media of each option in a commit-on-Enter DisclosurePicker list.

Subcomponents

Name Type Description
ThemePreview { theme: ThemeManifest; mode?: "light" | "dark"; size?: "md" | "sm" } The tile each option draws: the theme as a miniature of itself (background, "Aa" in its display face, a card, a primary button in its own corner shape), in its own scope. Exported for anywhere that shows a theme outside the picker, e.g. a row naming the current preset, or each option of a DisclosurePicker list where a pick has a cost. Sized in the caller's spacing unit, so it lines up with the row it sits in.

Props

Name Type Default Description
value ThemeId — The currently selected Sable design theme id.
onValueChange (themeId: ThemeId) => void — Called with the next design theme id when an option is chosen.
themes readonly ThemeManifest[] themeManifests Theme manifests to render. Defaults to Sable's built-in themes.
mode "light" | "dark" — Preview mode for each theme's tile. Pass useSableTheme().mode to match the current color mode; omitted cards use their manifest defaultMode.
label string "Design theme" Accessible label for the radiogroup.
layout "cards" | "list" "cards" Presentation. "cards" is the page-register picker (~144px per card); "list" is one compact --control-sm row per theme, for chrome and popovers. A presentation variant, not a size — "list" is not "cards, smaller" — which is why it is a prop rather than a density scope.
className string — Merged onto the outer radiogroup grid.

Tokens used

input, card, border, background, primary, primary-foreground, accent, muted, muted-foreground, ring

Motion

Accessibility

Related

Examples

When a switch has a cost: a DisclosurePicker list of ThemePreview tiles

import { DisclosurePicker, DisclosurePickerList, DisclosurePickerOption, DisclosurePickerPanel, DisclosurePickerTrigger, ThemePreview, useSableTheme } from "@sableui/react"

// Arrows move; Enter, Space or a click commits — so whatever the switch costs
// (a confirm, a font load, a reset) happens once, on the pick.
const { themeId, setThemeId, themes, mode } = useSableTheme()
const current = themes.find((theme) => theme.id === themeId)
<DisclosurePicker>
  <DisclosurePickerTrigger aria-label={`Theme: ${current?.label}`} media={current ? <ThemePreview theme={current} mode={mode} size="sm" /> : null}>
    {current?.label}
  </DisclosurePickerTrigger>
  <DisclosurePickerPanel>
    <DisclosurePickerList aria-label="Theme" value={themeId} onValueChange={setThemeId}>
      {themes.map((theme) => (
        <DisclosurePickerOption key={theme.id} value={theme.id} media={<ThemePreview theme={theme} mode={mode} size="sm" />}>
          {theme.label}
        </DisclosurePickerOption>
      ))}
    </DisclosurePickerList>
  </DisclosurePickerPanel>
</DisclosurePicker>

With SableThemeProvider

import { ThemeSelector, useSableTheme } from "@sableui/react"

const { themeId, setThemeId, themes, mode } = useSableTheme()
<ThemeSelector value={themeId} onValueChange={setThemeId} themes={themes} mode={mode} />

Controlled

import { ThemeSelector, type ThemeId } from "@sableui/react"

const [themeId, setThemeId] = useState<ThemeId>("sable")
<ThemeSelector value={themeId} onValueChange={setThemeId} />

In chrome — a popover or a docked panel

import { PopoverContent, ThemeSelector, ThemeSwitcher } from "@sableui/react"

// Five 144px cards is the wrong object for a 256px surface. Rows are.
<PopoverContent align="end" className="w-64 p-3">
  <ThemeSwitcher value={preference} onValueChange={setPreference} />
  <ThemeSelector layout="list" value={themeId} onValueChange={setThemeId} mode={mode} />
</PopoverContent>

Do not reach for a viewport breakpoint

import { ThemeSelector } from "@sableui/react"

// ✗ `sm:` keys off the VIEWPORT, not this component's container. On a wide
//   screen it does nothing at all for a narrow parent — and this exact
//   workaround, once documented here, is how the cards layout ended up in a
//   256px popover clipping "Default" to "D".
<ThemeSelector className="sm:grid-cols-1" value={themeId} onValueChange={setThemeId} />

// ✓ The cards grid already reflows on its own width (auto-fit, 9rem tracks).
//   For a genuinely narrow surface, change the presentation instead.
<ThemeSelector layout="list" value={themeId} onValueChange={setThemeId} />