Theme switch
A React component in Beamline's Actions category, in the free sample.
The light/dark control: the page changes in one of four transitions starting from the button (reveal, eclipse, split, rise), and the icon turns between sun and moon.
Use it for
- A visible appearance control in settings or an app header.
Not for
- Products that ship dark only: keep the preference in settings.
Anatomy
- Button
- sun / moon icon
- label
Variants
- variant: reveal, eclipse, split, rise
- buttonVariant: secondary, ghost, outline
States
- dark
- light
- transitioning
Keyboard
- Enter / Space switches
Motion
The new theme is revealed by clipping only the new page snapshot (no stylesheet is added): reveal grows a circle from the button, eclipse closes an even-odd hole into it, split opens from the middle, rise from the bottom; 540 ms (1.5 × considered) on the in-out curve. The icon turns between sun and moon over 280 ms. Reduced motion or no View Transitions: instant swap. Icon only, its words arrive as the system tooltip (after a moment on hover, at once on keyboard focus).
Props
| Prop | Type | Default | Description |
|---|---|---|---|
theme | "light" | "dark" | — | Controlled colour theme; omit to use defaultTheme. |
onThemeChange | (next, variant, trigger) => void | — | Apply the theme here (set the class on your .pui root, store the choice). It runs inside the transition. |
variant | ThemeSwitchVariant | "reveal" | Legacy animation setting; omitted by default. Deprecated: Use animation instead. |
label | string | "Theme" | Visible text; the accessible name always says where it goes ("Switch to light theme"). Default "Theme". |
iconOnly | boolean | — | Shows only the icon while retaining the accessible name. Defaults to false. |
transitionTheme(apply, variant, from) | function | — | the transition alone, for your own control |
style / ref | CSSProperties / native Ref | — | style: Inline styles on the documented visual root; no inline overrides by default. ref: Receives the button or trigger; no ref by default. |
classNames | ThemeSwitchClassNames | — | Classes for the named visual parts; no part overrides by default. |
animation | ThemeSwitchVariant | — | How the new theme arrives: reveal, eclipse, split or rise; defaults to reveal. |
defaultTheme | "light" | "dark" | — | Initial theme indicated by the button when uncontrolled; defaults to dark. |
buttonVariant | ButtonVariant | — | Visual weight of the theme button. Defaults to secondary. |
size | ButtonSize | — | Control size within the supported size steps. Defaults to "md". |
className | string | — | Classes on the documented visual root; no override by default. |
ref | Ref<HTMLButtonElement> | — | Receives the button or trigger; no ref by default. |
style | CSSProperties | — | Inline styles on the documented visual root; no inline overrides by default. |
Built from
Dependencies
lucide-react, motion
Import
import { ThemeSwitch } from "@beamline/theme-switch";
Get it
Theme switch is part of Beamline UI. Install the parts you need in your React app as compiled packages or editable source. Theme switch is included in the free MIT sample. Get Beamline · Connect your agent
More in Actions
- Consequence preview: A risky action that shows what it will do before it runs: one headline sentence, what blocks it and what it also reaches as bands, then the rest as cards…
- Confirm morph: A destructive action that asks in place: the button morphs into its question, then into working, then into the result with Undo or Retry, without a dialog.
- Swipe actions: Row actions behind a swipe on touch screens and a two-finger swipe on a trackpad, and at the row's end for pointer and keyboard (a ⋯ menu in a narrow…
- Hold to confirm: Confirms a costly action by holding instead of clicking: a fill sweeps across while held and drains if let go early; pointer, touch, Space and Enter all…
- Split button: One obvious action joined to a menu of close alternatives; both halves are real buttons and the menu uses the shared menu rows.
- Copy button: Copies a value and confirms in place: the icon becomes a check and the label says Copied; a refused copy says so instead of pretending.
- Button: The action control: five weights and a brand fill, a buy/sell tone, sm/md/lg and a 44 px touch size, icon-only, a loading state that keeps its size and…