Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

Theming

Every component renders a stable class and its state as data attributes. The default theme styles them, and you choose how much of it you keep.

Use the default theme#

Import @kvirn-ui/theme/theme.css once. Every component of @kvirn-ui/react is then styled. The map and the rich text editor have their own opt-in files, @kvirn-ui/theme/map.css and @kvirn-ui/theme/rich-text.css, so a site without them does not pay for them. A Button is secondary by default. Add className="kv-button--primary" for the one main action on the page, or className="kv-button--danger" for an action that deletes something. Put class="kv-compact" on a container for smaller controls in staff tools.

<Button className="kv-button--primary">Send application</Button>

The colour scheme, contrast and motion follow the device until the user chooses. To avoid a flash of the wrong theme on a server-rendered page, see Rendering: server and client.

Override variables#

The theme is role scales (--kv-primary-500, --kv-neutral-50), named for what they do and not for their hue, and semantic tokens that point at them (--kv-color-primary). Set either in your own CSS. Everything in theme.css is in @layer kv, so your CSS always wins.

/* Rebrand: give the primary scale your brand's colours. All four themes follow. */
:root {
  --kv-primary-50: #edfafa;
  --kv-primary-100: #cdf0f0;
  --kv-primary-200: #9be0e2;
  --kv-primary-300: #039aa4;
  --kv-primary-400: #03828c;
  --kv-primary-500: #007d86;
  --kv-primary-600: #00707a;
  --kv-primary-700: #005a62;
  --kv-primary-800: #00474e;
  --kv-primary-900: #003a40;
  --kv-primary-950: #00262a;
}

A secondary Button's edge uses the secondary scale, which is the neutral steps by default. Give --kv-secondary-* your own 11 steps to colour it.

Each theme uses different steps, so a swapped scale can break contrast. Check your colours with checkThemeCss() from @kvirn-ui/theme on your customised copy. It measures every text, control and focus pair in all four themes.

Replace it or skip it#

theme.css is one readable file. Copy it from node_modules/@kvirn-ui/theme/theme.css into your project, edit it, and import your copy instead. Or skip it, and style the part classes (such as kv-button) and the state attributes with Tailwind or your own CSS. Remove the import and every component is unstyled again: KvirnUI never loads CSS for you.

<Button className="rounded-md border px-4 py-2 data-disabled:border-dashed data-focus-visible:outline-2">
  Save draft
</Button>

Moving indicators and WCAG 2.2.2#

These move for as long as a wait lasts: the spinner and the bar sheen in Progress, the busy Button, the job Toast, the FileUpload track for an unknown size and the busy Table. The library honours prefers-reduced-motion: reduce and shows a still rest shape instead. The text, the percent and the slow sentence at 10 seconds carry the wait.

An indicator that can keep moving for more than 5 seconds alongside other content needs a visible control on the page that stops or hides it (2.2.2 Pause, Stop, Hide). An indicator that is the only content during a wait where nothing else can be done is exempt. prefers-reduced-motion alone is not that control. The library ships no such control. Your app offers a visible "Reduce motion" control before the content, keeps the choice itself (a cookie or your user settings) and applies the stop CSS below.

If your app already uses useTheme().selectMotion('reduce'), every indicator stops: it sets data-kv-motion on the page and the library does the rest. The CSS below is for an app that keeps its own control.

/* After theme.css. The attribute name is yours: set it on <html> from your control. */
:root[data-reduce-motion='true'] .kv-spinner,
:root[data-reduce-motion='true'] .kv-spinner::before,
:root[data-reduce-motion='true'] .kv-progress-track,
:root[data-reduce-motion='true'] .kv-progress-track::before,
:root[data-reduce-motion='true'] .kv-progress-bar,
:root[data-reduce-motion='true'] .kv-icon.kv-animate-spinner,
:root[data-reduce-motion='true'] .kv-icon.kv-animate-spinner > path,
:root[data-reduce-motion='true'] .kv-table[data-busy] .kv-table-column-header,
:root[data-reduce-motion='true'] .kv-table[data-busy] .kv-table-head > tr:last-child::after {
  animation: none;
}

With the animation removed, each indicator shows its rest shape: a three-quarter arc (the CSS spinner, and the spinner icon with the kv-animate-spinner class), a hatched track and a plain gradient fill.