A semantic layer built on top of shadcn. Component source remains unforked; everything expressive — brand, theme, density, dark mode, contrast — moves into a three-tier token pipeline, with an interface for tracing and overriding it. The semantic naming is the substantive part: generated interfaces require roles that can be reasoned about rather than hex values that have to be inferred.
Platform:
Web (React, Tailwind)
Year:
2026
Role:
Design & build
Stack:
shadcn · Base UI · Style Dictionary
Platform:
Web (React, Tailwind)
Year:
2026
Role:
Design & build
Stack:
shadcn · Base UI · Style Dictionary
Introduction
The problem: components without a semantic vocabulary
Copy-paste component libraries address only half of the problem. A project receives forty accessible, well-built components in its own repository, but they arrive full of hardcoded utility classes and raw variable names that carry no meaning outside the file they sit in. There is no answer to the question of what colour a destructive action is in a given brand, because the answer is written as bg-red-500 in nine separate places. Design System v2 adds a semantic layer above that: roles, weights and states with names, resolved through tokens, with the component source left exactly as it arrived.
Three token tiers — primitive, semantic, component — resolved by Style Dictionary in W3C DTCG format.
Four bridge layers so shadcn components pick up tokens without a single edit to their source.
465 tokens, of which 213 are semantic colours: 10 roles × 7 weights, with 5 states on the interactive weights.
Dark mode as 213 redeclared semantic values under one attribute — no JavaScript involved.
A six-tab interface for tracing a component's token chain, editing semantics, and exporting overrides.
Spec-Driven
Spec-first repository structure
The repository is written spec-first. Four markdown documents hold the rules — the architecture and phase gates, the token specification, the bridge implementation, and the working agreement for anyone editing the repository — and the token values sit beside them as W3C DTCG JSON. Nothing downstream is authored twice. Style Dictionary resolves the JSON into CSS, a Tailwind preset and the bridge, with outputReferences enabled so that the var() chains survive into the output and the browser performs the final resolution at runtime. That is what makes dark mode a redeclaration rather than a rebuild, and it follows from the underlying principle: values are referenced, never copied.
Fig. 01 — Spec as the source, and the one place it leaks. Audited against the repo, not taken on trust.
Audit: what held, and what drifted
The system was audited rather than assumed correct. Every one of the 58 colour tokens documented on the docs site still exists in the build, with no orphans and no dangling renames, and the swatches render correctly because they read the live custom property. The documentation site builds without errors across 50 pages. However, 20 of those 58 printed hex labels are incorrect. The neutral palette moved from gray to stone and the interactive role from blue to sky, and because those labels are typed into the MDX by hand rather than read from the token, they remained on the previous values. The bridge shows the same fault in the opposite direction: seven variables ship in the CSS that the specification does not mention.
The conclusion is narrower than a general instruction to keep documentation in sync. Spec-driven development holds exactly as far as consumption is by reference. A swatch declaring background: var(--color-neutral-surface) resolves to the current value, whereas a caption stating #f9fafb is a copy and diverges as soon as the token changes. The remedy is structural rather than procedural: read the value at render time, or generate the page from the tokens.
The existing enforcement mechanism
One enforcement mechanism already exists in the repository, and it serves as a model for the rest. A Storybook story renders every Tailwind utility the components rely on — text-sm, rounded-lg, font-medium and the others — reads back the computed style, and marks each according to whether it resolved to a var() reference or to a raw pixel value. This makes the scale replacement verifiable rather than asserted. It covers the component layer. It does not cover the documentation layer, which is where the drift occurred.
The Semantic Layer
Semantic naming: roles rather than values
A primitive token records gray-950. A semantic token records color-neutral-heavy, denoting darkest text and high-contrast labels. The first states a fact about a colour, the second states a decision about a role, and only the second survives a rebrand. Every semantic token references a primitive rather than restating its value, so the brand can be replaced underneath without modifying any component, and the chain remains inspectable end to end.
Semantic roles and generative interfaces
Semantic naming becomes more significant where interfaces are generated. If a model assembles an interface, or a component that does not yet exist has to be styled correctly on first render, it requires a vocabulary with meaning attached. An instruction expressed as critical, trim weight, hover state can be reasoned about and validated, whereas a hex value such as #dc2626 is correct in one theme and wrong in the other. Semantic roles give generation a target that can be checked, and give review a question that can be answered: whether the role is correct, rather than whether the colour is.
Fig. 02 — The semantic colour grid. A designer picks a role and a weight; the state variants come with it.
Ten roles, seven weights, and five states on the four interactive weights. The resulting count is the argument for generating tokens rather than authoring them: 213 colour values exceeds the point at which consistency can be maintained by hand, and each value has to hold its contrast relationship in both themes.
The Bridge
The bridge: four layers, with component source unmodified
The hard constraint was that shadcn component source is never modified. That keeps updates inexpensive, since a new version is a copy rather than a merge conflict, but it requires the tokens to reach the components from outside. Layer one maps shadcn's stable CSS variable names onto semantic tokens, which covers every colour in every component, including components not yet added. Layer two replaces Tailwind's default scales rather than extending them, so the utility classes already present in the source — text-sm, rounded-lg, font-medium — resolve to token variables at build time. Layer three adds role-named utilities for components shadcn does not ship. Layer four scopes per-component variables by data-slot, so a single component can be restyled without affecting the role it inherits from.
Fig. 03 — The bridge. Four layers so that the component source stays vanilla and everything expressive lives in tokens.
The distinction in layer two determines whether the approach works at all. Keys placed under Tailwind's theme replace its defaults; keys placed under theme.extend are added alongside them. Under extend, text-sm remains hardcoded at 0.875rem and the typography scale stays outside the token system.
One component, traced. Button's --radius, --spacing-sm and --text-sm resolve through the bridge into semantic tokens and land on primitives; everything it does not touch is dimmed.
Theming
Theming through token overrides
Because the semantic layer is the only interface the components see, applying a brand consists of overriding token values, rather than rewriting components or maintaining a parallel copy of the library. The primitive palette is replaced, the semantic references remain identical, and all forty components change simultaneously. Dark mode is the same operation at smaller scale: 213 semantic colour values redeclared under a data attribute, with the browser resolving the var() chain at runtime, without a theme provider and without a re-render.
Semantics. Typography roles composed from primitives, each showing the primitive it references — change the reference, not the hundred places it is used.
Accessibility
Generating colour ramps
A brand colour arrives as a single hex value and has to become an eleven-step ramp that meets its contrast obligations at every step, in both themes. Ramps selected by eye tend to appear even and measure poorly. These are generated with Chroma Sculptor, a separate tool, which builds the ramp in a perceptual colour space, reports the contrast of every step against both ends, and allows the chroma curve to be shaped against the gamut rather than estimated.
Eleven steps generated in CIE L*a*b*, each reported in OKLCH with its WCAG contrast against white and black, AA and AAA labelled per step. APCA is available alongside WCAG.
Fig. 04 — Every step carries its contrast with it. Step 500 is the pivot: the last step that fails AA on white is the first that clears it on black, which is what makes a light/dark token pair mechanical rather than hand-tuned.
Perceptual colour space and contrast thresholds
Ramps produced by adjusting HSL values are perceptually uneven, because HSL lightness does not correspond to measured lightness. The same eleven steps generated on an even perceptual ramp read as evenly spaced in OKLCH and sag through the middle in HSL. That difference is the error a hand-tuned palette inherits, and it is why two brand colours with the same nominal lightness can fall on opposite sides of a contrast threshold.
Fig. 05 — Why the colour space matters. The ramp is even by construction; HSL reports it as uneven, and a palette tuned by HSL numbers inherits that error.
The chroma curve, shaped against the gamut boundary rather than guessed — stops are dragged in lightness/chroma space, with the maximum available chroma at each lightness drawn behind them.
The Interface
The token map interface
A token system that cannot be inspected becomes undocumented practice within a short period. The token map addresses this. Graph traces a component's full chain across four columns, Inspector reads a single node, Primitives and Semantics are editable views of the two token tiers, Preview renders components under the current values at three viewports, and Overrides toggles whole categories — border, spacing density, radius, shadow, sizing, motion, opacity, surface and z-index — then exports the result as JSON or CSS.
Overrides. Toggle a category, watch every component respond, then export the delta as JSON or CSS — this is what a brand handover looks like when the system is token-driven.
Preview, dark. The same components, the same component source — only the semantic values underneath have changed.
Primitives. The raw layer nothing is designed against directly, kept visible so that the references resolve to a legible value.
The Process
Foundations: shadcn Base UI components generated unmodified into the workspace, Storybook as the verification environment
Colour: Brand hues expanded into 11-step ramps in Chroma Sculptor, contrast checked per step against both themes
Tokens: W3C DTCG JSON in three tiers, resolved by Style Dictionary with references preserved into the CSS output
Bridge: CSS var mapping, Tailwind scale replacement, named utilities, per-component data-slot scoping
Verification: A coverage story that fails if any component cell shows a raw pixel value instead of a var() reference
Interface: Token map for tracing, editing and exporting overrides across six views