DocsTheming & motion
Dark mode
Light and dark themes with Uniwind, and how to switch between them.
init writes every colour token twice, once per theme, inside Uniwind's theme block:
@layer theme {
:root {
@variant light {
--color-background: #f8fafc;
/* … */
}
@variant dark {
--color-background: #0b1020;
/* … */
}
}
}Components only use the token classes, so they change with the theme. None of them check the colour scheme themselves.
Following the system or choosing a theme
With ThemeProvider, use useTheme().setScheme('dark') or the ready-made Theme switch, listed under Buttons, so named presets and system tracking stay coordinated. Without the provider, base themes can use Uniwind directly:
import { Uniwind } from 'uniwind';
Uniwind.setTheme('dark'); // 'light', 'dark' or 'system'Gotchas
- Keep both themes complete. A token defined only for light falls back to nothing in dark.
npx @swipeui/cli doctorlists missing tokens. - Check contrast in both themes when you change colours: text and icons need WCAG AA against their background.
- Glass surfaces are untinted Liquid Glass (
tintedaddsglass-tint), and fall back tosurface-elevatedwhen Reduce Transparency is on (seeuse-reduce-transparency).