Add JSON typography and size map exports to brand-primitives - #1394
Add JSON typography and size map exports to brand-primitives#1394stefankp wants to merge 3 commits into
Conversation
Mirror the color map export (#1370) with per-type json/one-dimensional exports for typography and size tokens, written to lib/design-tokens/json/{typography,size}.json. Typography sources the two files brand ships in its CSS entry (base typography + functional responsive typography); size sources base size, functional size, breakpoints and border, and additionally filters by a new isSizeValue value-shape predicate to drop non-size values (animation easing/duration, inset border composites) that live alongside sizes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The typography allowlist is name-based, so it must cover every shipped typography custom property. Source functional/typography/typography.json for its --brand-text-body/title/caption/subtitle/display/code tokens and --brand-fontStack-sansSerifDisplay (43 names present nowhere else), ordering typography-responsive.json last so brand (Mona Sans) fontStack values win the name collisions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 42e9a10 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🟢 No design token changes found |
🟢 Bundle size report
|
There was a problem hiding this comment.
Pull request overview
Adds two new one-dimensional JSON token map exports (typography + size) to @primer/brand-primitives, intended for downstream tooling to validate var(--…) references against the set of custom properties Brand actually ships—mirroring the existing colors.json export.
Changes:
- Added
isSizeValuepredicate (and unit tests) to include only length-like size tokens and exclude animation/time/easing, inset composites, and media-query ranges. - Added new
buildPrimitivessteps to generatelib/design-tokens/json/typography.jsonandlib/design-tokens/json/size.jsonvia the existingjson/one-dimensionalformat. - Added a changeset bump (consistent with the earlier color-map export) to publish the new artifacts.
Show a summary per file
| File | Description |
|---|---|
| packages/design-tokens/src/filters/isSizeValue.js | Adds the value-shape predicate used to select size/length tokens for the size JSON export. |
| packages/design-tokens/src/filters/isSizeValue.test.js | Adds unit tests covering the intended include/exclude cases for size token values. |
| packages/design-tokens/scripts/build-tokens.js | Adds build steps to emit json/typography.json and json/size.json using the existing one-dimensional JSON format and appropriate filtering/prefixing rules. |
| .changeset/brand-functional-token-maps-export.md | Declares a release bump to publish the new JSON exports. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Low
🟢 No visual differences foundOur visual comparison tests did not find any differences in the UI. |
|
Worth calling out a change to the typography export, since it changes the shape of the output. The map was originally built from three sources, including That matters more than the count. This export is consumed as a name-based allowlist, so including a token that's never defined green-lights The export goes from 152 → 109 tokens. I cross-checked the emitted key list against the typography primitives actually defined in the built Two things this also cleans up:
The description has been updated to match. |
Summary
Adds two per-type JSON token maps to
@primer/brand-primitives, mirroring the color map export merged in #1370:lib/design-tokens/json/typography.jsonandlib/design-tokens/json/size.json. Each is a one-dimensional map keyed by CSS custom-property name (--brand-*/--base-*) → value, reusing the existingjson/one-dimensionalStyle Dictionary format.These back downstream tooling (e.g. stylelint rules) that validates
var(--…)references against the set of custom properties brand actually ships. It's a name-based allowlist, so each export is scoped to exactly match brand's shipped custom properties for that category. Colors were done in #1370; typography and size are next.Example —
typography.json:{ "--base-text-weight-bold": 700, "--brand-body-fontFamily": "'Mona Sans', 'MonaSansFallback',-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'", "--brand-fontStack-sansSerif": "'Mona Sans', 'MonaSansFallback',-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'", "--brand-heading-lineHeight-400": "1.3", "--brand-text-size-200": "1rem", "--brand-text-size-800": "2rem", "--brand-text-weight-600": "var(--base-text-weight-normal)" }Example —
size.json:{ "--base-size-8": "0.5rem", "--base-size-16": "1rem", "--brand-borderRadius-medium": "0.5rem", "--brand-borderWidth-thin": "max(1px, 0.0625rem)", "--brand-box-spacing-normal": "1.5rem", "--brand-breakpoint-medium": "48rem", "--brand-control-medium-gap": "0.75rem" }List of notable changes:
lib/design-tokens/json/typography.json(109 tokens) — base typography + functional responsive typographylib/design-tokens/json/size.json(76 tokens) — base size + functional size, breakpoints and border widths/radiisrc/filters/isSizeValue.js(+ unit tests) — value-shape predicate that restricts the size export to length-valued tokensbuildPrimitivessteps inscripts/build-tokens.jsfor the typography and size exportsScope decisions (intentional exclusions):
functional/size/viewportis excluded — it emits only@custom-mediabreakpoint definitions (0 custom properties), never referenced asvar().--brand-control-animation-duration,--brand-control-animation-easing) are dropped byisSizeValue— they belong to a future animation rule.--brand-borderInset-*inset 0 0 0 …composites are dropped byisSizeValue— they'll belong to a future border rule.-autopointer variants fromsize-fine/size-coarseare excluded — those files aren't imported by brand and the tokens are referenced 0× in brand CSS, so they aren't shipped custom properties.functional/typography/typography.jsonis excluded —packages/react/src/css/stylesheets.tsdoesn't import the CSS built from it, so its 43 tokens (the--brand-text-{body,title,caption,subtitle,display,code*}-*styles plus--brand-fontStack-sansSerifDisplay) never become shipped custom properties. Same criterion as thesize-fine/size-coarseexclusion above. It's also what keeps--brand-fontStack-*on the Mona Sans values shown in the sample above — that file was the only thing redefining them to the generic system stack.Note: values in
size.jsonare resolved literals (e.g.--brand-borderRadius-medium: "0.5rem"), whereas typography and colors keepvar()references where present — but the key/name set, which is what the allowlist consumes, is complete and correct.What should reviewers focus on?
--brand-*/--base-*custom properties for that category.isSizeValuecorrectly keeps lengths / math functions / sizevar()refs and drops time, easing,inset …composites, and media-query ranges.Steps to test:
npm run build -w @primer/brand-primitiveslib/design-tokens/json/typography.json(109 entries) andsize.json(76 entries) are generatednpm test -w @primer/brand-primitives— 29 tests pass (incl. the newisSizeValuesuite)Supporting resources (related issues, external links, etc):
Contributor checklist:
update snapshotslabel to the PR) — N/A, no UI changesOut of scope: pre-existing issue in
colors.jsonWhile cross-checking the typography map against brand's built CSS, I found one entry in the existing
colors.jsonexport that isn't a shipped custom property:--brand-blinking-cursor-fgColor. It's defined only in the vendoredlib/design-tokens/css/tokens/functional/components/blinking-cursor/colors-with-modes.css, and nothing underpackages/react/srcimports that file — so the token is absent frommain.cssand from every per-component esm chunk.This came in with the color map export in #1370 and predates this PR. I've deliberately left it alone to keep this diff focused; flagging it here for reviewers and for a follow-up. The other 516 entries in
colors.jsoncheck out.