Foundations
Theming
Light and dark themes, palettes and accents, switched with three data attributes.
Every color in Deft is a CSS variable, and three attributes decide its value. data-theme picks light or dark, data-palette picks a complete set of colors, and data-accent picks an accent color on a neutral base. The example shows the eight palettes in both themes.
Attributes
| Attribute | Values | Without it |
|---|---|---|
data-theme | light, dark, system | Light. |
data-palette | canyon, cove, dunes, frost, lupine, mesa, minimal, valley | The base palette. |
data-accent | cobalt, orange, amber, green, teal, violet, pink | The accent of the palette. |
Set them on the root element to theme the whole app:
<html data-accent="cobalt" data-palette="minimal" data-theme="system" lang="en">Themes
data-theme sets the CSS color-scheme of its element: light, dark, or light dark for system, which follows the operating system. Every token is declared with light-dark(), so the browser picks the matching value by itself:
--bg-default: light-dark(var(--light-bg-default), var(--dark-bg-default));Deft also redefines the Tailwind dark: variant. It applies inside [data-theme="dark"], and inside [data-theme="system"] when the operating system prefers dark. Components need it only where swapping a token is not enough. For example, the thumb of Switch.Root and the list and indicator of Tabs change their surface in the dark theme. In your own code, use the color tokens first and dark: as the exception.
No attribute means light
An element tree without data-theme is always light, and dark: never applies in it. Set data-theme="system" to follow the operating system.
Palettes
A palette gives a value to all 70 tokens, once for light and once for dark: surfaces, text, accent, state colors, borders, chart colors, hues and the shadow colors of each elevation. data-palette selects one of the eight palettes by its id.
Without data-palette the root uses the base palette, which has a blue accent.
minimal is the grayscale palette. Its accent is near black in the light theme and near white in the dark one, its chart ramp and series are steps of gray, and its eight hues share one gray pair. It is also the base that every accent is built from.
Accents
An accent replaces the tokens that carry the brand color. The example shows four of them with their utilities. The fifth, bg-accent-subtle, is listed with the surfaces.
data-accent is not a tint on top of the current palette. Each accent is a complete set of tokens generated from minimal in two steps:
- Every pure gray of
minimal, exceptfg-on-emphasis, gets a slight tint in the hue of the accent and keeps its lightness. - The five accent tokens are replaced with the accent's own values:
accent-emphasis,accent-emphasis-hover,accent-fg,accent-mutedandbg-accent-subtle.
Tokens that already have a color keep it. State colors and the warning, danger and critical chart colors are the same in every accent.
In the stylesheet the accent rules come after the palette rules, so data-accent wins when both attributes sit on one element. A value that matches no accent leaves the palette as it is.
What the dashboard uses
The dashboard sets all three attributes on <html>:
data-paletteis alwaysminimal.data-themefollows the Theme preference: System (the default), Light or Dark.data-accentfollows the Accent color preference: Cobalt (the default), Neutral, Orange, Amber, Green, Teal, Violet or Pink.
The user changes both preferences in Settings → Preferences, in the Appearance section. They are stored in a cookie, so the server already renders <html> with the right attributes.
Neutral is not an accent. It writes data-accent="neutral", which matches no accent rule, so the plain minimal palette shows through. That is why the dashboard sets data-palette="minimal" next to the accent.
Theme a part of the page
The attributes work on any element, not only on the root. An element with data-theme, data-palette or data-accent resolves all tokens again for its subtree:
<aside className="bg-default text-default" data-theme="dark">
<Button.Root variant="primary">Always on a dark surface</Button.Root>
</aside>The dashboard uses this for the accent swatches in its preferences: each swatch is a <span> with its own data-accent and the bg-accent utility.
Helpers
@openperf/deft exports the palettes as data, for code that needs a color outside CSS.
| Export | Type | Contents |
|---|---|---|
paletteIds | readonly array | The eight values of data-palette. |
accentIds | readonly array | The seven values of data-accent. |
hues | readonly array | red, orange, amber, green, teal, blue, violet, pink. |
palettes | Record<Palette, { light: PaletteTokens; dark: PaletteTokens }> | Token values of each palette. |
accentPalettes | Record<Accent, { light: PaletteTokens; dark: PaletteTokens }> | Token values of each accent, after the tint. |
basePalette | { light: PaletteTokens; dark: PaletteTokens } | Token values used without data-palette. |
getContrast | (foreground: string, background: string) => number | Contrast ratio of two #rrggbb colors, from 1 to 21. An alpha channel is ignored. |
The types that go with them:
| Type | Meaning |
|---|---|
Palette | Union of the palette ids. |
Accent | Union of the accent ids. |
Hue | Union of the hue names. |
PaletteTokenName | Union of the 70 token names, such as "bg-default" or "accent-emphasis". |
PaletteTokens | Record<PaletteTokenName, string>, one hex value per token. |
The dashboard reads the page background from these objects to fill its theme-color meta tags. The core of that code:
import { type Accent, accentPalettes, palettes } from "@openperf/deft";
export const toThemeColors = (accent: "neutral" | Accent) => {
const schemes = accent === "neutral" ? palettes.minimal : accentPalettes[accent];
return { light: schemes.light["bg-default"], dark: schemes.dark["bg-default"] };
};It also builds its accent picker and validates the stored preference from accentIds.
Where the values live
Palettes are TypeScript objects in packages/deft/src/libs/palettes: one file per palette in schemes, and the accent colors in accents.ts. The stylesheet palettes.gen.css is generated from them and is never edited by hand. It contains:
- one rule for
:root,[data-theme],[data-palette]and[data-accent]that declares every token withlight-dark(); - the
--light-*and--dark-*values of the base palette on:root; - one
[data-palette="…"]rule per palette and one[data-accent="…"]rule per accent with the same variables.
A test compares the committed file with the output of the generator, so the stylesheet cannot drift from the objects. To change a color, edit the palette object and update that file snapshot.
Tests also guard contrast in every palette, accent and theme. Colors lists the pairs they check.