Skip to the page
Supply UI

Colour scheme provider

In code: ColorSchemeProvider

Put it around the page in the root layout, at the top of <body>, when the tool has a <ColorSchemeSwitch>: the person's saved choice is then applied before the page is drawn, so a dark page never flashes light. The layout's <html> needs suppressHydrationWarning, because the choice is written on it before React starts.

Preview

Paid

Use

The code of the preview above
import { Badge, Button, ColorSchemeProvider, ColorSchemeSwitch, Row, Stack } from '@/components/ui';

function ColorSchemeProviderDemo() {
  return (
    <ColorSchemeProvider>
      <Stack gap={3}>
        <ColorSchemeSwitch />
        <Row gap={2}>
          <Button variant="primary">Book</Button>
          <Button>Later</Button>
          <Badge tone="success" dot>Paid</Badge>
        </Row>
      </Stack>
    </ColorSchemeProvider>
  );
}

This page as text, for an AI

Options

OptionTypeWhat it does
children ReactNodeWhat goes inside.
nonce stringThe nonce of your Content Security Policy, for the small script it writes into the page.

Without React

With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:

components/button.csscomponents/segmented-control.csscomponents/calendar.css

Helpers: states, do and don’t

Lets the person choose light or dark for themselves, on their own device. The theme's mode stays the default. With it, wrap the page in <ColorSchemeProvider> at the top of <body> in the root layout and add suppressHydrationWarning to <html>: the saved choice is then applied before the page is drawn.

Hooks and functions the components are made of, passed on so a project uses the same ones: keyboard shortcuts, options loaded while typing, search matching, saved preferences, screen-reader announcements, smooth sizes, the theme.

Do

  • Use useShortcut for app-wide keys, and show the key with formatShortcut so it reads right on each computer.
  • Use announce() to tell a screen reader what changed when nothing visible takes focus ("3 results").

Don't

  • Don't turn off the smooth sizes Toaster starts; boxes would jump when their content changes.