An open source design system that's fully customizable and agent ready
TypeScript
feat(themes)!: matcha and y2k spacing steps are rem (#7374)
Cindy Zhang6ecd41722788
diff --git a/.changeset/first-party-theme-spacing-rem.md b/.changeset/first-party-theme-spacing-rem.mdnew file mode 100644index 0000000000..88dd4921b3--- /dev/null+++ b/.changeset/first-party-theme-spacing-rem.md@@ -0,0 +1,10 @@+---+'@astryxdesign/theme-matcha': minor+'@astryxdesign/theme-y2k': minor+'@astryxdesign/cli': minor+---++[breaking] matcha's and y2k's spacing steps are rem (`--spacing-2: 0.75rem`), so their gaps and padding follow the reader's root font size like the core scale. Every step is the same pixel value at the default 16px root; a reader with a larger root font size now sees proportionally larger spacing on these themes. The CLI's copies of both theme templates and the annotated theme template's spacing example change the same way.++Migration: nothing to change to take the new behaviour. To keep fixed pixel spacing on one of these themes, extend it and override the steps in px, which is honoured as written: `defineTheme({name: 'app', extends: matchaTheme, tokens: {'--spacing-2': '12px'}})`.+@cixzhangdiff --git a/packages/cli/assets/templates/themes/matcha/matchaTheme.ts b/packages/cli/assets/templates/themes/matcha/matchaTheme.tsindex aa5c93d981..baf86314f4 100644--- a/packages/cli/assets/templates/themes/matcha/matchaTheme.ts+++ b/packages/cli/assets/templates/themes/matcha/matchaTheme.ts@@ -180,20 +180,20 @@ export const matchaTheme = defineTheme({// =========================================================================// Spacing// =========================================================================- '--spacing-0-5': '3px',- '--spacing-1': '6px',- '--spacing-1-5': '9px',- '--spacing-2': '12px',- '--spacing-3': '18px',- '--spacing-4': '24px',- '--spacing-5': '30px',- '--spacing-6': '36px',- '--spacing-7': '42px',- '--spacing-8': '48px',- '--spacing-9': '54px',- '--spacing-10': '60px',- '--spacing-11': '66px',- '--spacing-12': '72px',+ '--spacing-0-5': '0.1875rem',+ '--spacing-1': '0.375rem',+ '--spacing-1-5': '0.5625rem',+ '--spacing-2': '0.75rem',+ '--spacing-3': '1.125rem',+ '--spacing-4': '1.5rem',+ '--spacing-5': '1.875rem',+ '--spacing-6': '2.25rem',+ '--spacing-7': '2.625rem',+ '--spacing-8': '3rem',+ '--spacing-9': '3.375rem',+ '--spacing-10': '3.75rem',+ '--spacing-11': '4.125rem',+ '--spacing-12': '4.5rem',// =========================================================================// Radius — soft and roundeddiff --git a/packages/cli/assets/templates/themes/y2k/y2kTheme.ts b/packages/cli/assets/templates/themes/y2k/y2kTheme.tsindex bf46342b12..771d696f29 100644--- a/packages/cli/assets/templates/themes/y2k/y2kTheme.ts+++ b/packages/cli/assets/templates/themes/y2k/y2kTheme.ts@@ -63,16 +63,16 @@ export const y2kTheme = defineTheme({// =========================================================================// Spacing — comfortable preset (base=6)// =========================================================================- '--spacing-0-5': '3px',- '--spacing-1': '6px',- '--spacing-1-5': '9px',- '--spacing-2': '12px',- '--spacing-3': '18px',- '--spacing-4': '24px',- '--spacing-5': '30px',- '--spacing-6': '36px',- '--spacing-7': '42px',- '--spacing-8': '48px',+ '--spacing-0-5': '0.1875rem',+ '--spacing-1': '0.375rem',+ '--spacing-1-5': '0.5625rem',+ '--spacing-2': '0.75rem',+ '--spacing-3': '1.125rem',+ '--spacing-4': '1.5rem',+ '--spacing-5': '1.875rem',+ '--spacing-6': '2.25rem',+ '--spacing-7': '2.625rem',+ '--spacing-8': '3rem',// Size — comfortable preset'--size-element-sm': '32px',diff --git a/packages/cli/assets/theme.template.ts b/packages/cli/assets/theme.template.tsindex 81552fa933..d3ff822ea2 100644--- a/packages/cli/assets/theme.template.ts+++ b/packages/cli/assets/theme.template.ts@@ -373,7 +373,7 @@ export const myTheme = defineTheme({// {// // Narrow at every pointer precision.// when: {width: {below: 'md'}},- // value: {tokens: {'--spacing-4': '12px'}},+ // value: {tokens: {'--spacing-4': '0.75rem'}},// },// {// // Taller controls under a finger or stylus at every width.diff --git a/packages/themes/matcha/src/matchaTheme.spacing.test.ts b/packages/themes/matcha/src/matchaTheme.spacing.test.tsnew file mode 100644index 0000000000..470c251df4--- /dev/null+++ b/packages/themes/matcha/src/matchaTheme.spacing.test.ts@@ -0,0 +1,46 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, expect, it} from 'vitest';+import {matchaTheme} from './matchaTheme';++const ROOT_FONT_SIZE_PX = 16;++// The pixel values these steps had before they moved to rem.+const previousPx: Record<string, number> = {+ '--spacing-0-5': 3,+ '--spacing-1': 6,+ '--spacing-1-5': 9,+ '--spacing-2': 12,+ '--spacing-3': 18,+ '--spacing-4': 24,+ '--spacing-5': 30,+ '--spacing-6': 36,+ '--spacing-7': 42,+ '--spacing-8': 48,+ '--spacing-9': 54,+ '--spacing-10': 60,+ '--spacing-11': 66,+ '--spacing-12': 72,+};++describe('matcha spacing steps', () => {+ const tokens = matchaTheme.tokens as Record<string, string>;+ const spacingSteps = Object.entries(tokens).filter(([name]) =>+ name.startsWith('--spacing-'),+ );++ it('are rem, so they follow the root font size', () => {+ expect(spacingSteps.length).toBe(Object.keys(previousPx).length);+ for (const [name, value] of spacingSteps) {+ expect(value, name).toMatch(/^\d+(\.\d+)?rem$/);+ }+ });++ it('keep their previous pixel values at the default 16px root', () => {+ for (const [name, px] of Object.entries(previousPx)) {+ expect(Number.parseFloat(tokens[name]) * ROOT_FONT_SIZE_PX, name).toBe(+ px,+ );+ }+ });+});diff --git a/packages/themes/matcha/src/matchaTheme.ts b/packages/themes/matcha/src/matchaTheme.tsindex aa5c93d981..baf86314f4 100644--- a/packages/themes/matcha/src/matchaTheme.ts+++ b/packages/themes/matcha/src/matchaTheme.ts@@ -180,20 +180,20 @@ export const matchaTheme = defineTheme({// =========================================================================// Spacing// =========================================================================- '--spacing-0-5': '3px',- '--spacing-1': '6px',- '--spacing-1-5': '9px',- '--spacing-2': '12px',- '--spacing-3': '18px',- '--spacing-4': '24px',- '--spacing-5': '30px',- '--spacing-6': '36px',- '--spacing-7': '42px',- '--spacing-8': '48px',- '--spacing-9': '54px',- '--spacing-10': '60px',- '--spacing-11': '66px',- '--spacing-12': '72px',+ '--spacing-0-5': '0.1875rem',+ '--spacing-1': '0.375rem',+ '--spacing-1-5': '0.5625rem',+ '--spacing-2': '0.75rem',+ '--spacing-3': '1.125rem',+ '--spacing-4': '1.5rem',+ '--spacing-5': '1.875rem',+ '--spacing-6': '2.25rem',+ '--spacing-7': '2.625rem',+ '--spacing-8': '3rem',+ '--spacing-9': '3.375rem',+ '--spacing-10': '3.75rem',+ '--spacing-11': '4.125rem',+ '--spacing-12': '4.5rem',// =========================================================================// Radius — soft and roundeddiff --git a/packages/themes/y2k/src/y2kTheme.spacing.test.ts b/packages/themes/y2k/src/y2kTheme.spacing.test.tsnew file mode 100644index 0000000000..a90ba661e2--- /dev/null+++ b/packages/themes/y2k/src/y2kTheme.spacing.test.ts@@ -0,0 +1,42 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, expect, it} from 'vitest';+import {y2kTheme} from './y2kTheme';++const ROOT_FONT_SIZE_PX = 16;++// The pixel values these steps had before they moved to rem.+const previousPx: Record<string, number> = {+ '--spacing-0-5': 3,+ '--spacing-1': 6,+ '--spacing-1-5': 9,+ '--spacing-2': 12,+ '--spacing-3': 18,+ '--spacing-4': 24,+ '--spacing-5': 30,+ '--spacing-6': 36,+ '--spacing-7': 42,+ '--spacing-8': 48,+};++describe('y2k spacing steps', () => {+ const tokens = y2kTheme.tokens as Record<string, string>;+ const spacingSteps = Object.entries(tokens).filter(([name]) =>+ name.startsWith('--spacing-'),+ );++ it('are rem, so they follow the root font size', () => {+ expect(spacingSteps.length).toBe(Object.keys(previousPx).length);+ for (const [name, value] of spacingSteps) {+ expect(value, name).toMatch(/^\d+(\.\d+)?rem$/);+ }+ });++ it('keep their previous pixel values at the default 16px root', () => {+ for (const [name, px] of Object.entries(previousPx)) {+ expect(Number.parseFloat(tokens[name]) * ROOT_FONT_SIZE_PX, name).toBe(+ px,+ );+ }+ });+});diff --git a/packages/themes/y2k/src/y2kTheme.ts b/packages/themes/y2k/src/y2kTheme.tsindex bf46342b12..771d696f29 100644--- a/packages/themes/y2k/src/y2kTheme.ts+++ b/packages/themes/y2k/src/y2kTheme.ts@@ -63,16 +63,16 @@ export const y2kTheme = defineTheme({// =========================================================================// Spacing — comfortable preset (base=6)// =========================================================================- '--spacing-0-5': '3px',- '--spacing-1': '6px',- '--spacing-1-5': '9px',- '--spacing-2': '12px',- '--spacing-3': '18px',- '--spacing-4': '24px',- '--spacing-5': '30px',- '--spacing-6': '36px',- '--spacing-7': '42px',- '--spacing-8': '48px',+ '--spacing-0-5': '0.1875rem',+ '--spacing-1': '0.375rem',+ '--spacing-1-5': '0.5625rem',+ '--spacing-2': '0.75rem',+ '--spacing-3': '1.125rem',+ '--spacing-4': '1.5rem',+ '--spacing-5': '1.875rem',+ '--spacing-6': '2.25rem',+ '--spacing-7': '2.625rem',+ '--spacing-8': '3rem',// Size — comfortable preset'--size-element-sm': '32px',