Skip to content

feat: ratio-based type scale system with typeScale in defineTheme - #638

Merged
cixzhang merged 10 commits into
mainfrom
navi/feat/type-scale-system
Mar 17, 2026
Merged

cixzhang merged 10 commits into
mainfrom
navi/feat/type-scale-system

Conversation

@ernestt

@ernestt ernestt commented Mar 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements #586 — adds a configurable type scale system to XDS themes.

Type scale system

A single { base, ratio } config in defineTheme generates all heading and text typography tokens via geometric progression (size = base × ratio^step).

const theme = defineTheme({
  name: 'admin',
  typeScale: {
    base: 14,
    ratio: 1.2,
    // Optional: override weights per level/type
    weights: {
      heading: { 1: 'var(--font-weight-bold)' },
      text: { large: 'var(--font-weight-normal)' },
    },
  },
});

New default heading scale (base=14, ratio=1.2, h4=anchor)

Level Size Line-Height Previous
h1 24px 1.3333 20px
h2 20px 1.4 18px
h3 17px 1.4118 16px
h4 14px 1.4286 14px
h5 12px 1.3333 14px
h6 10px 1.6 12px

Generated CSS output (default theme)

This is what generateThemeCSS produces for the default theme with typeScale: { base: 14, ratio: 1.2 }:

@scope ([data-xds-theme="default"]) to ([data-xds-theme]) {
  :scope {
    --heading-1-size: 24px;
    --heading-1-weight: var(--font-weight-semibold);
    --heading-1-leading: 1.3333;
    --heading-2-size: 20px;
    --heading-2-weight: var(--font-weight-semibold);
    --heading-2-leading: 1.4;
    --heading-3-size: 17px;
    --heading-3-weight: var(--font-weight-semibold);
    --heading-3-leading: 1.4118;
    --heading-4-size: 14px;
    --heading-4-weight: var(--font-weight-semibold);
    --heading-4-leading: 1.4286;
    --heading-5-size: 12px;
    --heading-5-weight: var(--font-weight-semibold);
    --heading-5-leading: 1.3333;
    --heading-6-size: 10px;
    --heading-6-weight: var(--font-weight-semibold);
    --heading-6-leading: 1.6;
    --text-body-size: 14px;
    --text-body-weight: var(--font-weight-normal);
    --text-body-leading: 1.7143;
    --text-large-size: 17px;
    --text-large-weight: var(--font-weight-semibold);
    --text-large-leading: 1.6471;
    --text-label-size: 14px;
    --text-label-weight: var(--font-weight-medium);
    --text-label-leading: 1.4286;
    --text-code-size: 14px;
    --text-code-weight: var(--font-weight-normal);
    --text-code-leading: 1.7143;
    --text-supporting-size: 12px;
    --text-supporting-weight: var(--font-weight-normal);
    --text-supporting-leading: 1.6667;
  }

  .xds-heading.level-1 {
    font-family: var(--font-heading);
    font-size: var(--heading-1-size);
    font-weight: var(--heading-1-weight);
    line-height: var(--heading-1-leading);
    color: var(--color-text-primary);
  }

  /* ... levels 2-6 follow same pattern */

  .xds-text.body {
    font-family: var(--font-heading);
    font-size: var(--text-body-size);
    font-weight: var(--text-body-weight);
    line-height: var(--text-body-leading);
    color: var(--color-text-primary);
  }

  /* ... other text types follow same pattern */
}

What changed

New files:

  • expandTypeScale.ts — pure function: { base, ratio, weights? } → 33 token overrides
  • expandTypeScale.test.ts — tests for default, dense, airy scales + weight overrides

Core changes:

  • 33 new semantic tokens in tokens.stylex.ts — base values reference existing --text-* vars where possible, use unitless ratios for line-heights
  • defineTheme accepts optional typeScale config; explicit tokens take precedence
  • XDSTypeScaleConfig supports optional weights.heading and weights.text overrides
  • XDSHeading: removed variant prop (was 'default' | 'editorial')
  • XDSFontWrapper: removed variant prop (simplified to prose wrapper)
  • typography.css: removed editorial variant classes, uses type scale tokens
  • Default + neutral themes use typeScale: { base: 14, ratio: 1.2 } and reference type scale tokens
  • Theme Editor: interactive type scale controls in Typography tab with live preview

Breaking changes (nothing shipped to consumers):

  • Removed XDSHeadingVariant and XDSFontWrapperVariant types
  • Removed variant prop from XDSHeading and XDSFontWrapper
  • Removed editorial heading scale from themes and typography.css

Design decisions

  • Line-heights are unitless ratios (not px) so they scale proportionally when StyleX converts font sizes to relative units
  • Base token defaults reference --text-* vars where sizes align (24px → var(--text-3xl)) so the base system composes through the existing token layer
  • expandTypeScale() outputs computed px values for theme overrides, which take precedence over the var-referenced defaults
  • Weights are configurable via optional weights.heading / weights.text in the type scale config

Test results

All 1492 tests pass (92/92 test files).

Closes #586

Implements #586 — adds a configurable type scale system to XDS themes.

Type scale configuration:
- Single { base, ratio } config in defineTheme generates all heading
  and text typography tokens via geometric progression
- Default: base=14, ratio=1.2 with h4 anchored to base (14px)
- Headings h1-h3 scale up, h5-h6 scale down from the anchor
- 33 new semantic tokens (--heading-{n}-{size|weight|leading},
  --text-{type}-{size|weight|leading})

New default heading scale:
  h1: 24px, h2: 20px, h3: 17px, h4: 14px, h5: 12px, h6: 10px

API changes:
- defineTheme accepts optional typeScale: { base, ratio }
- Explicit token overrides take precedence over typeScale values
- expandTypeScale() exported as a pure computation function

Breaking changes (nothing shipped to consumers):
- Removed variant prop from XDSHeading (was 'default' | 'editorial')
- Removed variant prop from XDSFontWrapper (simplified to prose wrapper)
- Removed XDSHeadingVariant and XDSFontWrapperVariant types
- Removed editorial heading scale from default and neutral themes
- Removed editorial variant classes from typography.css

For mixed density regions, nest <XDSTheme> with a different typeScale
instead of using variant props — same mechanism as brand theming.

Theme component overrides (heading, text) now reference type scale
tokens (var(--heading-1-size)) instead of text size tokens
(var(--text-2xl)), so they automatically respond to typeScale changes.

Co-authored-by: navi <[email protected]>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 16, 2026
@github-actions

github-actions Bot commented Mar 16, 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

Text · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 433B N/A
Lines of Code N/A 513 -
Complexity N/A Very High (44) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 10.2KB 16.3KB 2.5KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

XDSText - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/22 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

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

ernestt and others added 2 commits March 16, 2026 23:36
Adds an interactive Type Scale tab to the Theme Editor with:
- Base size slider (10–24px) and ratio slider (1.05–1.5)
- Preset buttons: Dense (12/1.125), Default (14/1.2), Airy (16/1.25)
- Live heading scale preview (h1–h6 with computed sizes)
- Live text type preview (large, body, label, code, supporting)
- Prose preview via XDSFontWrapper
- Formula display showing the geometric progression
- Collapsible raw token values (33 tokens)
- Code generator emits typeScale config when non-default

Also updates Typography categories to reference new type scale tokens
(--heading-{n}-size instead of --text-2xl, etc.)

Co-authored-by: navi <[email protected]>
- Merged Type Scale controls into the Typography tab (no separate tab)
  Base/ratio sliders and presets sit above the typography category selector
- Removed Theme Editor header and Theme Name input
- Removed light/dark mode toggle — now derives from storybook's global
  dark mode via prefers-color-scheme and class observer
- Fixed double scrolling: replaced height:100vh with position:absolute inset:0,
  removed 24px padding wrapper on preview panel

Net -212 lines.

Co-authored-by: navi <[email protected]>
@ernestt
ernestt marked this pull request as ready for review March 16, 2026 23:56
@ernestt
ernestt requested a review from cixzhang as a code owner March 16, 2026 23:56
'--text-label-leading': '20px',
'--text-code-size': '14px', // base
'--text-code-weight': 'var(--font-weight-normal)',
'--text-code-leading': '24px',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line-height should be ratio-based instead of pixel based. StyleX will convert px sizes to ems.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — all leading values are now unitless ratios (e.g. '1.7143' instead of '24px'). The computeLeading() function in expandTypeScale.ts returns a unitless ratio snapped to 4px grid, so StyleX's em conversion works correctly.


tokens[`--text-${type}-size`] = `${size}px`;
tokens[`--text-${type}-weight`] = TEXT_WEIGHTS[type];
tokens[`--text-${type}-leading`] = `${lh}px`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always compute ratios here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — expandTypeScale() now returns unitless ratios via computeLeading() (e.g. '1.3333' not '32px').

@ernestt
ernestt marked this pull request as draft March 17, 2026 00:05
// No token overrides needed — defineTheme fills in defaults automatically.
// See packages/core/src/theme/tokens.stylex.ts for all token values.
tokens: {},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be implementing the new typeScale API?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes — defaultTheme now uses typeScale: {base: 14, ratio: 1.2} which feeds into defineTheme() → expandTypeScale() to generate all the heading/text tokens.

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would help for Navi to produce as part of the PR description the output of the build of one of the themes so we can inspect the real CSS output.

Comment on lines +83 to +90
const HEADING_WEIGHTS: Record<number, string> = {
1: 'var(--font-weight-semibold)',
2: 'var(--font-weight-semibold)',
3: 'var(--font-weight-semibold)',
4: 'var(--font-weight-semibold)',
5: 'var(--font-weight-semibold)',
6: 'var(--font-weight-semibold)',
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard coded for now? Did we want this to be configured as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now configurable — XDSTypeScaleConfig accepts an optional weights object with heading and text overrides. Defaults are in DEFAULT_HEADING_WEIGHTS / DEFAULT_TEXT_WEIGHTS and get merged with any overrides the theme provides.

Comment on lines +95 to +101
const TEXT_WEIGHTS: Record<string, string> = {
body: 'var(--font-weight-normal)',
large: 'var(--font-weight-semibold)',
label: 'var(--font-weight-medium)',
code: 'var(--font-weight-normal)',
supporting: 'var(--font-weight-normal)',
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix — text weights are also configurable now via weights.text in the config.


tokens[`--heading-${level}-size`] = `${size}px`;
tokens[`--heading-${level}-weight`] = HEADING_WEIGHTS[level];
tokens[`--heading-${level}-leading`] = `${lh}px`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compute ratios.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — heading leading is now a unitless ratio (e.g. '1.3333') computed by computeLeading(), same as text leading.

Two issues prevented the preview from updating when type scale sliders changed:

1. Missing component overrides — the preview theme had tokens but no CSS rules
   to consume them. Now includes defaultTheme.components which has rules like
   .xds-heading.level-1 { font-size: var(--heading-1-size) }.

2. Type scale tokens not emitted at default values — when tokens matched
   allDefaults they were excluded from the theme's :scope {} CSS. But the
   component rules reference var(--heading-1-size) which only exists when
   the theme explicitly sets it. Type scale tokens are now always included.

Also fixes outer padding conflict with storybook decorator (margin: -16).

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

export const typeScaleDefaults = {
// Heading tokens — h4 is the anchor at base (14px)
'--heading-1-size': '24px', // 14 × 1.2³

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where possible, let's use variables for anything in base. Otherwise our base values aren't compatible with our css vars by default. Themed values can be the absolute correct values but base values need to be themeable via vars.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — base token defaults now use var() references wherever a matching token exists:

  • Sizes: var(--text-3xl), var(--text-2xl), var(--text-base), var(--text-xsm), var(--text-3xs)
  • Weights: var(--font-weight-semibold), var(--font-weight-normal), etc.

Only h3 and text-large use raw '17px' since there's no matching --text-* token at that size. When typeScale is used in defineTheme, those get overridden with computed px values anyway.

Comment thread yarn.lock
"@tailwindcss/oxide-win32-x64-msvc" "4.2.1"

"@tailwindcss/postcss@^4.2.1":
"@tailwindcss/postcss@^4", "@tailwindcss/postcss@^4.2.1":

@cixzhang cixzhang Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, do you remember what this was about?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lockfile drift from yarn install — not an intentional change. The same line already landed on main independently via PR #634, so the branch and main are in sync. No action needed.

Addresses all review comments from #638:

1. Line-heights are now unitless ratios (e.g. '1.3333') instead of px
   values. snapLineHeight → computeLeading returns ratio snapped so
   computed px aligns to 4px grid. StyleX can convert font sizes to
   em/rem without breaking the proportional relationship.

2. typeScaleDefaults base values reference existing --text-* vars where
   possible (e.g. var(--text-3xl) instead of 24px) so they compose
   through the token system. expandTypeScale() outputs computed px
   values that override these when a theme configures typeScale.

3. Font weights are now configurable via optional weights.heading and
   weights.text in XDSTypeScaleConfig. Themes can override individual
   heading levels or text types. Unset values use defaults.

4. Default and neutral themes now use typeScale: { base: 14, ratio: 1.2 }
   to demonstrate the API and eat our own cooking.

5. Reverted stray yarn.lock change (tailwindcss dedup artifact).

Test count: 1492 (5 new weight override tests).

Co-authored-by: navi <[email protected]>
@ernestt
ernestt marked this pull request as ready for review March 17, 2026 16:29
ernestt and others added 2 commits March 17, 2026 16:37
The CI build uses strict noImplicitAny. Spreading Partial<Record<1|2|3|4|5|6, string>>
onto Record<number, string> produced index signature incompatibility because
the partial type includes undefined in its value type.

Fix: cast the optional spread operand to Record<number, string> | undefined
so the spread result has a clean Record<number, string> type.

Also reverts yarn.lock to match origin/main (stray dedup was re-introduced).

Co-authored-by: navi <[email protected]>
1. Fixed page-level scrolling: added overflow:hidden to outer container
   so the storybook decorator padding doesn't cause double scrollbars.

2. Added light/dark mode toggle to the Live Preview header bar.
   Removed 'See your changes in real-time' subtext.

3. Renamed presets: Dense→Functional, Airy→Editorial. Added
   'Recommended values' label above the preset buttons.

4. Replaced raw HTML spans/labels with XDSText/XDSHeading throughout
   the type scale editor for dogfooding.

5. Replaced ratio slider with a named-ratio selector dropdown:
   Minor Second (1.067), Major Second (1.125), Minor Third (1.2),
   Major Third (1.25), Perfect Fourth (1.333), Augmented Fourth (1.414),
   Perfect Fifth (1.5), Golden Ratio (1.618), plus a Custom option
   that reveals the slider for freeform values.

Co-authored-by: navi <[email protected]>
ernestt added a commit that referenced this pull request Mar 17, 2026
…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.

## Motivation

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.

## Semantic mapping

| 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 }.

## What changed

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.

## Depends on

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]>
Replaced all native HTML form controls with XDS components:
- Base Size <input type=range> → XDSSlider
- Scale Ratio <select> → XDSSelector (with section groups)
- Custom Ratio slider → XDSSlider
- Color category <select> → XDSSelector
- Typography category <select> → XDSSelector (with section groups)
- Category description <div> → XDSText

Fixed left panel padding: added top padding (16px) to token group
tabs area so content doesn't touch the top edge.

Net -61 lines — XDS components are more concise than raw HTML.

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

ernestt commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

@cixzhang addressed comments. Could I get a second look on this?

Comment thread packages/core/src/Text/Text.doc.mjs Outdated
{
label: 'Editorial heading',
code: '<XDSHeading level={1} variant="editorial">Article Title</XDSHeading>',
code: '<XDSHeading level={1}>Page Title</XDSHeading>',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need the font wrapper here now to demonstrate an editorial heading. But maybe we can skip this example since we have editorial scale below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — removed the duplicate 'Editorial heading' example (it was identical to the regular heading since we removed the variant prop). Also updated the XDSFontWrapper example to drop variant="editorial".

// Text — semantic text styles
// Text — semantic text styles, sized by type scale tokens
// =========================================================================
text: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to clean all this up because it's getting generated by typeScale right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes — implemented. defineTheme now auto-generates heading and text component override rules when typeScale is provided, via a new generateTypeScaleComponents() function. The generated rules include fontFamily, fontSize, fontWeight, and lineHeight.

Color is intentionally excluded — it's already handled by component internals (XDSHeading defaults to primary, XDSText has defaultColorByType). Including color in the generated rules would duplicate component logic and risk specificity conflicts with the color prop.

Explicit components entries deep-merge on top of auto-generated, so themes can still override individual levels (e.g. a display font on h1, letter-spacing tweaks).

The default theme now shrinks from ~60 lines of manual heading/text overrides to just the button secondary background.


// =========================================================================
// Heading — Geist font, same dense scale
// Heading — Geist font, sized by type scale tokens

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Seems like typescale should cover these? Do we think we still need manual overrides?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up — neutral theme now uses typeScale.weights.heading to express the bold h3/h4 weights, and the manual heading: { ... } and text: { ... } blocks are gone. The full config is now:

typeScale: {
  base: 14,
  ratio: 1.2,
  weights: {
    heading: {
      3: 'var(--font-weight-bold)',
      4: 'var(--font-weight-bold)',
    },
  },
},

The auto-generated component rules pick up the bold weights because expandTypeScale() merges weights.heading overrides into the generated --heading-3-weight / --heading-4-weight tokens, and the component rules reference those tokens.

// Heading — default variant (dense scale for internal tools)
// Heading — sized by type scale tokens
// =========================================================================
heading: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this could probably be cleaned up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up — the entire heading and text blocks are gone. See reply on the other comment for the full explanation of what the auto-generation produces.

Previous approach (position:absolute + margin:-16) tried to escape the
storybook decorator's padding:16 wrapper but left the decorator div with
a scrollable content height, causing body-level scroll.

position:fixed is always relative to the viewport — it truly escapes all
ancestor containers regardless of padding or overflow. margin:-16 is no
longer needed.

Also switched xdsTheme from 'none' to 'default' so the editor chrome
(left panel) receives proper XDS theming. The preview panel uses its
own nested <XDSTheme theme={currentTheme}>, which is unaffected.

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

ernestt commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Generated CSS Build Output

Here's the full CSS output that generateThemeCSS produces for the default theme with typeScale: { base: 14, ratio: 1.2 }. This is what gets injected into a <style> tag at runtime (or pre-compiled via xds theme build).

@layer xds.theme {
@scope ([data-xds-theme="default"]) to ([data-xds-theme]) {
  :scope {
    --heading-1-size: 24px;
    --heading-1-weight: var(--font-weight-semibold);
    --heading-1-leading: 1.3333;
    --heading-2-size: 20px;
    --heading-2-weight: var(--font-weight-semibold);
    --heading-2-leading: 1.4;
    --heading-3-size: 17px;
    --heading-3-weight: var(--font-weight-semibold);
    --heading-3-leading: 1.4118;
    --heading-4-size: 14px;
    --heading-4-weight: var(--font-weight-semibold);
    --heading-4-leading: 1.4286;
    --heading-5-size: 12px;
    --heading-5-weight: var(--font-weight-semibold);
    --heading-5-leading: 1.3333;
    --heading-6-size: 10px;
    --heading-6-weight: var(--font-weight-semibold);
    --heading-6-leading: 1.6;
    --text-body-size: 14px;
    --text-body-weight: var(--font-weight-normal);
    --text-body-leading: 1.7143;
    --text-large-size: 17px;
    --text-large-weight: var(--font-weight-semibold);
    --text-large-leading: 1.6471;
    --text-label-size: 14px;
    --text-label-weight: var(--font-weight-medium);
    --text-label-leading: 1.4286;
    --text-code-size: 14px;
    --text-code-weight: var(--font-weight-normal);
    --text-code-leading: 1.7143;
    --text-supporting-size: 12px;
    --text-supporting-weight: var(--font-weight-normal);
    --text-supporting-leading: 1.6667;
  }

  .xds-button.secondary {
    background-color: light-dark(rgba(5, 54, 89, 0.1), rgba(223, 226, 229, 0.2));
  }

  .xds-heading.level-1 {
    font-family: var(--font-heading);
    font-size: var(--heading-1-size);
    font-weight: var(--heading-1-weight);
    line-height: var(--heading-1-leading);
    color: var(--color-text-primary);
  }
  .xds-heading.level-2 {
    font-family: var(--font-heading);
    font-size: var(--heading-2-size);
    font-weight: var(--heading-2-weight);
    line-height: var(--heading-2-leading);
    color: var(--color-text-primary);
  }
  .xds-heading.level-3 {
    font-family: var(--font-heading);
    font-size: var(--heading-3-size);
    font-weight: var(--heading-3-weight);
    line-height: var(--heading-3-leading);
    color: var(--color-text-primary);
  }
  .xds-heading.level-4 {
    font-family: var(--font-heading);
    font-size: var(--heading-4-size);
    font-weight: var(--heading-4-weight);
    line-height: var(--heading-4-leading);
    color: var(--color-text-primary);
  }
  .xds-heading.level-5 {
    font-family: var(--font-heading);
    font-size: var(--heading-5-size);
    font-weight: var(--heading-5-weight);
    line-height: var(--heading-5-leading);
    color: var(--color-text-primary);
  }
  .xds-heading.level-6 {
    font-family: var(--font-heading);
    font-size: var(--heading-6-size);
    font-weight: var(--heading-6-weight);
    line-height: var(--heading-6-leading);
    color: var(--color-text-primary);
  }

  .xds-text.body {
    font-family: var(--font-heading);
    font-size: var(--text-body-size);
    font-weight: var(--text-body-weight);
    line-height: var(--text-body-leading);
    color: var(--color-text-primary);
  }
  .xds-text.large {
    font-family: var(--font-heading);
    font-size: var(--text-large-size);
    font-weight: var(--text-large-weight);
    line-height: var(--text-large-leading);
    color: var(--color-text-primary);
  }
  .xds-text.label {
    font-family: var(--font-heading);
    font-size: var(--text-label-size);
    font-weight: var(--text-label-weight);
    line-height: var(--text-label-leading);
    color: var(--color-text-primary);
  }
  .xds-text.supporting {
    font-family: var(--font-heading);
    font-size: var(--text-supporting-size);
    font-weight: var(--text-supporting-weight);
    line-height: var(--text-supporting-leading);
    color: var(--color-text-secondary);
  }
  .xds-text.code {
    font-family: var(--font-code);
    font-size: var(--text-code-size);
    font-weight: var(--text-code-weight);
    line-height: var(--text-code-leading);
    color: var(--color-text-primary);
  }
}
}

Observation

Looking at this output, Cindy's feedback in the latest comments is right — the heading and text component overrides are purely mechanical wiring from var(--heading-N-size) → .xds-heading.level-N { font-size }. Since typeScale already generates the tokens, defineTheme should also be able to auto-generate these component override rules. That would let themes drop the manual heading: { ... } and text: { ... } blocks entirely, leaving only truly custom overrides (like the button secondary background).

This is tracked in the comment thread — see replies below on the 4 new comments.

When typeScale is provided to defineTheme, it now auto-generates both:
- Token values (--heading-1-size, etc.) — already existed
- Component override rules (.xds-heading.level-1 { ... }) — NEW

Generated rules include fontFamily, fontSize, fontWeight, lineHeight.
Color is intentionally excluded — it's handled by component internals
(XDSHeading defaults to primary, XDSText has per-type defaults via
defaultColorByType). Including color would duplicate component logic
and risk specificity conflicts with the color prop.

Explicit components deep-merge on top of auto-generated rules, so
themes can still customize individual levels (e.g. letterSpacing on h1,
display font on h1).

Theme cleanup:
- Default theme: removed ~60 lines of manual heading/text overrides.
  Now just typeScale + button secondary override.
- Neutral theme: removed ~90 lines of manual heading/text overrides.
  Bold h3/h4 weights now expressed via typeScale.weights.heading.

Also cleaned up:
- Text.doc.mjs: removed stale editorial/variant references
- Theme editor: uses typeScale auto-generation instead of
  manually passing defaultTheme.components

New tests: 13 (7 for generateTypeScaleComponents, 6 for defineTheme
auto-generation + deep merge behavior).

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

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may tweak this a bit later. The output isn't quite right but it's hard to describe it.

@cixzhang
cixzhang merged commit 9f0e96f into main Mar 17, 2026
11 checks passed
@cixzhang
cixzhang deleted the navi/feat/type-scale-system branch March 17, 2026 20:54
ernestt added a commit that referenced this pull request Mar 17, 2026
…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]>
ernestt added a commit that referenced this pull request Mar 17, 2026
…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]>
ernestt added a commit that referenced this pull request Mar 17, 2026
…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]>
ernestt added a commit that referenced this pull request Mar 19, 2026
…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 pushed a commit that referenced this pull request Mar 20, 2026
…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 pushed a commit that referenced this pull request Mar 20, 2026
…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 pushed a commit that referenced this pull request Mar 20, 2026
…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]>
ernestt added a commit that referenced this pull request Mar 20, 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 Apr 26, 2026
* feat: ratio-based type scale system with typeScale in defineTheme

Implements #586 — adds a configurable type scale system to XDS themes.

Type scale configuration:
- Single { base, ratio } config in defineTheme generates all heading
  and text typography tokens via geometric progression
- Default: base=14, ratio=1.2 with h4 anchored to base (14px)
- Headings h1-h3 scale up, h5-h6 scale down from the anchor
- 33 new semantic tokens (--heading-{n}-{size|weight|leading},
  --text-{type}-{size|weight|leading})

New default heading scale:
  h1: 24px, h2: 20px, h3: 17px, h4: 14px, h5: 12px, h6: 10px

API changes:
- defineTheme accepts optional typeScale: { base, ratio }
- Explicit token overrides take precedence over typeScale values
- expandTypeScale() exported as a pure computation function

Breaking changes (nothing shipped to consumers):
- Removed variant prop from XDSHeading (was 'default' | 'editorial')
- Removed variant prop from XDSFontWrapper (simplified to prose wrapper)
- Removed XDSHeadingVariant and XDSFontWrapperVariant types
- Removed editorial heading scale from default and neutral themes
- Removed editorial variant classes from typography.css

For mixed density regions, nest <XDSTheme> with a different typeScale
instead of using variant props — same mechanism as brand theming.

Theme component overrides (heading, text) now reference type scale
tokens (var(--heading-1-size)) instead of text size tokens
(var(--text-2xl)), so they automatically respond to typeScale changes.

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

* feat: add type scale editor to theme editor storybook

Adds an interactive Type Scale tab to the Theme Editor with:
- Base size slider (10–24px) and ratio slider (1.05–1.5)
- Preset buttons: Dense (12/1.125), Default (14/1.2), Airy (16/1.25)
- Live heading scale preview (h1–h6 with computed sizes)
- Live text type preview (large, body, label, code, supporting)
- Prose preview via XDSFontWrapper
- Formula display showing the geometric progression
- Collapsible raw token values (33 tokens)
- Code generator emits typeScale config when non-default

Also updates Typography categories to reference new type scale tokens
(--heading-{n}-size instead of --text-2xl, etc.)

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

* fix: merge type scale into typography tab, clean up theme editor UX

- Merged Type Scale controls into the Typography tab (no separate tab)
  Base/ratio sliders and presets sit above the typography category selector
- Removed Theme Editor header and Theme Name input
- Removed light/dark mode toggle — now derives from storybook's global
  dark mode via prefers-color-scheme and class observer
- Fixed double scrolling: replaced height:100vh with position:absolute inset:0,
  removed 24px padding wrapper on preview panel

Net -212 lines.

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

* fix: theme editor preview now responds to type scale changes

Two issues prevented the preview from updating when type scale sliders changed:

1. Missing component overrides — the preview theme had tokens but no CSS rules
   to consume them. Now includes defaultTheme.components which has rules like
   .xds-heading.level-1 { font-size: var(--heading-1-size) }.

2. Type scale tokens not emitted at default values — when tokens matched
   allDefaults they were excluded from the theme's :scope {} CSS. But the
   component rules reference var(--heading-1-size) which only exists when
   the theme explicitly sets it. Type scale tokens are now always included.

Also fixes outer padding conflict with storybook decorator (margin: -16).

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

* fix: address review feedback — ratios, var refs, weights, themes

Addresses all review comments from #638:

1. Line-heights are now unitless ratios (e.g. '1.3333') instead of px
   values. snapLineHeight → computeLeading returns ratio snapped so
   computed px aligns to 4px grid. StyleX can convert font sizes to
   em/rem without breaking the proportional relationship.

2. typeScaleDefaults base values reference existing --text-* vars where
   possible (e.g. var(--text-3xl) instead of 24px) so they compose
   through the token system. expandTypeScale() outputs computed px
   values that override these when a theme configures typeScale.

3. Font weights are now configurable via optional weights.heading and
   weights.text in XDSTypeScaleConfig. Themes can override individual
   heading levels or text types. Unset values use defaults.

4. Default and neutral themes now use typeScale: { base: 14, ratio: 1.2 }
   to demonstrate the API and eat our own cooking.

5. Reverted stray yarn.lock change (tailwindcss dedup artifact).

Test count: 1492 (5 new weight override tests).

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

* fix: resolve strict TS errors in weight override spread types

The CI build uses strict noImplicitAny. Spreading Partial<Record<1|2|3|4|5|6, string>>
onto Record<number, string> produced index signature incompatibility because
the partial type includes undefined in its value type.

Fix: cast the optional spread operand to Record<number, string> | undefined
so the spread result has a clean Record<number, string> type.

Also reverts yarn.lock to match origin/main (stray dedup was re-introduced).

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

* fix: theme editor UX — scrolling, mode toggle, presets, ratio selector

1. Fixed page-level scrolling: added overflow:hidden to outer container
   so the storybook decorator padding doesn't cause double scrollbars.

2. Added light/dark mode toggle to the Live Preview header bar.
   Removed 'See your changes in real-time' subtext.

3. Renamed presets: Dense→Functional, Airy→Editorial. Added
   'Recommended values' label above the preset buttons.

4. Replaced raw HTML spans/labels with XDSText/XDSHeading throughout
   the type scale editor for dogfooding.

5. Replaced ratio slider with a named-ratio selector dropdown:
   Minor Second (1.067), Major Second (1.125), Minor Third (1.2),
   Major Third (1.25), Perfect Fourth (1.333), Augmented Fourth (1.414),
   Perfect Fifth (1.5), Golden Ratio (1.618), plus a Custom option
   that reveals the slider for freeform values.

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

* fix: use XDS components throughout theme editor, fix left panel padding

Replaced all native HTML form controls with XDS components:
- Base Size <input type=range> → XDSSlider
- Scale Ratio <select> → XDSSelector (with section groups)
- Custom Ratio slider → XDSSlider
- Color category <select> → XDSSelector
- Typography category <select> → XDSSelector (with section groups)
- Category description <div> → XDSText

Fixed left panel padding: added top padding (16px) to token group
tabs area so content doesn't touch the top edge.

Net -61 lines — XDS components are more concise than raw HTML.

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

* fix: eliminate page scrolling with position:fixed + default theme

Previous approach (position:absolute + margin:-16) tried to escape the
storybook decorator's padding:16 wrapper but left the decorator div with
a scrollable content height, causing body-level scroll.

position:fixed is always relative to the viewport — it truly escapes all
ancestor containers regardless of padding or overflow. margin:-16 is no
longer needed.

Also switched xdsTheme from 'none' to 'default' so the editor chrome
(left panel) receives proper XDS theming. The preview panel uses its
own nested <XDSTheme theme={currentTheme}>, which is unaffected.

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

* feat: auto-generate heading/text component overrides from typeScale

When typeScale is provided to defineTheme, it now auto-generates both:
- Token values (--heading-1-size, etc.) — already existed
- Component override rules (.xds-heading.level-1 { ... }) — NEW

Generated rules include fontFamily, fontSize, fontWeight, lineHeight.
Color is intentionally excluded — it's handled by component internals
(XDSHeading defaults to primary, XDSText has per-type defaults via
defaultColorByType). Including color would duplicate component logic
and risk specificity conflicts with the color prop.

Explicit components deep-merge on top of auto-generated rules, so
themes can still customize individual levels (e.g. letterSpacing on h1,
display font on h1).

Theme cleanup:
- Default theme: removed ~60 lines of manual heading/text overrides.
  Now just typeScale + button secondary override.
- Neutral theme: removed ~90 lines of manual heading/text overrides.
  Bold h3/h4 weights now expressed via typeScale.weights.heading.

Also cleaned up:
- Text.doc.mjs: removed stale editorial/variant references
- Theme editor: uses typeScale auto-generation instead of
  manually passing defaultTheme.components

New tests: 13 (7 for generateTypeScaleComponents, 6 for defineTheme
auto-generation + deep merge behavior).

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

---------

Co-authored-by: navi <[email protected]>
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
* feat: ratio-based type scale system with typeScale in defineTheme

Implements #586 — adds a configurable type scale system to XDS themes.

Type scale configuration:
- Single { base, ratio } config in defineTheme generates all heading
  and text typography tokens via geometric progression
- Default: base=14, ratio=1.2 with h4 anchored to base (14px)
- Headings h1-h3 scale up, h5-h6 scale down from the anchor
- 33 new semantic tokens (--heading-{n}-{size|weight|leading},
  --text-{type}-{size|weight|leading})

New default heading scale:
  h1: 24px, h2: 20px, h3: 17px, h4: 14px, h5: 12px, h6: 10px

API changes:
- defineTheme accepts optional typeScale: { base, ratio }
- Explicit token overrides take precedence over typeScale values
- expandTypeScale() exported as a pure computation function

Breaking changes (nothing shipped to consumers):
- Removed variant prop from XDSHeading (was 'default' | 'editorial')
- Removed variant prop from XDSFontWrapper (simplified to prose wrapper)
- Removed XDSHeadingVariant and XDSFontWrapperVariant types
- Removed editorial heading scale from default and neutral themes
- Removed editorial variant classes from typography.css

For mixed density regions, nest <XDSTheme> with a different typeScale
instead of using variant props — same mechanism as brand theming.

Theme component overrides (heading, text) now reference type scale
tokens (var(--heading-1-size)) instead of text size tokens
(var(--text-2xl)), so they automatically respond to typeScale changes.

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

* feat: add type scale editor to theme editor storybook

Adds an interactive Type Scale tab to the Theme Editor with:
- Base size slider (10–24px) and ratio slider (1.05–1.5)
- Preset buttons: Dense (12/1.125), Default (14/1.2), Airy (16/1.25)
- Live heading scale preview (h1–h6 with computed sizes)
- Live text type preview (large, body, label, code, supporting)
- Prose preview via XDSFontWrapper
- Formula display showing the geometric progression
- Collapsible raw token values (33 tokens)
- Code generator emits typeScale config when non-default

Also updates Typography categories to reference new type scale tokens
(--heading-{n}-size instead of --text-2xl, etc.)

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

* fix: merge type scale into typography tab, clean up theme editor UX

- Merged Type Scale controls into the Typography tab (no separate tab)
  Base/ratio sliders and presets sit above the typography category selector
- Removed Theme Editor header and Theme Name input
- Removed light/dark mode toggle — now derives from storybook's global
  dark mode via prefers-color-scheme and class observer
- Fixed double scrolling: replaced height:100vh with position:absolute inset:0,
  removed 24px padding wrapper on preview panel

Net -212 lines.

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

* fix: theme editor preview now responds to type scale changes

Two issues prevented the preview from updating when type scale sliders changed:

1. Missing component overrides — the preview theme had tokens but no CSS rules
   to consume them. Now includes defaultTheme.components which has rules like
   .xds-heading.level-1 { font-size: var(--heading-1-size) }.

2. Type scale tokens not emitted at default values — when tokens matched
   allDefaults they were excluded from the theme's :scope {} CSS. But the
   component rules reference var(--heading-1-size) which only exists when
   the theme explicitly sets it. Type scale tokens are now always included.

Also fixes outer padding conflict with storybook decorator (margin: -16).

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

* fix: address review feedback — ratios, var refs, weights, themes

Addresses all review comments from #638:

1. Line-heights are now unitless ratios (e.g. '1.3333') instead of px
   values. snapLineHeight → computeLeading returns ratio snapped so
   computed px aligns to 4px grid. StyleX can convert font sizes to
   em/rem without breaking the proportional relationship.

2. typeScaleDefaults base values reference existing --text-* vars where
   possible (e.g. var(--text-3xl) instead of 24px) so they compose
   through the token system. expandTypeScale() outputs computed px
   values that override these when a theme configures typeScale.

3. Font weights are now configurable via optional weights.heading and
   weights.text in XDSTypeScaleConfig. Themes can override individual
   heading levels or text types. Unset values use defaults.

4. Default and neutral themes now use typeScale: { base: 14, ratio: 1.2 }
   to demonstrate the API and eat our own cooking.

5. Reverted stray yarn.lock change (tailwindcss dedup artifact).

Test count: 1492 (5 new weight override tests).

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

* fix: resolve strict TS errors in weight override spread types

The CI build uses strict noImplicitAny. Spreading Partial<Record<1|2|3|4|5|6, string>>
onto Record<number, string> produced index signature incompatibility because
the partial type includes undefined in its value type.

Fix: cast the optional spread operand to Record<number, string> | undefined
so the spread result has a clean Record<number, string> type.

Also reverts yarn.lock to match origin/main (stray dedup was re-introduced).

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

* fix: theme editor UX — scrolling, mode toggle, presets, ratio selector

1. Fixed page-level scrolling: added overflow:hidden to outer container
   so the storybook decorator padding doesn't cause double scrollbars.

2. Added light/dark mode toggle to the Live Preview header bar.
   Removed 'See your changes in real-time' subtext.

3. Renamed presets: Dense→Functional, Airy→Editorial. Added
   'Recommended values' label above the preset buttons.

4. Replaced raw HTML spans/labels with XDSText/XDSHeading throughout
   the type scale editor for dogfooding.

5. Replaced ratio slider with a named-ratio selector dropdown:
   Minor Second (1.067), Major Second (1.125), Minor Third (1.2),
   Major Third (1.25), Perfect Fourth (1.333), Augmented Fourth (1.414),
   Perfect Fifth (1.5), Golden Ratio (1.618), plus a Custom option
   that reveals the slider for freeform values.

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

* fix: use XDS components throughout theme editor, fix left panel padding

Replaced all native HTML form controls with XDS components:
- Base Size <input type=range> → XDSSlider
- Scale Ratio <select> → XDSSelector (with section groups)
- Custom Ratio slider → XDSSlider
- Color category <select> → XDSSelector
- Typography category <select> → XDSSelector (with section groups)
- Category description <div> → XDSText

Fixed left panel padding: added top padding (16px) to token group
tabs area so content doesn't touch the top edge.

Net -61 lines — XDS components are more concise than raw HTML.

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

* fix: eliminate page scrolling with position:fixed + default theme

Previous approach (position:absolute + margin:-16) tried to escape the
storybook decorator's padding:16 wrapper but left the decorator div with
a scrollable content height, causing body-level scroll.

position:fixed is always relative to the viewport — it truly escapes all
ancestor containers regardless of padding or overflow. margin:-16 is no
longer needed.

Also switched xdsTheme from 'none' to 'default' so the editor chrome
(left panel) receives proper XDS theming. The preview panel uses its
own nested <XDSTheme theme={currentTheme}>, which is unaffected.

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

* feat: auto-generate heading/text component overrides from typeScale

When typeScale is provided to defineTheme, it now auto-generates both:
- Token values (--heading-1-size, etc.) — already existed
- Component override rules (.xds-heading.level-1 { ... }) — NEW

Generated rules include fontFamily, fontSize, fontWeight, lineHeight.
Color is intentionally excluded — it's handled by component internals
(XDSHeading defaults to primary, XDSText has per-type defaults via
defaultColorByType). Including color would duplicate component logic
and risk specificity conflicts with the color prop.

Explicit components deep-merge on top of auto-generated rules, so
themes can still customize individual levels (e.g. letterSpacing on h1,
display font on h1).

Theme cleanup:
- Default theme: removed ~60 lines of manual heading/text overrides.
  Now just typeScale + button secondary override.
- Neutral theme: removed ~90 lines of manual heading/text overrides.
  Bold h3/h4 weights now expressed via typeScale.weights.heading.

Also cleaned up:
- Text.doc.mjs: removed stale editorial/variant references
- Theme editor: uses typeScale auto-generation instead of
  manually passing defaultTheme.components

New tests: 13 (7 for generateTypeScaleComponents, 6 for defineTheme
auto-generation + deep merge behavior).

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

---------

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
* feat: ratio-based type scale system with typeScale in defineTheme

Implements #586 — adds a configurable type scale system to XDS themes.

Type scale configuration:
- Single { base, ratio } config in defineTheme generates all heading
  and text typography tokens via geometric progression
- Default: base=14, ratio=1.2 with h4 anchored to base (14px)
- Headings h1-h3 scale up, h5-h6 scale down from the anchor
- 33 new semantic tokens (--heading-{n}-{size|weight|leading},
  --text-{type}-{size|weight|leading})

New default heading scale:
  h1: 24px, h2: 20px, h3: 17px, h4: 14px, h5: 12px, h6: 10px

API changes:
- defineTheme accepts optional typeScale: { base, ratio }
- Explicit token overrides take precedence over typeScale values
- expandTypeScale() exported as a pure computation function

Breaking changes (nothing shipped to consumers):
- Removed variant prop from XDSHeading (was 'default' | 'editorial')
- Removed variant prop from XDSFontWrapper (simplified to prose wrapper)
- Removed XDSHeadingVariant and XDSFontWrapperVariant types
- Removed editorial heading scale from default and neutral themes
- Removed editorial variant classes from typography.css

For mixed density regions, nest <XDSTheme> with a different typeScale
instead of using variant props — same mechanism as brand theming.

Theme component overrides (heading, text) now reference type scale
tokens (var(--heading-1-size)) instead of text size tokens
(var(--text-2xl)), so they automatically respond to typeScale changes.


* feat: add type scale editor to theme editor storybook

Adds an interactive Type Scale tab to the Theme Editor with:
- Base size slider (10–24px) and ratio slider (1.05–1.5)
- Preset buttons: Dense (12/1.125), Default (14/1.2), Airy (16/1.25)
- Live heading scale preview (h1–h6 with computed sizes)
- Live text type preview (large, body, label, code, supporting)
- Prose preview via XDSFontWrapper
- Formula display showing the geometric progression
- Collapsible raw token values (33 tokens)
- Code generator emits typeScale config when non-default

Also updates Typography categories to reference new type scale tokens
(--heading-{n}-size instead of --text-2xl, etc.)


* fix: merge type scale into typography tab, clean up theme editor UX

- Merged Type Scale controls into the Typography tab (no separate tab)
  Base/ratio sliders and presets sit above the typography category selector
- Removed Theme Editor header and Theme Name input
- Removed light/dark mode toggle — now derives from storybook's global
  dark mode via prefers-color-scheme and class observer
- Fixed double scrolling: replaced height:100vh with position:absolute inset:0,
  removed 24px padding wrapper on preview panel

Net -212 lines.


* fix: theme editor preview now responds to type scale changes

Two issues prevented the preview from updating when type scale sliders changed:

1. Missing component overrides — the preview theme had tokens but no CSS rules
   to consume them. Now includes defaultTheme.components which has rules like
   .xds-heading.level-1 { font-size: var(--heading-1-size) }.

2. Type scale tokens not emitted at default values — when tokens matched
   allDefaults they were excluded from the theme's :scope {} CSS. But the
   component rules reference var(--heading-1-size) which only exists when
   the theme explicitly sets it. Type scale tokens are now always included.

Also fixes outer padding conflict with storybook decorator (margin: -16).


* fix: address review feedback — ratios, var refs, weights, themes

Addresses all review comments from #638:

1. Line-heights are now unitless ratios (e.g. '1.3333') instead of px
   values. snapLineHeight → computeLeading returns ratio snapped so
   computed px aligns to 4px grid. StyleX can convert font sizes to
   em/rem without breaking the proportional relationship.

2. typeScaleDefaults base values reference existing --text-* vars where
   possible (e.g. var(--text-3xl) instead of 24px) so they compose
   through the token system. expandTypeScale() outputs computed px
   values that override these when a theme configures typeScale.

3. Font weights are now configurable via optional weights.heading and
   weights.text in XDSTypeScaleConfig. Themes can override individual
   heading levels or text types. Unset values use defaults.

4. Default and neutral themes now use typeScale: { base: 14, ratio: 1.2 }
   to demonstrate the API and eat our own cooking.

5. Reverted stray yarn.lock change (tailwindcss dedup artifact).

Test count: 1492 (5 new weight override tests).


* fix: resolve strict TS errors in weight override spread types

The CI build uses strict noImplicitAny. Spreading Partial<Record<1|2|3|4|5|6, string>>
onto Record<number, string> produced index signature incompatibility because
the partial type includes undefined in its value type.

Fix: cast the optional spread operand to Record<number, string> | undefined
so the spread result has a clean Record<number, string> type.

Also reverts yarn.lock to match origin/main (stray dedup was re-introduced).


* fix: theme editor UX — scrolling, mode toggle, presets, ratio selector

1. Fixed page-level scrolling: added overflow:hidden to outer container
   so the storybook decorator padding doesn't cause double scrollbars.

2. Added light/dark mode toggle to the Live Preview header bar.
   Removed 'See your changes in real-time' subtext.

3. Renamed presets: Dense→Functional, Airy→Editorial. Added
   'Recommended values' label above the preset buttons.

4. Replaced raw HTML spans/labels with XDSText/XDSHeading throughout
   the type scale editor for dogfooding.

5. Replaced ratio slider with a named-ratio selector dropdown:
   Minor Second (1.067), Major Second (1.125), Minor Third (1.2),
   Major Third (1.25), Perfect Fourth (1.333), Augmented Fourth (1.414),
   Perfect Fifth (1.5), Golden Ratio (1.618), plus a Custom option
   that reveals the slider for freeform values.


* fix: use XDS components throughout theme editor, fix left panel padding

Replaced all native HTML form controls with XDS components:
- Base Size <input type=range> → XDSSlider
- Scale Ratio <select> → XDSSelector (with section groups)
- Custom Ratio slider → XDSSlider
- Color category <select> → XDSSelector
- Typography category <select> → XDSSelector (with section groups)
- Category description <div> → XDSText

Fixed left panel padding: added top padding (16px) to token group
tabs area so content doesn't touch the top edge.

Net -61 lines — XDS components are more concise than raw HTML.


* fix: eliminate page scrolling with position:fixed + default theme

Previous approach (position:absolute + margin:-16) tried to escape the
storybook decorator's padding:16 wrapper but left the decorator div with
a scrollable content height, causing body-level scroll.

position:fixed is always relative to the viewport — it truly escapes all
ancestor containers regardless of padding or overflow. margin:-16 is no
longer needed.

Also switched xdsTheme from 'none' to 'default' so the editor chrome
(left panel) receives proper XDS theming. The preview panel uses its
own nested <XDSTheme theme={currentTheme}>, which is unaffected.


* feat: auto-generate heading/text component overrides from typeScale

When typeScale is provided to defineTheme, it now auto-generates both:
- Token values (--heading-1-size, etc.) — already existed
- Component override rules (.xds-heading.level-1 { ... }) — NEW

Generated rules include fontFamily, fontSize, fontWeight, lineHeight.
Color is intentionally excluded — it's handled by component internals
(XDSHeading defaults to primary, XDSText has per-type defaults via
defaultColorByType). Including color would duplicate component logic
and risk specificity conflicts with the color prop.

Explicit components deep-merge on top of auto-generated rules, so
themes can still customize individual levels (e.g. letterSpacing on h1,
display font on h1).

Theme cleanup:
- Default theme: removed ~60 lines of manual heading/text overrides.
  Now just typeScale + button secondary override.
- Neutral theme: removed ~90 lines of manual heading/text overrides.
  Bold h3/h4 weights now expressed via typeScale.weights.heading.

Also cleaned up:
- Text.doc.mjs: removed stale editorial/variant references
- Theme editor: uses typeScale auto-generation instead of
  manually passing defaultTheme.components

New tests: 13 (7 for generateTypeScaleComponents, 6 for defineTheme
auto-generation + deep merge behavior).


---------
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.

feat: Functional text type + typeScale theme shortcut

2 participants