diff --git a/src/presentation/design-system/tokens/primitive.css b/src/presentation/design-system/tokens/primitive.css index c7c2b5ab..c0b47770 100644 --- a/src/presentation/design-system/tokens/primitive.css +++ b/src/presentation/design-system/tokens/primitive.css @@ -26,6 +26,8 @@ --font-size-sm: 0.875rem; --font-size-md: 1rem; --font-size-lg: 1.125rem; + --font-size-xl: 1.25rem; + --font-size-2xl: 1.5rem; --line-height-tight: 1.25; --line-height-normal: 1.5; --line-height-relaxed: 1.7; diff --git a/src/presentation/design-system/tokens/semantic.css b/src/presentation/design-system/tokens/semantic.css index de4142f0..0d8f8ab8 100644 --- a/src/presentation/design-system/tokens/semantic.css +++ b/src/presentation/design-system/tokens/semantic.css @@ -31,6 +31,11 @@ --color-danger-border: oklch(0.72 0.12 25); --font-sans: system-ui, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Noto Sans CJK KR", sans-serif; + /* 08-04. One step per heading level; a product retunes the scale here. */ + --font-size-heading-2: var(--font-size-2xl); + --font-size-heading-3: var(--font-size-xl); + --font-size-heading-4: var(--font-size-md); + --font-weight-heading: var(--font-weight-semibold); --spacing-page: var(--space-6); --radius-control: var(--radius-sm); --radius-surface: var(--radius-md); diff --git a/src/presentation/styles/theme/base.css b/src/presentation/styles/theme/base.css index aeb4f630..3c2a3d82 100644 --- a/src/presentation/styles/theme/base.css +++ b/src/presentation/styles/theme/base.css @@ -34,8 +34,25 @@ letter-spacing: -0.04em; } + /* 08-04. Tailwind's preflight resets headings to body text; each level + gets its own step so a section title does not read like a paragraph. */ + h2, + h3, + h4 { + font-weight: var(--font-weight-heading); + line-height: var(--line-height-tight); + } + h2 { - line-height: 1.25; + font-size: var(--font-size-heading-2); + } + + h3 { + font-size: var(--font-size-heading-3); + } + + h4 { + font-size: var(--font-size-heading-4); } :focus-visible { diff --git a/tests/e2e/typography.spec.ts b/tests/e2e/typography.spec.ts new file mode 100644 index 00000000..3fa3cfe3 --- /dev/null +++ b/tests/e2e/typography.spec.ts @@ -0,0 +1,33 @@ +import { expect, test } from "../support/browser/strict-browser-test.ts"; + +// 08-04. Tailwind's preflight resets every heading to the body size and +// weight, so a section title read like a paragraph. Each level must stand +// apart from the next one and from body copy. +test("steps heading size and weight down from h2 to body copy", async ({ + page, +}) => { + await page.goto("/examples/states"); + await expect(page.getByRole("heading", { level: 1 })).toBeVisible(); + + const scale = await page.evaluate(() => { + const read = (element: Element | null) => { + if (!element) throw new Error("missing element"); + const style = getComputedStyle(element); + return { + size: Number.parseFloat(style.fontSize), + weight: Number.parseFloat(style.fontWeight), + }; + }; + const main = document.querySelector("main"); + return { + h2: read(main?.querySelector("h2") ?? null), + h3: read(main?.querySelector("h3") ?? null), + body: read(document.body), + }; + }); + + expect(scale.h2.size).toBeGreaterThan(scale.h3.size); + expect(scale.h3.size).toBeGreaterThan(scale.body.size); + expect(scale.h2.weight).toBeGreaterThan(scale.body.weight); + expect(scale.h3.weight).toBeGreaterThan(scale.body.weight); +});