An open source design system that's fully customizable and agent ready
TypeScript
fix(themes): Butter, Stone and Y2K set supporting text in rem (#10320)
Cindy Zhang732c338746b5
diff --git a/.changeset/themes-supporting-size-rem.md b/.changeset/themes-supporting-size-rem.mdnew file mode 100644index 0000000000..27a1cb4589--- /dev/null+++ b/.changeset/themes-supporting-size-rem.md@@ -0,0 +1,10 @@+---+'@astryxdesign/theme-butter': patch+'@astryxdesign/theme-stone': patch+'@astryxdesign/theme-y2k': patch+'@astryxdesign/cli': patch+---++[fix] The Butter, Stone and Y2K themes set supporting text (`--text-supporting-size`) in rem instead of a fixed 12px, so it grows when a reader raises the browser's default font size, like the rest of the text. At the default size it is still 12px. The CLI's copies of these themes match.++@cixzhangdiff --git a/docs/specs/AST-102-typography-theme-owned/spec.md b/docs/specs/AST-102-typography-theme-owned/spec.mdindex c0b53966b9..d9228cf202 100644--- a/docs/specs/AST-102-typography-theme-owned/spec.md+++ b/docs/specs/AST-102-typography-theme-owned/spec.md@@ -106,14 +106,12 @@ the person's device.Sankey labels using `system-ui` directly and several Core and Lab componentssetting their own sizes or line heights; under FR1 those are conformancegaps.-- `architecture:theme-tokens`: text size tokens stay rem; Butter, Stone, and- Y2K's 12 px supporting-size token is the token-level gap below. Spacing and+- `architecture:theme-tokens`: text size tokens stay rem, in every+ first-party theme. Spacing andelement size tokens keep their values when a size is set; a control growswith its text under FR4.- Defects under FR3 and FR4:- On iOS and iPadOS, text ignores Dynamic Type in every theme.- - Butter, Stone, and Y2K fix supporting text at 12 px, so it does not follow- a larger browser or Android text size.- Controls hold fixed heights, such as 40 px elements, `component:Badge`FR1's block size, `component:Button` FR4's and `component:Token` FR1'selement sizes, and InputGroup's row height in `family:input-fields`, so a@@ -124,12 +122,12 @@ the person's device.## Verification-| Contract | Verification | Representative states | Mutation or failure expectation |-| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| FR1 | Source check over Core and Lab component styles plus token review | family, size, and line height of rendered text in component styles; an inherited value; a `1em` icon size; coarse and fine pointer; a platform font keyword; the iOS text-entry floor | A Core or Lab web component sets the family, size, or line height of text it renders outside typography tokens and not by inheritance, or applies a platform font keyword directly; icon sizing, the family floor, and a hidden internal element that only measures a platform text style are not failures |-| FR2 | Theme token review plus Safari on iOS, top-level document | an unbranded shipped theme using the system body font family; a branded theme; the default theme | A branded theme's body font replaced by the system font, or a system body font applied by a component instead of a theme token |-| FR3 | Safari on iOS across Dynamic Type categories; Chrome on Android in the emulator with font scale; a desktop browser with a larger default font size and with zoom; theme review | a branded and an unbranded theme; no size set; default category; a size set on each platform; macOS Safari | Text that ignores a size the person set; text that differs from the theme's family or size when none is set, other than the `family:input-fields` FR9 iOS text-entry floor; a theme family replaced; a public option, prop, or document attribute; a changed root font size |-| FR4 | Desktop browser at 200%, 250%, and 300% text size, plus Safari on iOS at accessibility categories | reading text; a button, text input, tab, badge, table cell, and segmented control | Lost content or function at 200% or less; a label clipped by its control's height at any size; a control that keeps a fixed height while its text grows |+| Contract | Verification | Representative states | Mutation or failure expectation |+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| FR1 | Source check over Core and Lab component styles plus token review | family, size, and line height of rendered text in component styles; an inherited value; a `1em` icon size; coarse and fine pointer; a platform font keyword; the iOS text-entry floor | A Core or Lab web component sets the family, size, or line height of text it renders outside typography tokens and not by inheritance, or applies a platform font keyword directly; icon sizing, the family floor, and a hidden internal element that only measures a platform text style are not failures |+| FR2 | Theme token review plus Safari on iOS, top-level document | an unbranded shipped theme using the system body font family; a branded theme; the default theme | A branded theme's body font replaced by the system font, or a system body font applied by a component instead of a theme token |+| FR3 | Safari on iOS across Dynamic Type categories; Chrome on Android in the emulator with font scale; a desktop browser with a larger default font size and with zoom; theme review; `scripts/check-theme-text-size-units.test.mjs` (no first-party theme sets a text or font size in px) | a branded and an unbranded theme; no size set; default category; a size set on each platform; macOS Safari | Text that ignores a size the person set; text that differs from the theme's family or size when none is set, other than the `family:input-fields` FR9 iOS text-entry floor; a theme family replaced; a public option, prop, or document attribute; a changed root font size |+| FR4 | Desktop browser at 200%, 250%, and 300% text size, plus Safari on iOS at accessibility categories | reading text; a button, text input, tab, badge, table cell, and segmented control | Lost content or function at 200% or less; a label clipped by its control's height at any size; a control that keeps a fixed height while its text grows |## Decision logdiff --git a/packages/cli/assets/templates/themes/butter/butterTheme.ts b/packages/cli/assets/templates/themes/butter/butterTheme.tsindex 7a0a5fd6d8..d591917473 100644--- a/packages/cli/assets/templates/themes/butter/butterTheme.ts+++ b/packages/cli/assets/templates/themes/butter/butterTheme.ts@@ -260,7 +260,7 @@ export const butterTheme = defineTheme({'--color-tint-hover': [neutral.light[0], neutral.dark[100]],// Typography override- '--text-supporting-size': '12px',+ '--text-supporting-size': '0.75rem', // 12px at the default root size// Element sizes — slightly taller defaults so the new input padding// (--spacing-2 block) has room to breathe.diff --git a/packages/cli/assets/templates/themes/stone/stoneTheme.ts b/packages/cli/assets/templates/themes/stone/stoneTheme.tsindex bde6befe59..bd446c7834 100644--- a/packages/cli/assets/templates/themes/stone/stoneTheme.ts+++ b/packages/cli/assets/templates/themes/stone/stoneTheme.ts@@ -240,7 +240,7 @@ export const stoneTheme = defineTheme({'--color-tint-hover': [neutral.light[0], neutral.dark[100]],// Typography override- '--text-supporting-size': '12px',+ '--text-supporting-size': '0.75rem', // 12px at the default root size// Categorical// Light mode pairs pastel stop 90 surfaces with stop 30 foregrounds.diff --git a/packages/cli/assets/templates/themes/y2k/y2kTheme.ts b/packages/cli/assets/templates/themes/y2k/y2kTheme.tsindex 01c3b61899..2c1fa8da9c 100644--- a/packages/cli/assets/templates/themes/y2k/y2kTheme.ts+++ b/packages/cli/assets/templates/themes/y2k/y2kTheme.ts@@ -236,7 +236,7 @@ export const y2kTheme = defineTheme({'--color-tint-hover': [neutral.light[15], neutral.dark[95]],// Typography override- '--text-supporting-size': '12px',+ '--text-supporting-size': '0.75rem', // 12px at the default root size// Categorical colors'--color-background-green': [green.light[80], green.dark[80]],diff --git a/packages/themes/butter/src/butterTheme.ts b/packages/themes/butter/src/butterTheme.tsindex 7a0a5fd6d8..d591917473 100644--- a/packages/themes/butter/src/butterTheme.ts+++ b/packages/themes/butter/src/butterTheme.ts@@ -260,7 +260,7 @@ export const butterTheme = defineTheme({'--color-tint-hover': [neutral.light[0], neutral.dark[100]],// Typography override- '--text-supporting-size': '12px',+ '--text-supporting-size': '0.75rem', // 12px at the default root size// Element sizes — slightly taller defaults so the new input padding// (--spacing-2 block) has room to breathe.diff --git a/packages/themes/stone/src/stoneTheme.ts b/packages/themes/stone/src/stoneTheme.tsindex bde6befe59..bd446c7834 100644--- a/packages/themes/stone/src/stoneTheme.ts+++ b/packages/themes/stone/src/stoneTheme.ts@@ -240,7 +240,7 @@ export const stoneTheme = defineTheme({'--color-tint-hover': [neutral.light[0], neutral.dark[100]],// Typography override- '--text-supporting-size': '12px',+ '--text-supporting-size': '0.75rem', // 12px at the default root size// Categorical// Light mode pairs pastel stop 90 surfaces with stop 30 foregrounds.diff --git a/packages/themes/y2k/src/y2kTheme.ts b/packages/themes/y2k/src/y2kTheme.tsindex 01c3b61899..2c1fa8da9c 100644--- a/packages/themes/y2k/src/y2kTheme.ts+++ b/packages/themes/y2k/src/y2kTheme.ts@@ -236,7 +236,7 @@ export const y2kTheme = defineTheme({'--color-tint-hover': [neutral.light[15], neutral.dark[95]],// Typography override- '--text-supporting-size': '12px',+ '--text-supporting-size': '0.75rem', // 12px at the default root size// Categorical colors'--color-background-green': [green.light[80], green.dark[80]],diff --git a/scripts/check-theme-text-size-units.test.mjs b/scripts/check-theme-text-size-units.test.mjsnew file mode 100644index 0000000000..04ecbcfe88--- /dev/null+++ b/scripts/check-theme-text-size-units.test.mjs@@ -0,0 +1,56 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Text size unit guard for the first-party themes.+ *+ * A text size the person set wins (spec:AST-102 FR3). A larger default font+ * size in the browser reaches theme text only through rem: a theme that pins+ * a text or font size in px keeps that text at its size whatever the person+ * set.+ *+ * @input Every first-party theme package, as `listThemeSlugs()` finds them.+ * @output Fails when a theme sets a `--text-*-size` or `--font-size-*` token+ * in px.+ * @position Repo-level guard, sibling of the other scripts/check-*.+ */++import {describe, it, expect} from 'vitest';+import {listThemeSlugs} from './generate-cli-themes.mjs';++const SIZE_TOKEN = /^--(?:text-[a-z0-9-]+-size|font-size-[a-z0-9-]+)$/;++/** The export name of a theme package's theme object (`stone` → `stoneTheme`). */+function themeExportName(slug) {+ return `${slug.replace(/-([a-z])/g, (_, c) => c.toUpperCase())}Theme`;+}++/** Every size token a theme sets, wherever the theme object keeps it. */+function sizeTokensOf(value, out = []) {+ if (value == null || typeof value !== 'object') return out;+ for (const [key, entry] of Object.entries(value)) {+ if (SIZE_TOKEN.test(key)) out.push([key, entry]);+ else if (typeof entry === 'object') sizeTokensOf(entry, out);+ }+ return out;+}++const slugs = listThemeSlugs();++describe('first-party theme text sizes follow the size the person set', () => {+ it('finds the first-party themes', () => {+ expect(slugs.length).toBeGreaterThan(0);+ });++ for (const slug of slugs) {+ it(`${slug} sets no text or font size in px`, async () => {+ const name = themeExportName(slug);+ const module = await import(`../packages/themes/${slug}/src/${name}.ts`);+ const pinned = sizeTokensOf(module[name]).filter(([, entry]) =>+ (Array.isArray(entry) ? entry : [entry]).some(+ v => typeof v === 'string' && /\d(?:\.\d+)?px\b/.test(v),+ ),+ );+ expect(pinned).toEqual([]);+ });+ }+});