Skip to content

refactor: migrate components from raw text size tokens to semantic type scale tokens - #661

Merged
ernestt merged 2 commits into
mainfrom
navi/refactor/semantic-text-tokens
Mar 20, 2026
Merged

ernestt merged 2 commits into
mainfrom
navi/refactor/semantic-text-tokens

Conversation

@ernestt

@ernestt ernestt commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Migrates all component files from raw textSizeVars to semantic typeScaleVars tokens for fontSize.

Before: fontSize: textSizeVars['--text-xsm']
After: fontSize: typeScaleVars['--text-supporting-size']

This makes font sizes themeable through the type scale system — change the base size or ratio and all components follow.

Files changed: 52

All component .tsx/.ts files that referenced textSizeVars directly now use typeScaleVars semantic tokens.

Follow-up: lineHeight migration

Many files now pair typeScaleVars fontSize with raw lineHeightVars. Safe-to-migrate pairings where the values are identical:

  • --text-body-size + lineHeightVars['--leading-base'] → typeScaleVars['--text-body-leading']
  • --text-label-size + lineHeightVars['--leading-base'] → typeScaleVars['--text-label-leading']

Intentional overrides that should stay as raw lineHeightVars (different values):

  • --text-supporting-size + --leading-snug (tighter than --text-supporting-leading for dense UI)
  • --text-large-size + --leading-tight / --leading-snug (tighter than --text-large-leading for headings)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 17, 2026
@ernestt
ernestt marked this pull request as ready for review March 17, 2026 19:06
@ernestt
ernestt requested a review from cixzhang as a code owner March 17, 2026 19:06
@ernestt
ernestt marked this pull request as draft March 17, 2026 19:06
@ernestt
ernestt marked this pull request as ready for review March 17, 2026 19:30
@ernestt
ernestt marked this pull request as draft March 17, 2026 19:31
Base automatically changed from navi/feat/type-scale-system to main March 17, 2026 20:54
@ernestt
ernestt force-pushed the navi/refactor/semantic-text-tokens branch 3 times, most recently from d75c691 to 49ef480 Compare March 17, 2026 23:39
@github-actions

github-actions Bot commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

AppShell · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 801B N/A
Lines of Code N/A 544 -
Complexity N/A Very High (88) -
Badge · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 203B N/A
Lines of Code N/A 132 -
Complexity N/A Low (3) -
Banner · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 429B N/A
Lines of Code N/A 277 -
Complexity N/A High (21) -
Breadcrumbs · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 289B N/A
Lines of Code N/A 278 -
Complexity N/A Medium (13) -
Button · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 333B N/A
Lines of Code N/A 293 -
Complexity N/A High (22) -
Calendar · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 933B N/A
Lines of Code N/A 925 -
Complexity N/A Very High (122) -
CheckboxInput · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 443B N/A
Lines of Code N/A 366 -
Complexity N/A Very High (32) -
Collapsible · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 4.6KB N/A
Lines of Code N/A 244 -
Complexity N/A High (18) -
DateInput · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 787B N/A
Lines of Code N/A 388 -
Complexity N/A Very High (47) -
Divider · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 239B N/A
Lines of Code N/A 138 -
Complexity N/A Medium (9) -
DropdownMenu · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 687B N/A
Lines of Code N/A 511 -
Complexity N/A Very High (63) -
EmptyState · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 213B N/A
Lines of Code N/A 132 -
Complexity N/A Medium (8) -
Field · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 818B N/A
Lines of Code N/A 505 -
Complexity N/A High (19) -
Kbd · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 199B N/A
Lines of Code N/A 97 -
Complexity N/A Medium (10) -
Link · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 581B N/A
Lines of Code N/A 228 -
Complexity N/A Medium (11) -
List · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 231B N/A
Lines of Code N/A 391 -
Complexity N/A Very High (35) -
MoreMenu · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 625B N/A
Lines of Code N/A 374 -
Complexity N/A Very High (49) -
NavItem
Metric Before After Delta
Bundle Size (ESM) N/A 181B N/A
Lines of Code N/A 58 -
Complexity N/A Low (1) -
NumberInput · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 471B N/A
Lines of Code N/A 357 -
Complexity N/A Very High (52) -
Pagination · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 799B N/A
Lines of Code N/A 383 -
Complexity N/A Very High (49) -
Popover · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 345B N/A
Lines of Code N/A 474 -
Complexity N/A Very High (42) -
PowerSearch · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.4KB N/A
Lines of Code N/A 3042 -
Complexity N/A Very High (296) -
ProgressBar · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 215B N/A
Lines of Code N/A 215 -
Complexity N/A Medium (13) -
RadioList · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 475B N/A
Lines of Code N/A 406 -
Complexity N/A High (28) -
Selector · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.1KB N/A
Lines of Code N/A 928 -
Complexity N/A Very High (47) -
SideNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.1KB N/A
Lines of Code N/A 1488 -
Complexity N/A Very High (146) -
Slider · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 429B N/A
Lines of Code N/A 615 -
Complexity N/A Very High (75) -
Switch · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 429B N/A
Lines of Code N/A 325 -
Complexity N/A High (30) -
TabList · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 479B N/A
Lines of Code N/A 559 -
Complexity N/A High (26) -
Table · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 863B N/A
Lines of Code N/A 847 -
Complexity N/A Very High (54) -
TextArea · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 497B N/A
Lines of Code N/A 235 -
Complexity N/A High (27) -
TextInput · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 499B N/A
Lines of Code N/A 222 -
Complexity N/A High (25) -
TimeInput · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 499B N/A
Lines of Code N/A 384 -
Complexity N/A Very High (54) -
Token · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 267B N/A
Lines of Code N/A 357 -
Complexity N/A Medium (14) -
TopNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.2KB N/A
Lines of Code N/A 1508 -
Complexity N/A Very High (92) -
TreeList · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 241B N/A
Lines of Code N/A 678 -
Complexity N/A Very High (60) -
Typeahead · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 619B N/A
Lines of Code N/A 887 -
Complexity N/A Very High (121) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 10.8KB 17.3KB 2.7KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang

Copy link
Copy Markdown
Contributor

Rebase notes after PR #665

PR #665 just landed with significant changes to theme CSS generation. Here's what to expect when rebasing:

Files removed:

  • typography.css — deleted entirely. If your branch references it, remove those imports.
  • XDSFontWrapper.tsx — deleted. If your branch touches it, drop those changes.
  • FontWrapper.stories.tsx — deleted.
  • dist/index.css import in storybook preview — removed (was generated from typography.css).

Files changed that will likely conflict:

  • packages/core/src/Text/index.ts — FontWrapper exports removed
  • packages/core/src/theme/defineTheme.ts — generateThemeCSS refactored into generateThemeRules (shared intermediary). If your branch modifies generateThemeCSS, the changes need to go into generateThemeRules instead.
  • packages/core/src/theme/expandTypeScale.ts — now outputs rem instead of px (e.g. 1.5rem not 24px)
  • packages/core/src/theme/index.ts — new export generateThemeRules
  • packages/core/package.json — ./typography.css export removed
  • packages/core/src/Text/Text.doc.mjs — FontWrapper entries removed

Key architectural change:
Both runtime and build paths now use generateThemeRules(theme) from @xds/core/theme. The function produces an array of CSS rule strings including:

  1. Token :scope block
  2. Component .xds-* overrides
  3. Prose HTML element rules (h1-h6, p, small, code, hr)
  4. Prop-level color overrides (.xds-text.primary, etc.)

If your semantic token migration changes how component styles reference tokens, those should still work — generateTypeScaleComponents produces the var() references.

@ernestt
ernestt marked this pull request as ready for review March 19, 2026 16:44
@ernestt
ernestt force-pushed the navi/refactor/semantic-text-tokens branch from 49ef480 to acd9467 Compare March 19, 2026 17:08
@cixzhang
cixzhang force-pushed the navi/refactor/semantic-text-tokens branch from acd9467 to 6adb50d Compare March 20, 2026 22:11
@cixzhang
cixzhang requested a review from josephfarina as a code owner March 20, 2026 22:11
@cixzhang
cixzhang force-pushed the navi/refactor/semantic-text-tokens branch from 6adb50d to 9c1e5da Compare March 20, 2026 22:18
…pe scale tokens

Components now reference semantic type scale tokens (typeScaleVars) instead
of raw text size tokens (textSizeVars) for font sizing. This is the same
principle as using --color-accent instead of a hex code — components should
reference the semantic layer, not the raw palette.

The raw --text-* tokens (--text-base, --text-sm, --text-xsm, --text-lg)
are a size palette — they define what sizes exist. The semantic type scale
tokens (--text-body-size, --text-label-size, --text-supporting-size,
--text-large-size) define what sizes mean. Components should express intent
("this is a label", "this is supporting text") not implementation
("this is 14px", "this is 12px").

With this change, adjusting the type scale via defineTheme's typeScale
config now affects ALL text in the system — headings, body text, button
labels, table cells, nav items, form controls — not just XDSHeading
and XDSText.

| Raw token | Semantic token | Used for |
|-----------|---------------|----------|
| --text-base | --text-label-size | Interactive controls: buttons, tabs, selectors, menu items, form labels, nav items |
| --text-base | --text-body-size | Content: text inputs, links, descriptions, table cells (spacious) |
| --text-sm | --text-supporting-size | Secondary: descriptions, breadcrumbs, captions, placeholders |
| --text-xsm | --text-supporting-size | Compact: badges, helper text, field status, keyboard shortcuts |
| --text-lg | --text-large-size | Emphasis: empty state titles, nav headings |
| --text-2xs | --text-supporting-size | Micro: compact density descriptions |

Note: Both --text-sm and --text-xsm map to --text-supporting-size.
The distinction between these two raw sizes was arbitrary — they both
serve the same semantic purpose (secondary/supporting information).
The type scale system resolves this by having a single supporting size
that themes control via { base, ratio }.

47 component files updated. Each change replaces a textSizeVars reference
with the semantically correct typeScaleVars reference. Zero net line change
(142 insertions, 142 deletions) — this is a pure token migration.

This PR depends on #638 (type scale system) which defines the semantic
tokens. It should be merged after #638.

Co-authored-by: navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/refactor/semantic-text-tokens branch from 9c1e5da to 70551a9 Compare March 20, 2026 22:27
…ng for descriptions

- ListItem/TreeListItem compact+balanced: supporting → body (primary item text)
- TableCell compact: supporting → body (table data content)
- TableHeaderCell all densities: → label (headers are labels)
- BreadcrumbItem/Breadcrumbs defaultSize: supporting → body (navigational text)
- ProgressBar label+valueLabel: supporting → body (progress label text)
- Calendar dayCell: supporting → body (interactive day numbers)

Supporting text is for descriptions, sublabels, and subtext only.
@ernestt
ernestt merged commit 7b0b7d6 into main Mar 20, 2026
12 of 13 checks passed
@cixzhang
cixzhang deleted the navi/refactor/semantic-text-tokens branch April 9, 2026 14:34
cixzhang pushed a commit that referenced this pull request Apr 26, 2026
…pe scale tokens (#661)

* refactor: migrate components from raw text size tokens to semantic type scale tokens

Components now reference semantic type scale tokens (typeScaleVars) instead
of raw text size tokens (textSizeVars) for font sizing. This is the same
principle as using --color-accent instead of a hex code — components should
reference the semantic layer, not the raw palette.

The raw --text-* tokens (--text-base, --text-sm, --text-xsm, --text-lg)
are a size palette — they define what sizes exist. The semantic type scale
tokens (--text-body-size, --text-label-size, --text-supporting-size,
--text-large-size) define what sizes mean. Components should express intent
("this is a label", "this is supporting text") not implementation
("this is 14px", "this is 12px").

With this change, adjusting the type scale via defineTheme's typeScale
config now affects ALL text in the system — headings, body text, button
labels, table cells, nav items, form controls — not just XDSHeading
and XDSText.

| Raw token | Semantic token | Used for |
|-----------|---------------|----------|
| --text-base | --text-label-size | Interactive controls: buttons, tabs, selectors, menu items, form labels, nav items |
| --text-base | --text-body-size | Content: text inputs, links, descriptions, table cells (spacious) |
| --text-sm | --text-supporting-size | Secondary: descriptions, breadcrumbs, captions, placeholders |
| --text-xsm | --text-supporting-size | Compact: badges, helper text, field status, keyboard shortcuts |
| --text-lg | --text-large-size | Emphasis: empty state titles, nav headings |
| --text-2xs | --text-supporting-size | Micro: compact density descriptions |

Note: Both --text-sm and --text-xsm map to --text-supporting-size.
The distinction between these two raw sizes was arbitrary — they both
serve the same semantic purpose (secondary/supporting information).
The type scale system resolves this by having a single supporting size
that themes control via { base, ratio }.

47 component files updated. Each change replaces a textSizeVars reference
with the semantically correct typeScaleVars reference. Zero net line change
(142 insertions, 142 deletions) — this is a pure token migration.

This PR depends on #638 (type scale system) which defines the semantic
tokens. It should be merged after #638.

Co-authored-by: navi <[email protected]>

* fix: use body/label tokens for primary content text, reserve supporting for descriptions

- ListItem/TreeListItem compact+balanced: supporting → body (primary item text)
- TableCell compact: supporting → body (table data content)
- TableHeaderCell all densities: → label (headers are labels)
- BreadcrumbItem/Breadcrumbs defaultSize: supporting → body (navigational text)
- ProgressBar label+valueLabel: supporting → body (progress label text)
- Calendar dayCell: supporting → body (interactive day numbers)

Supporting text is for descriptions, sublabels, and subtext only.

---------

Co-authored-by: navi <[email protected]>
cixzhang pushed a commit that referenced this pull request Jun 21, 2026
…pe scale tokens (#661)

* refactor: migrate components from raw text size tokens to semantic type scale tokens

Components now reference semantic type scale tokens (typeScaleVars) instead
of raw text size tokens (textSizeVars) for font sizing. This is the same
principle as using --color-accent instead of a hex code — components should
reference the semantic layer, not the raw palette.

The raw --text-* tokens (--text-base, --text-sm, --text-xsm, --text-lg)
are a size palette — they define what sizes exist. The semantic type scale
tokens (--text-body-size, --text-label-size, --text-supporting-size,
--text-large-size) define what sizes mean. Components should express intent
("this is a label", "this is supporting text") not implementation
("this is 14px", "this is 12px").

With this change, adjusting the type scale via defineTheme's typeScale
config now affects ALL text in the system — headings, body text, button
labels, table cells, nav items, form controls — not just XDSHeading
and XDSText.

| Raw token | Semantic token | Used for |
|-----------|---------------|----------|
| --text-base | --text-label-size | Interactive controls: buttons, tabs, selectors, menu items, form labels, nav items |
| --text-base | --text-body-size | Content: text inputs, links, descriptions, table cells (spacious) |
| --text-sm | --text-supporting-size | Secondary: descriptions, breadcrumbs, captions, placeholders |
| --text-xsm | --text-supporting-size | Compact: badges, helper text, field status, keyboard shortcuts |
| --text-lg | --text-large-size | Emphasis: empty state titles, nav headings |
| --text-2xs | --text-supporting-size | Micro: compact density descriptions |

Note: Both --text-sm and --text-xsm map to --text-supporting-size.
The distinction between these two raw sizes was arbitrary — they both
serve the same semantic purpose (secondary/supporting information).
The type scale system resolves this by having a single supporting size
that themes control via { base, ratio }.

47 component files updated. Each change replaces a textSizeVars reference
with the semantically correct typeScaleVars reference. Zero net line change
(142 insertions, 142 deletions) — this is a pure token migration.

This PR depends on #638 (type scale system) which defines the semantic
tokens. It should be merged after #638.

Co-authored-by: navi <[email protected]>

* fix: use body/label tokens for primary content text, reserve supporting for descriptions

- ListItem/TreeListItem compact+balanced: supporting → body (primary item text)
- TableCell compact: supporting → body (table data content)
- TableHeaderCell all densities: → label (headers are labels)
- BreadcrumbItem/Breadcrumbs defaultSize: supporting → body (navigational text)
- ProgressBar label+valueLabel: supporting → body (progress label text)
- Calendar dayCell: supporting → body (interactive day numbers)

Supporting text is for descriptions, sublabels, and subtext only.

---------

Co-authored-by: navi <[email protected]>
cixzhang pushed a commit that referenced this pull request Jun 21, 2026
…pe scale tokens (#661)

* refactor: migrate components from raw text size tokens to semantic type scale tokens

Components now reference semantic type scale tokens (typeScaleVars) instead
of raw text size tokens (textSizeVars) for font sizing. This is the same
principle as using --color-accent instead of a hex code — components should
reference the semantic layer, not the raw palette.

The raw --text-* tokens (--text-base, --text-sm, --text-xsm, --text-lg)
are a size palette — they define what sizes exist. The semantic type scale
tokens (--text-body-size, --text-label-size, --text-supporting-size,
--text-large-size) define what sizes mean. Components should express intent
("this is a label", "this is supporting text") not implementation
("this is 14px", "this is 12px").

With this change, adjusting the type scale via defineTheme's typeScale
config now affects ALL text in the system — headings, body text, button
labels, table cells, nav items, form controls — not just XDSHeading
and XDSText.

| Raw token | Semantic token | Used for |
|-----------|---------------|----------|
| --text-base | --text-label-size | Interactive controls: buttons, tabs, selectors, menu items, form labels, nav items |
| --text-base | --text-body-size | Content: text inputs, links, descriptions, table cells (spacious) |
| --text-sm | --text-supporting-size | Secondary: descriptions, breadcrumbs, captions, placeholders |
| --text-xsm | --text-supporting-size | Compact: badges, helper text, field status, keyboard shortcuts |
| --text-lg | --text-large-size | Emphasis: empty state titles, nav headings |
| --text-2xs | --text-supporting-size | Micro: compact density descriptions |

Note: Both --text-sm and --text-xsm map to --text-supporting-size.
The distinction between these two raw sizes was arbitrary — they both
serve the same semantic purpose (secondary/supporting information).
The type scale system resolves this by having a single supporting size
that themes control via { base, ratio }.

47 component files updated. Each change replaces a textSizeVars reference
with the semantically correct typeScaleVars reference. Zero net line change
(142 insertions, 142 deletions) — this is a pure token migration.

This PR depends on #638 (type scale system) which defines the semantic
tokens. It should be merged after #638.


* fix: use body/label tokens for primary content text, reserve supporting for descriptions

- ListItem/TreeListItem compact+balanced: supporting → body (primary item text)
- TableCell compact: supporting → body (table data content)
- TableHeaderCell all densities: → label (headers are labels)
- BreadcrumbItem/Breadcrumbs defaultSize: supporting → body (navigational text)
- ProgressBar label+valueLabel: supporting → body (progress label text)
- Calendar dayCell: supporting → body (interactive day numbers)

Supporting text is for descriptions, sublabels, and subtext only.

---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants