
Overview
The token system uses a three-layer architecture. Primitivesdefine raw color palettes—22 hue ramps with 9 stops each (100–900), plus alpha and absolute channels. Semantic tokens map primitives to UI roles grouped as surface, content, and border. Components reference semantic tokens, never raw primitives. Light and dark modes use mirrored primitive palettes (100 ↔ 900) so semantic mappings stay identical.
Why OKLCH
OKLCH (Oklab Lightness–Chroma–Hue) is a perceptually uniform color space. Two colors with the same lightness value look equally bright to the human eye, eliminating the uneven contrast jumps common in HSL ramps. Each shade step carries predictable contrast, accessible pairings are easier to verify, and new theme hues can be generated by rotating the hue channel while preserving the same lightness–chroma curve.
All primitives below are currently defined in HEX and will be progressively converted to OKLCH. A HEX fallback will be provided for browsers that don't support oklch():
.element {
/* Fallback for older browsers */
background: #006AFF;
/* OKLCH for modern browsers */
background: oklch(0.55 0.24 264);
}
ThemeProvider
Wrap your application with ThemeProvider to enable theming. It injects all color tokens and static tokens as CSS custom properties.
import { ThemeProvider } from "madagent";
import "madagent/styles";
function App() {
return (
<ThemeProvider theme="blue" mode="light">
{}
</ThemeProvider>
);
}
The provider renders a div with data-md-theme and data-md-mode attributes, which you can use for mode-specific CSS overrides.
useTheme Hook
Access the current theme and switch themes at runtime:
import { useTheme, themes } from "madagent";
function ThemeToggle() {
const { theme, setTheme } = useTheme();
const isDark = theme.mode === "dark";
return (
<button onClick={() =>
setTheme(isDark ? themes.blue("light") : themes.blue("dark"))
}>
Switch to {isDark ? "light" : "dark"} mode
</button>
);
}
Primitives
Raw color palettes with 9 stops each (100–900). In light mode, 100 is the lightest and 900 the darkest. In dark mode, the ramp is inverted. Values are currently HEX and will be converted to OKLCH.
Alpha
Absolute
Semantic Tokens
Semantic tokens map primitives to UI roles. Components consume these instead of referencing primitives directly. Grouped into three categories: surface (backgrounds), content (text/icons), and border (strokes/dividers).
Surface
Colors for backgrounds and fills. Use var(--md-surface-*) in CSS.
Content
Colors for text and icons. Use var(--md-content-*) in CSS.
Border
Colors for strokes and dividers. Use var(--md-border-*) in CSS.
Spacing
Spacing tokens are not theme-dependent. Available as --md-spacing-* CSS custom properties.
Typography
Font Families
Font Sizes
Font Weights
Line Heights
Borders & Radii
Border Widths
Border Radii
Corner Smoothing
Rounded corners match Figma's corner smoothing at 0.65 (Apple-style). CSS can't draw Figma's smoothed curve, so madagent pairs a superellipse with a slightly larger radius: superellipse(1.39) on a radius 1.25× the designed one matches it to within about 0.5% of the radius. Browsers without corner-shape keep the scale at 1 and draw a plain arc at the designed radius, so there is no fallback code to write.
The radius tokens above keep their designed values. Wherever a radius step is used, multiply it by the scale and set the shape in the same rule:
.card {
border-radius: calc(var(--md-radius-2xl) * var(--md-corner-scale));
corner-shape: var(--md-corner-shape);
}
/* Pills, circles and dots: no scale, plain round corners. */
.pill {
border-radius: var(--md-radius-full);
corner-shape: round;
}
--md-radius-full always takes corner-shape: round and no scale, and --md-radius-none and one-off radii (50%, inherit) are left alone. Set the scale and the shape together: the scale alone only makes corners rounder, and the shape alone draws a tighter curve than Figma's. Where a large radius sits on a small control, use --md-radius-fullinstead: CSS shrinks a radius that doesn't fit, while Figma squeezes the curve. Never use corner-shape: squircle; it is superellipse(2), about 6px off at a 32px radius. The tokens are defined once, on :root, by the madagent stylesheet, and npm run corner:audit checks every stylesheet in the repository follows these rules.
Motion
Duration and easing tokens for transitions and animations. base is the default interaction speed.
Durations
Easings
Z-Layers
Stacking order for layered surfaces: overlay < popover < toast < tooltip.