Theme Toggle Button
A persistent theme control with optional View Transition shapes.
A persistent theme control with optional View Transition shapes.
Import
Section titled “Import”import { ThemeToggleButton } from "@zentara-co/zenos-ui";Text and icons
Section titled “Text and icons”The button accepts text, an icon, or both. Each can be a render function receiving the current and next theme. Icon-only controls receive a default accessible name based on the next action.
Transition shapes
Section titled “Transition shapes”When the browser supports the View Transition API, the next theme is revealed using the selected clip shape. Unsupported browsers and users requesting reduced motion receive an immediate theme change.
Origin and duration
Section titled “Origin and duration”The reveal starts at the button by default. Set fromCenter for a viewport-centered transition and tune duration in milliseconds.
Controlled and persistent themes
Section titled “Controlled and persistent themes”Pass theme and onThemeChange when an application theme provider owns state. Without theme, the button updates the document root and persists through useTheme; storageKey={null} disables persistence.
The live examples on this page use storageKey="starlight-theme", matching the documentation shell so every toggle reads and writes the same preference. In your application, use the same key as your theme initialization script or provider.
Variants
circlesquarediamondrectanglehexagontriangle API
| Prop | Type | Default | Description |
|---|---|---|---|
theme | light | dark | — | Controlled theme. |
defaultTheme | light | dark | light | Initial uncontrolled theme. |
onThemeChange | (theme: Theme) => void | — | Runs after theme changes. |
shape | ThemeTransitionShape | circle | View-transition reveal shape. |
duration | number | 400 | Transition duration in milliseconds. |
storageKey | string | null | theme | Persistence key; null disables persistence. |
icon / children | ReactNode | (renderProps) => ReactNode | — | Theme-aware icon and visible content. |
fromCenter | boolean | false | Starts the reveal at the viewport center instead of the button. |
native props | React.ButtonHTMLAttributes<HTMLButtonElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |
Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props,
including className, style, aria-*, and data-*.
Accessibility
Section titled “Accessibility”ThemeToggleButton is a native pressed button. aria-pressed communicates whether dark mode is active, while its accessible name describes the next action. Keep icon-only controls labeled, and do not disable the reduced-motion fallback. Consumers remain responsible for semantic token contrast in both themes.