Composites
Mode toggle
Lets a reader choose light mode, dark mode or their device's setting, and remembers the choice.
Unreleased
These changes are merged and will be in the next release of the packages.
- Add Mode toggle, shadcn's mode toggle: an icon button with a sun or a moon that opens a menu of Light, Dark and System, with the chosen mode ticked. Choosing Light or Dark sets
data-modeon<html>and stores it inlocalStorageundercadence-mode. System removes both, so the page followsprefers-color-scheme. Every storage read and write is guarded, so the mode still changes where storage is blocked.valueandonValueChangecontrol it,labelsreplaces its words, and the rest of its props go to the Button.useModegives any component the page's mode and follows a change made by the toggle, another tab or the device.setMode,getModeandgetResolvedModework outside React, andMODE_SCRIPTapplies a remembered mode in the page's<head>before the first paint.