Repository navigation
feat: ratio-based type scale system with typeScale in defineTheme - #638
Conversation
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]>
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsText · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. XDSText - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
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]>
| '--text-label-leading': '20px', | ||
| '--text-code-size': '14px', // base | ||
| '--text-code-weight': 'var(--font-weight-normal)', | ||
| '--text-code-leading': '24px', |
There was a problem hiding this comment.
Line-height should be ratio-based instead of pixel based. StyleX will convert px sizes to ems.
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
Always compute ratios here.
There was a problem hiding this comment.
Fixed — expandTypeScale() now returns unitless ratios via computeLeading() (e.g. '1.3333' not '32px').
| // No token overrides needed — defineTheme fills in defaults automatically. | ||
| // See packages/core/src/theme/tokens.stylex.ts for all token values. | ||
| tokens: {}, | ||
|
|
There was a problem hiding this comment.
Shouldn't this be implementing the new typeScale API?
There was a problem hiding this comment.
Yes — defaultTheme now uses typeScale: {base: 14, ratio: 1.2} which feeds into defineTheme() → expandTypeScale() to generate all the heading/text tokens.
cixzhang
left a comment
There was a problem hiding this comment.
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.
| 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)', | ||
| }; |
There was a problem hiding this comment.
Hard coded for now? Did we want this to be configured as well?
There was a problem hiding this comment.
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.
| 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)', | ||
| }; |
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
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³ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| "@tailwindcss/oxide-win32-x64-msvc" "4.2.1" | ||
|
|
||
| "@tailwindcss/postcss@^4.2.1": | ||
| "@tailwindcss/postcss@^4", "@tailwindcss/postcss@^4.2.1": |
There was a problem hiding this comment.
Hmm, do you remember what this was about?
There was a problem hiding this comment.
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]>
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]>
…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]>
|
@cixzhang addressed comments. Could I get a second look on this? |
| { | ||
| label: 'Editorial heading', | ||
| code: '<XDSHeading level={1} variant="editorial">Article Title</XDSHeading>', | ||
| code: '<XDSHeading level={1}>Page Title</XDSHeading>', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
I think we should be able to clean all this up because it's getting generated by typeScale right?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Same here. Seems like typescale should cover these? Do we think we still need manual overrides?
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
Also this could probably be cleaned up.
There was a problem hiding this comment.
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]>
Generated CSS Build OutputHere's the full CSS output that @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);
}
}
}ObservationLooking at this output, Cindy's feedback in the latest comments is right — the heading and text component overrides are purely mechanical wiring from 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
left a comment
There was a problem hiding this comment.
I may tweak this a bit later. The output isn't quite right but it's hard to describe it.
…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]>
…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]>
…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]>
…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]>
…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]>
…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]>
…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]>
…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]>
* 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]>
…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]>
* 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]>
…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]>
* 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). ---------
…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. ---------
Summary
Implements #586 — adds a configurable type scale system to XDS themes.
Type scale system
A single
{ base, ratio }config indefineThemegenerates all heading and text typography tokens via geometric progression (size = base × ratio^step).New default heading scale (base=14, ratio=1.2, h4=anchor)
Generated CSS output (default theme)
This is what
generateThemeCSSproduces for the default theme withtypeScale: { base: 14, ratio: 1.2 }:What changed
New files:
expandTypeScale.ts— pure function:{ base, ratio, weights? } → 33 token overridesexpandTypeScale.test.ts— tests for default, dense, airy scales + weight overridesCore changes:
tokens.stylex.ts— base values reference existing--text-*vars where possible, use unitless ratios for line-heightsdefineThemeaccepts optionaltypeScaleconfig; explicit tokens take precedenceXDSTypeScaleConfigsupports optionalweights.headingandweights.textoverridesXDSHeading: removedvariantprop (was'default' | 'editorial')XDSFontWrapper: removedvariantprop (simplified to prose wrapper)typography.css: removed editorial variant classes, uses type scale tokenstypeScale: { base: 14, ratio: 1.2 }and reference type scale tokensBreaking changes (nothing shipped to consumers):
XDSHeadingVariantandXDSFontWrapperVarianttypesvariantprop fromXDSHeadingandXDSFontWrapperDesign decisions
--text-*vars where sizes align (24px →var(--text-3xl)) so the base system composes through the existing token layerexpandTypeScale()outputs computed px values for theme overrides, which take precedence over the var-referenced defaultsweights.heading/weights.textin the type scale configTest results
All 1492 tests pass (92/92 test files).
Closes #586