Skip to content

Typed design-token system#1

Merged
ThomasHartDev merged 1 commit into
mainfrom
thomas/feat/design-tokens
Jul 18, 2026
Merged

Typed design-token system#1
ThomasHartDev merged 1 commit into
mainfrom
thomas/feat/design-tokens

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

adds a small typed design-token tree in src/tokens that acts as the single origin for the app's design values. instead of hand-writing the same CSS variables twice, the token module generates the :root custom properties and the root layout injects them at render time, so there's one source and nothing to drift. the token() helper hands back a var() reference and is generic over the tree, so a wrong name is a compile error rather than a silent typo. also threw in a /tokens route that renders the swatches straight from the tree (stays a server component, no client JS) and wired the home page link to it. tests cover the kebab-casing, the var generation, empty groups, and the round-trip back into a :root rule anyway.

@ThomasHartDev

Copy link
Copy Markdown
Owner Author

walked through this again before merging. src/tokens/tokens.ts holds the values as one as const tree and exports the group/key types off it. index.ts is the only thing that knows how a token becomes a CSS name: varName() does the kebab-casing once, cssVarName/token wrap it with the generic key constraint so callers can't pass a name that isn't in the tree, and tokensToCssVariables/cssVariablesToRootRule walk the tree into a :root block. layout.tsx calls those at module scope and drops the result into a <style>, which is why globals.css lost its hardcoded token block. next build confirms / and /tokens both prerender static with no client JS, so the token route is a pure server component. only thing i left for later is light/dark theming, which is a second :root under a media query and belongs in its own PR.

@ThomasHartDev
ThomasHartDev merged commit 959914f into main Jul 18, 2026
1 check passed
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/design-tokens branch July 18, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant