Skip to content
Playground

Theme Toggle Button

A persistent theme control with optional View Transition shapes.

A persistent theme control with optional View Transition shapes.

TSX
import { ThemeToggleButton } from "@zentara-co/zenos-ui";

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.

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.

The reveal starts at the button by default. Set fromCenter for a viewport-centered transition and tune duration in milliseconds.

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

PropTypeDefaultDescription
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-*.

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.