Theme builder
Start from a built-in theme or your own colours, watch real components restyle, check contrast, and export CSS, JSON or SwiftUI.
Demo
Usage
/* forest.css is the CSS export, loaded after Slant's stylesheet.
Slant's rules sit in @layer slant, so it wins without extra specificity. */
import '@tuttn/slant/styles.css'
import './forest.css'
import { Slant } from '@tuttn/slant'
// The theme prop is typed to the built-in ids, so set the attribute itself.
// Every --sl-* token inside follows, and nested roots without a theme inherit it.
<Slant data-theme="forest">
<App />
</Slant>
// Without React, on the hosted slant.css, the attribute is the whole contract.
<div class="slant" data-theme="forest">…</div>The builder runs the build's own code, shared/kit-tokens.lib.mjs, in the browser. The contrast gate is the one npm run build:tokens runs before it writes anything: the same pairs and the same minimums, from the contrast map in shared/kit-tokens.json. A theme that fails here would stop the build too. The preview is a nested Slant root whose inline style is the exported CSS block, so the tinted -soft backgrounds are mixed from your colours exactly as they will be in your app.
After any edit the address bar holds the theme, so the link shares it.
Making a theme built-in
To ship a theme with Slant itself, paste the kit-tokens.json export into themes in shared/kit-tokens.json, add its id to the ThemeId type in slant/react/src/theme.ts (the build doesn't write the type) and to the theme list scripts/kit-tokens.test.mjs expects, then run npm run build:tokens. The gate runs first; then the theme lands in tokens.css, in the package's themes list, and so in every theme switcher, in TUTTNTheme.swift, and in the hosted slant.css and tokens.json. npm run test:slant runs the story tests once per theme in the JSON, so the new theme is covered with no other change.
Overlays
Menus, toasts and tooltips render in a host at the end of the page that copies the root's theme prop, not an attribute set by hand. To carry a theme of your own into them too, pass it as the prop with a cast, theme={'forest' as ThemeId}, which sets the same attribute.
See Theming for roots, nesting, direction and density, and Tokens for every variable and its value in each built-in theme.