Design semantic tokens and primitives
Separate the system from the library
A design system is a maintained set of design decisions, implementation contracts, documentation and working practices. A component library implements reusable interface pieces; a CSS framework provides styling conventions or utilities. A library alone does not establish a design system. In our fictional tool library, every checkout screen uses the same primary action, spacing and error treatment. A design token names a design decision so it can be shared instead of copying a raw value into each component. Primitive tokens describe values such as a blue or a spacing step; semantic tokens describe purposes such as action background, text or error. Component-specific tokens may refer to those purposes. Keep the public semantic vocabulary small and document which values consumers may override.
.tool-system { --blue-700: #174b78; --gray-900: #17212b; --space-2: .5rem; --space-4: 1rem; --surface: #fff; --text: var(--gray-900); --action: var(--blue-700); --on-action: #fff; --error: #9c2020; --focus: #174b78; --body-size: 1rem; --motion-fast: 120ms; color: var(--text); background: var(--surface); font-size: var(--body-size);}.tool-system[data-theme="dark"] { --surface: #17212b; --text: #fff; --action: #a7d4ff; --on-action: #17212b; --error: #ffb4b4; --focus: #a7d4ff;}.ds-button { font: inherit; min-block-size: 44px; padding: var(--space-2) var(--space-4); border: 1px solid currentColor; border-radius: .375rem; cursor: pointer; transition: background-color var(--motion-fast); }.ds-button[data-variant="primary"] { background: var(--action); color: var(--on-action); }.ds-button[data-variant="secondary"] { background: var(--surface); color: var(--text); }.ds-button:disabled { opacity: .65; cursor: default; }.tool-system :focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }.ds-field { display: grid; gap: var(--space-2); margin-block: var(--space-4); }.ds-field input { font: inherit; padding: var(--space-2); color: var(--text); background: var(--surface); min-inline-size: 0; }.ds-error { color: var(--error); }.ds-card, .ds-dialog { border: 1px solid currentColor; padding: var(--space-4); background: var(--surface); color: var(--text); }.ds-card { overflow-wrap: anywhere; }.ds-dialog { max-inline-size: min(28rem, 85vw); }.ds-dialog::backdrop { background: rgb(0 0 0 / .55); }@media (prefers-reduced-motion: reduce) { .tool-system { --motion-fast: 0ms; } }Import this stylesheet in a reviewed React build and put the components inside a tool-system ancestor. Change data-theme to dark: the primary action keeps its purpose but receives a different background and foreground. The spacing uses logical block/inline dimensions where direction matters; the horizontal padding shorthand is symmetric. The 44px minimum is an illustrative usability target, not a proof of WCAG compliance. Check contrast, focus, zoom, forced colors and reduced motion in the real app. CSS custom properties are one delivery mechanism; the Design Tokens Community Group format is a separate interchange specification for tools. This CSS is not a DTCG JSON document. If an automated token build resolves aliases, reject missing references and cycles before emitting styles.
Constrain the primitive contract
import React, {type ReactNode} from 'react';export type ButtonProps = { children: ReactNode; variant?: 'primary' | 'secondary'; type?: 'button' | 'submit' | 'reset'; disabled?: boolean; loading?: boolean; onClick?: () => void;};export function Button({children, variant = 'primary', type = 'button', disabled = false, loading = false, onClick}: ButtonProps) { return <button className="ds-button" data-variant={variant} type={type} disabled={disabled || loading} onClick={onClick}> {children}{loading && ' (working)'} </button>;}A secondary action changes its visual emphasis without changing its native role. The default type is button so a secondary action inside a form does not accidentally submit. A real submit action must opt in to type="submit". Loading disables activation and adds visible text. The parent owns the actual request and should expose a persistent status message and guard duplicate submissions at the service boundary; this control is not a network idempotency mechanism. This example intentionally excludes arbitrary DOM prop forwarding, polymorphic tags and icon-only usage. The child content must provide a meaningful accessible name; document that requirement. Native disabled may remove the control from keyboard navigation, so choose the pending interaction and focus policy deliberately.
Compose a preview rather than adding arbitrary colors
import React, {useState} from 'react';import {Button} from './Button';import './system.css';export default function TokenPreview() { const [dark, setDark] = useState(false); return <section className="tool-system" data-theme={dark ? 'dark' : 'light'}> <h2>Tool library</h2> <Button variant="secondary" onClick={() => setDark(d => !d)}> Switch to {dark ? 'light' : 'dark'} theme </Button> <p><Button>Reserve drill</Button></p> </section>;}The theme switch is active; Reserve drill is only a visual preview and does not create a reservation. Production applications should not expose an apparently active no-op action. Use this isolated example to compare the same token roles in two themes. MUI offers Material Design components; Chakra exposes a theming system with tokens and styling recipes; Radix Primitives supply unstyled behavior primitives; shadcn/ui distributes component source for local ownership. Compare these candidates by required interaction patterns, visual ownership, dependency maintenance, compatibility and actual package licenses; no candidate was installed or audited here. A styled component does not guarantee accessibility in a composed product. Practice: add a semantic border token and verify its two theme values without changing Button.