Todae

Todae

Build your design system on Todae

A company design system on Todae is three things: a token package layered on Todae's tokens, a few TypeScript declarations, and thin wrappers around Todae's parts. Nothing is forked. When Todae updates, the company rebuilds its tokens and keeps its wrappers.

On this page

Token layers

Todae's tokens are DTCG 2025.10 files driven by tokens/resolver.json. Each set and modifier names its layer in $extensions["dev.todae"].layer, and a token may only reference tokens in a lower layer, or in its own layer when they come from the same set or modifier or from one earlier in resolutionOrder. A token in a set listed before the first scoped modifier, such as core, is declared only on :root, so it holds a literal value and references nothing.

  • core: raw scales, such as color.gray.900 and space.4.
  • appearance: semantic colors for light and dark, such as color.fg.muted and color.accent.default.
  • density: spacing for each density, such as space.control.x.
  • motion: the motion presets (data-motion): the role durations and the curves of what appears and goes, such as motion.popup.duration.enter and dialog.motion.easing.enter.
  • contract: what components read, such as button.primary.bg.default and field.border.focus.

Components read contract and motion tokens only. A rebrand changes the appearance layer, and the contract follows.

In CSS, every token is a custom property named after its path: color.accent.default is --todae-color-accent-default. Todae's tokens sit in the todae.base cascade layer.

A company resolver

A company writes its own resolver next to its token files. It may add sets, add contexts to Todae's modifiers, and replace tokens in them. Todae's resolver is loaded first, so every reference can point at Todae's tokens.

{
  "$schema": "https://www.designtokens.org/schemas/2025.10/resolver.json",
  "name": "acme",
  "version": "2025.10",
  "sets": {
    "brand": {
      "sources": [{ "$ref": "./brand.json" }],
      "$extensions": { "dev.todae": { "layer": "contract" } }
    }
  },
  "modifiers": {
    "appearance": {
      "contexts": {
        "light": [{ "$ref": "./appearance/light.json" }],
        "dark": [{ "$ref": "./appearance/dark.json" }]
      },
      "$extensions": {
        "dev.todae": { "layer": "appearance", "attribute": "data-appearance", "root": true, "colorScheme": true }
      }
    }
  },
  "resolutionOrder": [{ "$ref": "#/modifiers/appearance" }, { "$ref": "#/sets/brand" }]
}

References are JSON Pointers into the merged token tree:

{
  "brand": {
    "ink": { "$type": "color", "$value": { "$ref": "#/color/gray/900/$value" } }
  }
}

To change one of Todae's own tokens, declare it again in a set or modifier with the same name as the Todae one that declares it, and repeat that entry's layer and placement in $extensions. The company's value wins, and the rest of the entry stays Todae's.

  • core: raw scales, such as color.gray.*, radius.*, font.family.sans and font.weight.*.
  • appearance, density: semantic colors and spacing, in a context named light, dark or a density.
  • focus: focus.ring, focus.ring-width and focus.ring-offset.
  • button: button.base.*, the geometry every button variant shares.
  • buttonVariant: button.<variant>.*, in a context named after the variant.
  • motion: the role durations, each component's motion.easing.enter and exit, popover.motion.scale and dialog.motion.offset, in a context named after the preset, such as standard. Its $extensions are { "dev.todae": { "layer": "motion", "attribute": "data-motion", "inputs": true } }.
  • contract: every other component token, such as card.shadow and field.radius.
"sets": {
  "core": {
    "sources": [{ "$ref": "./core.json" }],
    "$extensions": { "dev.todae": { "layer": "core" } }
  },
  "button": {
    "sources": [{ "$ref": "./button.json" }],
    "$extensions": { "dev.todae": { "layer": "contract" } }
  }
}

Each row of the token catalog, @tounsoo/todae/tokens.json, names its entry in entry, which for a button variant also has a context field such as "primary", and a token in the wrong entry fails the build with a message naming the entry it belongs in. Change a core token only with a literal value, since core tokens are declared once on :root and reference nothing.

Build it with the todae-tokens CLI, from a project that has @tounsoo/todae installed. --no stops npx from fetching a package of that name from npm:

npx --no todae-tokens build --resolver ./tokens/resolver.json

It writes three files:

  • todae-theme.css: the company's tokens only, in the todae.theme layer, which comes after Todae's.
  • tokens.catalog.json: Todae's and the company's tokens together.
  • todae-theme.types.ts: THEME_OVERRIDE_TYPES for the company's keys, for ThemeProvider.

--css, --catalog and --types change the output paths. Add --check in CI to fail when the outputs are missing or out of date. The same build is a function, buildCompanyTokens from @tounsoo/todae/tokens-builder.

The build runs every check Todae's own build runs: path format, reference cycles, layer order, light and dark parity, and APCA contrast. The contrast pairs in Todae's resolver apply to the company's colors too, so a brand accent that fails them fails the build. See the Contrast section of Tokens for the pairs and how to change a minimum.

When a check fails, the message says what to change: the entry a misplaced token belongs in, the token that reads a missing or out-of-order reference, the tokens one context declares and another lacks, and for a contrast pair below its minimum, the nearest lightness of its text or of its background that passes without failing another pair the build checks, set on the token that holds the literal value. When that token is in Todae's own files, the message says to override it in the same set or modifier of your resolver. Build again after taking one, since one change can fix several pairs:

contrast: 1 pair(s) fail APCA
  "color.on-accent" on "color.accent.active" in appearance "dark" is Lc 56.2, below 60
    fix: set the lightness of "color.accent.active" (modifier "appearance" context "dark") from 0.74 to 0.764, for Lc 60.1

Load the CSS after Todae's:

import '@tounsoo/todae/todae.css';
import './todae-theme.css';

If your app has cascade layers of its own, such as Tailwind's, import both files from your CSS entry after a layer statement instead. See CSS layers.

Several themes on one page

The theme CSS changes Todae's tokens for the whole page. To give part of a page another theme, such as a sub-brand, build that theme with --scope and a CSS selector:

npx --no todae-tokens build --resolver ./tokens/business.resolver.json --scope .business --css ./business-theme.css

The CSS then holds all of Todae's tokens and the company's inside @scope (.business), so an element that matches the selector and everything in it take the theme, and nothing outside it does. Load it after Todae's CSS, as above, and load as many scoped themes as the page needs. A scope holds the whole theme, so a scope inside another scope shows none of the outer theme's tokens, nor the overrides of a ThemeProvider around it, and the nearer scope wins whichever file loads last. That makes a scoped file larger than Todae's own token CSS: about 17 KB gzipped, against 11 KB.

An element the selector matches takes the appearance, density and motion preset of the nearest element around it that sets data-appearance, data-density or data-motion, such as a ThemeProvider, or the defaults when there is none. A ThemeProvider inside the scope, or on the scoped element itself, switches them as it does anywhere:

<ThemeProvider appearance="dark" className="business">
  …
</ThemeProvider>

A scoped theme is built on Todae's tokens, not on another company theme. For a sub-brand, list the main brand's token files in the sub-brand's resolver, followed by the files that change, as business.resolver.json in examples/fernway does.

Overrides: CSS or ThemeProvider

There are two ways to change a token for part of a page.

CSS is for anything known at build time. Put it in a company token package when you can, so the build checks it. Otherwise write it in the todae.theme layer, or unlayered, which beats every layer:

@layer todae.theme {
  [data-appearance='dark'] {
    --todae-color-accent-default: oklch(0.78 0.13 25);
  }
  @media (prefers-color-scheme: dark) {
    [data-appearance='system'] {
      --todae-color-accent-default: oklch(0.78 0.13 25);
    }
  }
}

ThemeProvider appearance="system" renders data-appearance="system", which follows the user's color scheme in CSS. So a hand-written light or dark override also needs a system rule under the matching prefers-color-scheme query. A company token build emits these for you.

Set it on an element that carries data-appearance, data-density or data-motion. Contract tokens are computed there, so an override on a descendant does not reach them. Each of those elements computes the contract tokens again, so a contract-token override set in CSS must match every one of them, not only the outermost.

ThemeProvider overrides is for values that arrive at runtime, such as a customer's brand color. It takes token paths and DTCG values, sets them as custom properties on its own element, and rejects unknown paths and invalid values: it throws in development and skips them in production. In development it also checks the APCA contrast pairs from Todae's resolver where it renders, and logs a console.warn naming the pairs its overrides push below Todae's minimum. Production runs no contrast check.

<ThemeProvider overrides={{ 'color.accent.default': { colorSpace: 'oklch', components: [0.5, 0.15, 150] } }}>
  …
</ThemeProvider>

THEME_OVERRIDE_KEYS, exported from @tounsoo/todae, lists the paths overrides accepts. It joins the raw keys, the semantic keys, and the component keys. Read it when a tool must know which paths overrides accepts. The Tokens page names THEME_OVERRIDE_KEYS beside ThemeProvider. For the custom properties without a provider, call themeOverrideStyle with the same value.

A ThemeProvider with no appearance takes the enclosing provider's, and the outermost defaults to system, so a nested provider that only sets overrides keeps the page light or dark. Each provider declares the appearance tokens again, so an outer provider's override of one, such as color.accent.default, doesn't reach inside a nested provider: repeat it there. Component token overrides, such as card.shadow, do carry through. An override holds in every appearance of the provider that sets it. To give one a light and a dark value, pick it with useAppearance() in a component inside a provider. Under system the server renders the light value until the page hydrates, so a value known in advance belongs in a company token package, with a light and a dark context.

const PARTNER_ACCENT = {
  light: { colorSpace: 'oklch', components: [0.45, 0.12, 50] },
  dark: { colorSpace: 'oklch', components: [0.8, 0.1, 50] },
} as const;

function PartnerTheme({ children }: { children: React.ReactNode }) {
  return <ThemeProvider overrides={{ 'color.accent.default': PARTNER_ACCENT[useAppearance()] }}>{children}</ThemeProvider>;
}

Company tokens are unknown to Todae, so pass their generated types to allow them:

import { THEME_OVERRIDE_TYPES } from './todae-theme.types';

<ThemeProvider
  overrideTypes={THEME_OVERRIDE_TYPES}
  overrides={{ 'brand.ink': { colorSpace: 'oklch', components: [0.3, 0.05, 25] } }}
>
  …
</ThemeProvider>

TypeScript then accepts brand.* keys and still rejects misspelled ones.

A worked example

examples/fernway in Todae's repository themes Todae for a made-up company with tokens only. It changes Todae's grays, radii, font and accent, adds a button variant and tokens of its own, and sets a partner's colors at runtime.

Adding a variant or a density

Button variants and densities are modifier contexts, so a company adds one in its resolver.

A button variant is a buttonVariant context with the same token shape as Todae's: bg, fg and border for default, hover, active, focus and disabled, plus ring.focus and shadow. Todae's buttonVariant declares that shape as slots, and a company's buttonVariant keeps them, so the build checks a new variant too:

"buttonVariant": {
  "contexts": { "outline": [{ "$ref": "./button.outline.json" }] },
  "$extensions": {
    "dev.todae": { "layer": "contract", "attribute": "data-button-variant", "alias": true }
  }
}

A density is a density context that sets spacing tokens only:

"density": {
  "contexts": { "roomy": [{ "$ref": "./density/roomy.json" }] },
  "$extensions": { "dev.todae": { "layer": "density", "rules": ["density-space"], "attribute": "data-density", "root": true } }
}

Then tell TypeScript about the new names:

declare module '@tounsoo/todae' {
  interface ButtonVariants {
    outline: true;
  }
  interface Densities {
    roomy: true;
  }
  interface Motions {
    brisk: true;
  }
}

<Button.Root variant="outline">, <DensityProvider density="roomy"> and, for a brisk context of the motion modifier, <MotionProvider motion="brisk"> now type check and pick up the new tokens.

Wrapping a component

Wrap a part to fix a company default or add a company prop. Spread the rest of the props and pass ref through, since every part forwards native attributes and its ref:

import { Button, type ButtonRootProps } from '@tounsoo/todae';

export function AcmeButton({ variant = 'outline', ...props }: ButtonRootProps) {
  return <Button.Root {...props} variant={variant} />;
}

Parents never find their children by component type, so wrapped children work too. OptionList.Option registers with its list through context, so a wrapped option still selects and navigates. Button.Root finds Button.Icon by a data attribute it renders, so a wrapper that renders Button.Icon still counts as the button's icon:

function AcmeOption({ className, ...props }: OptionListOptionProps) {
  return <OptionList.Option {...props} className={['acme-option', className].filter(Boolean).join(' ')} />;
}

<OptionList.Root aria-label="Size" value={size} onValueChange={setSize}>
  <AcmeOption value="s">Small</AcmeOption>
  <AcmeOption value="m">Medium</AcmeOption>
</OptionList.Root>

To keep your own ref alongside one a hook gives you, combine them with composeRefs.

Restyle through tokens first. A class on a part works for layout, but colors and spacing set through tokens follow appearance and density, and a class does not.