ColorSchemeButton

Switch between light and dark themes with an icon that reflects the current scheme.

How to use

Use ColorSchemeButton to switch between light and dark schemes. New code uses this name; ThemeButton remains a compatibility export. Use StyleButton for design-style switching.

  • By default, follow the operating system until a manual choice is saved in a one-year cookie. Set systemPreference=false for deterministic examples and controlled initial values.

  • It updates the document theme by default. Set applyToDocument=false for local control. Without children it uses an icon-only layout.

Import

import { ColorSchemeButton } from '@snowui-design-system/components';

Usage

Variants

API Reference

Property Type Default Example Description
scheme ColorScheme — scheme={value} Current color scheme; supports bind:scheme. When systemPreference=false, takes priority over defaultScheme on mount. A click updates it, and it also follows root-attribute changes while document synchronization is active.
defaultScheme ColorScheme — defaultScheme={value} Initial uncontrolled scheme when systemPreference=false; scheme takes priority. If neither is set, reads the page root. With applyToDocument=false, falls back to light.
applyToDocument boolean true applyToDocument Synchronize current state to document.documentElement with theme="dark", removing theme for light. false disables reading, writing, and observing that page attribute; the caller owns the theme target. Cookie persistence is controlled separately by systemPreference.
systemPreference boolean true systemPreference Follow the operating system without a valid manual preference; save manual choices for 365 days and resume system following on expiry. Cookie/system values take priority over initial values. false disables system reading and preference cookie reads/writes.
ariaLabel string — ariaLabel="Example" Override the accessible Button name. By default, describes the state that clicking will switch to and follows LocaleProvider.
lightIcon Snippet — (built-in graphic) lightIcon={lightIconContent} Replace the Sun icon shown while the current scheme is light. Changes graphics only, not switching logic.
darkIcon Snippet — (built-in graphic) darkIcon={darkIconContent} Replace the Moon icon shown while the current scheme is dark. Changes graphics only, not switching logic.
children Snippet — <ColorSchemeButton>Content</ColorSchemeButton> Custom content after the state icon. Without it, the host Button uses iconOnly layout automatically.
disabled boolean false disabled Disable the Button action without preventing synchronization of an external binding or page attribute.
onSchemeChange (scheme: ColorScheme) => void — onSchemeChange={(value) => { /* handle value */ }} Receive the new value after a user click. Initialization, external assignments, and observed page-attribute changes do not call it.
onclick (event: MouseEvent) => void — onclick={(value) => { /* handle value */ }} Called before the state switches on a valid click. In the current implementation, preventDefault() does not cancel the subsequent switch. Not called when disabled.
No data