Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

Typography (#55)

Cindy Zhang57399b8728fd
diff --git a/.context/proposals/xds-text-heading-spec.md b/.context/proposals/xds-text-heading-spec.md
new file mode 100644
index 0000000000..63769e0653
--- /dev/null
+++ b/.context/proposals/xds-text-heading-spec.md
@@ -0,0 +1,594 @@
+# XDSText and XDSHeading Component Spec
+
+> **Status:** Draft
+> **Date:** 2026-01-26
+> **Context:** [typography-tokens.md](../explorations/typography-tokens.md)
+
+---
+
+## Overview
+
+This spec defines the API for `XDSText` and `XDSHeading` components, informed by the typography tokens exploration and analysis of the current implementation.
+
+---
+
+## Design Principles
+
+1. **Constrained escape hatches** — `xstyle` allowed for layout only (margins, flex); typography locked
+2. **Semantic-first** — Guide LLMs toward semantic types over raw sizes
+3. **Smart defaults** — Minimize required props; sensible behavior out of the box
+4. **Theme-driven** — Components pull styles from theme, not hardcoded mappings
+5. **Explicit over magic** — Prefer explicit props (e.g., `color="inherit"`) over context-based behavior
+6. **Boolean flags prefixed** — Use `is` or `has` prefix for boolean props (e.g., `hasCapsize`)
+
+---
+
+## XDSHeading
+
+### API
+
+```typescript
+interface XDSHeadingProps {
+ /**
+ * Visual heading level (1-6). Determines styling from theme.
+ * Required to ensure intentional visual hierarchy.
+ */
+ level: 1 | 2 | 3 | 4 | 5 | 6;
+
+ /**
+ * Accessibility level override. When set, the `aria-level` will differ
+ * from the visual `level`. Use this when the visual hierarchy doesn't
+ * match the document outline (e.g., sidebar headings, reused components).
+ *
+ * @default Same as `level`
+ *
+ * @example
+ * // Visually styled as h2, but semantically h3 in document outline
+ * <XDSHeading level={2} accessibilityLevel={3}>Sidebar Section</XDSHeading>
+ */
+ accessibilityLevel?: 1 | 2 | 3 | 4 | 5 | 6;
+
+ /**
+ * Visual variant. Themes define different scales for each variant.
+ * @default 'default'
+ */
+ variant?: 'default' | 'editorial';
+
+ /**
+ * Text color.
+ * @default 'primary'
+ */
+ color?: 'primary' | 'secondary' | 'disabled' | 'placeholder' | 'active' | 'inherit';
+
+ /**
+ * Display type. Headings default to block.
+ * @default 'block'
+ */
+ display?: 'inline' | 'block';
+
+ /**
+ * Maximum lines before truncation. 0 = no truncation.
+ * When set, shows tooltip on hover if content is truncated.
+ * @default 0
+ */
+ maxLines?: number;
+
+ /**
+ * Control tooltip behavior for truncated text.
+ * - `true` (default when maxLines > 0): show tooltip at default position
+ * - `false`: disable tooltip
+ * - Position value: show tooltip at specific position
+ */
+ truncateTooltip?: boolean | Position;
+
+ /**
+ * Enable optical alignment (textBoxTrim).
+ * @default false
+ */
+ hasCapsize?: boolean;
+
+ /**
+ * Strikethrough decoration.
+ * @default false
+ */
+ hasStrikethrough?: boolean;
+
+ /**
+ * Constrained styles for layout integration.
+ * Allows margins, flex child props, text alignment.
+ * See "Constrained xstyle" section for allowed properties.
+ */
+ xstyle?: StaticStyles<XDSTextXStyleAllowed>;
+
+ children: React.ReactNode;
+
+ 'data-testid'?: string;
+ id?: string;
+}
+```
+
+### Rationale
+
+**`level` as primary prop (visual):**
+- Determines visual styling from theme
+- Required to ensure intentional hierarchy
+- TypeScript constrains to valid values (no h7)
+
+**`accessibilityLevel` for document outline:**
+- Defaults to `level` — visual and semantic match by default
+- Override when visual hierarchy differs from document outline
+- Common use cases:
+ - Sidebar headings that shouldn't affect main content outline
+ - Reusable card components used at different nesting depths
+ - Fixed page sections where visual consistency > semantic correctness
+
+**`variant` for scale switching:**
+- `'default'` — standard XDS scale (denser)
+- `'editorial'` — larger scale for content-heavy pages
+- Extensible for future variants (e.g., `'display'`, `'marketing'`)
+
+**No separate `semanticLevel` prop:**
+- Current implementation has both `type` and `semanticLevel` which can diverge
+- New design: `level` IS the semantic level; use `variant` for visual differences
+- If truly needed (rare), can override via `aria-level` in future version
+
+### Theme Integration
+
+```typescript
+// Theme defines complete styles per level + variant
+const theme = {
+ typography: {
+ heading: {
+ default: {
+ 1: { fontSize: '1.25rem', lineHeight: '1.2', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 20px
+ 2: { fontSize: '1.125rem', lineHeight: '1.33', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 18px
+ 3: { fontSize: '1rem', lineHeight: '1.25', fontWeight: 700, fontFamily: 'var(--font-heading)' }, // 16px
+ 4: { fontSize: '0.875rem', lineHeight: '1.43', fontWeight: 700, fontFamily: 'var(--font-heading)' }, // 14px
+ 5: { fontSize: '0.875rem', lineHeight: '1.43', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 14px
+ 6: { fontSize: '0.75rem', lineHeight: '1.33', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 12px
+ },
+ editorial: {
+ 1: { fontSize: '2rem', lineHeight: '1.5', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 32px
+ 2: { fontSize: '1.5rem', lineHeight: '1.33', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 24px
+ 3: { fontSize: '1.25rem', lineHeight: '1.4', fontWeight: 700, fontFamily: 'var(--font-heading)' }, // 20px
+ 4: { fontSize: '1rem', lineHeight: '1.5', fontWeight: 700, fontFamily: 'var(--font-heading)' }, // 16px
+ 5: { fontSize: '0.875rem', lineHeight: '1.43', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 14px (fallback)
+ 6: { fontSize: '0.75rem', lineHeight: '1.33', fontWeight: 600, fontFamily: 'var(--font-heading)' }, // 12px (fallback)
+ },
+ },
+ },
+};
+```
+
+### Usage Examples
+
+```tsx
+// Standard headings
+<XDSHeading level={1}>Page Title</XDSHeading>
+<XDSHeading level={2}>Section</XDSHeading>
+<XDSHeading level={3}>Subsection</XDSHeading>
+
+// Editorial variant (larger scale)
+<XDSHeading level={1} variant="editorial">Article Title</XDSHeading>
+
+// Truncated heading with tooltip
+<XDSHeading level={2} maxLines={1}>Very Long Section Title That Might Truncate</XDSHeading>
+
+// Inherit color from parent
+<XDSHeading level={3} color="inherit">Inherits Parent Color</XDSHeading>
+```
+
+---
+
+## XDSText
+
+### API
+
+```typescript
+type XDSTextType = 'body' | 'large' | 'label' | 'large-label' | 'supporting' | 'code';
+type XDSTextSize = '4xs' | '3xs' | '2xs' | 'xsm' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl';
+
+interface XDSTextProps {
+ /**
+ * Semantic text type. Determines size, weight, and line-height from theme.
+ * Required to ensure semantic usage.
+ */
+ type: XDSTextType;
+
+ /**
+ * Explicit font size override. When set, overrides the size from `type`
+ * but preserves other type properties (font-family, default color).
+ *
+ * ⚠️ Lint rule: Prefer using `type` alone. Use `size` only for custom
+ * UI elements that need explicit size control (metrics, callouts).
+ */
+ size?: XDSTextSize;
+
+ /**
+ * Text color. Defaults vary by type:
+ * - 'supporting', 'label' → 'secondary'
+ * - others → 'primary'
+ */
+ color?: 'primary' | 'secondary' | 'disabled' | 'placeholder' | 'active' | 'inherit';
+
+ /**
+ * Font weight override.
+ */
+ weight?: 'normal' | 'medium' | 'semibold' | 'bold';
+
+ /**
+ * Display type. Text defaults to inline.
+ * @default 'inline'
+ */
+ display?: 'inline' | 'block';
+
+ /**
+ * Maximum lines before truncation. 0 = no truncation.
+ * Note: truncated text renders as block.
+ * @default 0
+ */
+ maxLines?: number;
+
+ /**
+ * Control tooltip behavior for truncated text.
+ * @default true (when maxLines > 0)
+ */
+ truncateTooltip?: boolean | Position;
+
+ /**
+ * Word break behavior for truncated text.
+ * @default 'break-all' for maxLines=1, 'break-word' otherwise
+ */
+ wordBreak?: 'break-word' | 'break-all';
+
+ /**
+ * Text wrapping behavior.
+ */
+ textWrap?: 'wrap' | 'nowrap';
+
+ /**
+ * Enable optical alignment (textBoxTrim).
+ * @default false
+ */
+ hasCapsize?: boolean;
+
+ /**
+ * Strikethrough decoration.
+ * @default false
+ */
+ hasStrikethrough?: boolean;
+
+ /**
+ * Use tabular (monospace) numbers for alignment.
+ * @default false
+ */
+ hasTabularNumbers?: boolean;
+
+ /**
+ * Constrained styles for layout integration.
+ * Allows margins, flex child props, text alignment.
+ * See "Constrained xstyle" section for allowed properties.
+ */
+ xstyle?: StaticStyles<XDSTextXStyleAllowed>;
+
+ children: React.ReactNode;
+
+ 'data-testid'?: string;
+ id?: string;
+}
+```
+
+### Type Values
+
+| Type | Size | Weight | Line Height | Default Color | Use Case |
+|------|------|--------|-------------|---------------|----------|
+| `body` | 14px | Regular | 20px (1.43) | primary | The bulk of content |
+| `large` | 16px | Regular | 24px (1.5) | primary | Emphasized content, quotes, descriptions |
+| `label` | 14px | Bold | 20px (1.43) | primary | Form/chart/table column labels |
+| `large-label` | 16px | SemiBold | 24px (1.5) | primary | Empty state labels, prominent labels |
+| `supporting` | 12px | Regular | 16px (1.33) | secondary | Helper text, supplemental info |
+| `code` | 14px | Regular | 20px (1.43) | primary | Inline code, monospace |
+
+### Rationale
+
+**Type-based (not size-based):**
+- Semantic types guide correct usage
+- Themes control actual sizes per type
+- Weights and line-heights bundled with type
+- LLMs learn patterns from codebase examples
+- `size` prop available for overrides, with lint steering toward semantic usage
+
+**Color defaults based on type:**
+- `supporting` defaults to secondary color (helper text is de-emphasized)
+- All other types default to primary color
+- Override with `color` prop when needed
+
+### Theme Integration
+
+```typescript
+const theme = {
+ typography: {
+ text: {
+ body: { fontSize: '0.875rem', lineHeight: '1.43', fontWeight: 400, fontFamily: 'var(--font-heading)' },
+ large: { fontSize: '1rem', lineHeight: '1.5', fontWeight: 400, fontFamily: 'var(--font-heading)' },
+ label: { fontSize: '0.875rem', lineHeight: '1.43', fontWeight: 700, fontFamily: 'var(--font-heading)' },
+ 'large-label': { fontSize: '1rem', lineHeight: '1.5', fontWeight: 600, fontFamily: 'var(--font-heading)' },
+ supporting: { fontSize: '0.75rem', lineHeight: '1.33', fontWeight: 400, fontFamily: 'var(--font-heading)' },
+ code: { fontSize: '0.875rem', lineHeight: '1.43', fontWeight: 400, fontFamily: 'var(--font-code)' },
+ },
+ },
+};
+```
+
+### Usage Examples
+
+```tsx
+// Standard body text (type is required)
+<XDSText type="body">Body text</XDSText>
+
+// Supporting/helper text (defaults to secondary color)
+<XDSText type="supporting">Last updated 5 minutes ago</XDSText>
+
+// Labels for form fields, chart columns, table headers
+<XDSText type="label">Email address</XDSText>
+
+// Large label for empty states, prominent labels
+<XDSText type="large-label">No results found</XDSText>
+
+// Large body for quotes, descriptions
+<XDSText type="large">Important message</XDSText>
+
+// Code
+<XDSText type="code">const x = 1;</XDSText>
+
+// Truncation
+<XDSText type="body" maxLines={2}>Long text that will be clamped to two lines...</XDSText>
+
+// Inherit color (for nested text)
+<XDSText type="body" color="inherit">Inherits parent color</XDSText>
+
+// Size override for custom UI elements (lint will warn if overused)
+<XDSText type="body" size="4xl" weight="bold">
+ {metricValue}
+</XDSText>
+```
+
+---
+
+## Component-Specific Text Styles
+
+These styles are used internally by specific components, not exposed on XDSText:
+
+| Style | Size | Weight | Line Height | Used By |
+|-------|------|--------|-------------|---------|
+| `data-viz-large` | 32px | Medium | 36px (1.125) | XDSMetricTile |
+| `data-viz-small` | 24px | Medium | 28px (1.167) | XDSMetricTile |
+| `app-name` | 20px | Bold | 24px (1.2) | Page navigation product name |
+| `badge` | 12px | SemiBold | 16px (1.33) | XDSBadge |
+
+These are defined in `theme.components.text.componentStyles` and accessed directly by their respective components.
+
+---
+
+## Size Scale
+
+When using the `size` prop to override type-based sizing:
+
+| Size | Value | Typical Usage |
+|------|-------|---------------|
+| `4xs` | 0.5rem (8px) | Citation, micro text |
+| `3xs` | 0.625rem (10px) | Micro labels |
+| `2xs` | 0.6875rem (11px) | Small micro text |
+| `xsm` | 0.75rem (12px) | Captions, badges, supporting |
+| `sm` | 0.8125rem (13px) | Secondary text |
+| `base` | 0.875rem (14px) | Body (XDS default) |
+| `lg` | 1rem (16px) | Large body, input text |
+| `xl` | 1.125rem (18px) | Large emphasis, h2 |
+| `2xl` | 1.25rem (20px) | h1, subtitle |
+| `3xl` | 1.5rem (24px) | Editorial h2, card title |
+| `4xl` | 2rem (32px) | Editorial h1, data viz |
+
+### Line Height Coupling
+
+Line height is automatically determined by size (not exposed as prop):
+
+```typescript
+const lineHeightBySize = {
+ '4xs': 1.33,
+ '3xs': 1.33,
+ '2xs': 1.33,
+ xsm: 1.33,
+ sm: 1.43,
+ base: 1.43,
+ lg: 1.5,
+ xl: 1.4,
+ '2xl': 1.3,
+ '3xl': 1.25,
+ '4xl': 1.2,
+};
+```
+
+### Lint Rules for Size Usage
+
+```typescript
+// Lint rule: xds/prefer-semantic-type
+// Warns when `size` prop is used, suggesting to rely on `type` instead.
+// Severity: warning (not error - size is valid for custom UI elements)
+
+// Example lint output:
+// ⚠️ Line 42: Consider removing `size` prop and using semantic `type` alone.
+// The `size` prop should only be used for custom UI elements like
+// dashboard metrics or data visualizations.
+```
+
+---
+
+## Truncation Behavior
+
+### Consolidated Props
+
+| Prop | Type | Default | Notes |
+|------|------|---------|-------|
+| `maxLines` | `number` | `0` | 0 = no truncation |
+| `truncateTooltip` | `boolean \| Position` | `true` | Shown only when actually overflowing |
+| `wordBreak` | `'break-word' \| 'break-all'` | Smart | `break-all` for 1 line, `break-word` otherwise |
+
+### Behavior
+
+1. **maxLines=0**: No truncation, text wraps naturally
+2. **maxLines=1**: Single-line truncation with ellipsis, defaults to `break-all`
+3. **maxLines>1**: Multi-line clamp with `-webkit-line-clamp`
+4. **Tooltip**: Only shown when content actually overflows (detected via ref)
+5. **Tooltip content**: Clamped to 10 lines max to prevent huge tooltips
+6. **Truncated text always renders as block** (required for line-clamp)
+
+### Migration from Current API
+
+| Current | New |
+|---------|-----|
+| `numberOfLines={2}` | `maxLines={2}` |
+| `hasTooltipForTruncatedText={false}` | `truncateTooltip={false}` |
+| `truncatedTextTooltipPosition="above"` | `truncateTooltip="above"` |
+
+---
+
+## Disabled State Handling
+
+### Open Question
+
+Current implementation uses `XDSInternalTextColorDisabledOverrideContext` to let parent components (like buttons) force disabled styling on child text.
+
+**Options:**
+
+1. **Keep context pattern** — Parent sets disabled, children inherit
+2. **Explicit prop only** — `color="disabled"` must be set explicitly
+3. **Both** — Support context but also allow explicit override
+
+**Recommendation:** Keep context for component library internals (XDSButton disabling its label), but also support explicit `color="disabled"` for standalone usage.
+
+---
+
+## Constrained xstyle
+
+Both XDSText and XDSHeading support a **constrained `xstyle` prop** for layout integration. This allows spacing and flex positioning without escaping typography styles.
+
+### Allowed Properties
+
+```typescript
+xstyle?: StaticStyles<{
+ // Margins (from XDSMarginXStyles)
+ margin?: unknown;
+ marginTop?: unknown;
+ marginBottom?: unknown;
+ marginStart?: unknown;
+ marginEnd?: unknown;
+ marginBlock?: unknown;
+ marginInline?: unknown;
+
+ // Width constraints (from XDSWidthXStyles)
+ width?: unknown;
+ minWidth?: unknown;
+ maxWidth?: unknown;
+
+ // Flex child properties
+ alignSelf?: unknown;
+ flexBasis?: unknown;
+ flexGrow?: unknown;
+ flexShrink?: unknown;
+ flexWrap?: unknown;
+
+ // Text layout (non-typography)
+ overflow?: unknown;
+ overflowWrap?: unknown;
+ textAlign?: unknown;
+ textAlignLast?: unknown;
+ textOverflow?: unknown;
+ verticalAlign?: unknown;
+ whiteSpace?: unknown;
+ wordBreak?: unknown;
+
+ // Decoration (allowed since hasStrikethrough exists)
+ textDecoration?: unknown;
+}>;
+```
+
+### NOT Allowed (enforced by type)
+
+- `fontSize`, `lineHeight`, `fontWeight`, `fontFamily` — use `type`/`level` props
+- `color` — use `color` prop
+- `padding` — internal to component
+- `background`, `border` — not text concerns
+
+### Rationale
+
+This matches the internal Meta implementation pattern. It allows:
+- Layout integration (margins for spacing rhythm)
+- Flex positioning (alignSelf for cross-axis control)
+- Text alignment (textAlign for content alignment)
+
+While preventing:
+- Typography escapes (can't override font-size)
+- Color escapes (must use semantic color prop)
+- Structural changes (no padding/background)
+
+---
+
+## Props NOT Included
+
+| Prop | Reason |
+|------|--------|
+| `style` | Prevents escaping design system |
+| `className` | Prevents escaping design system |
+| `lineHeight` | Coupled to size/type internally |
+| `fontSize` | Use `type` or `size` prop |
+| `fontFamily` | Determined by type (body vs code vs heading) |
+
+---
+
+## Migration Notes
+
+### XDSText Type Mapping
+
+| Current | New | Notes |
+|---------|-----|-------|
+| `body` | `body` | Same |
+| `large-body` | `large` | Renamed for brevity |
+| `emphasized` | `label` | Renamed to match use case (form/chart labels) |
+| `large-emphasized` | `large-label` | Renamed to match use case |
+| `supporting` | `supporting` | Same |
+| `label` | `label` | Same (if existed) |
+
+### XDSHeading Type Mapping
+
+| Current | New | Notes |
+|---------|-----|-------|
+| `header1` | `level={1}` | Semantic-first |
+| `header2` | `level={2}` | Semantic-first |
+| `header3` | `level={3}` | Semantic-first |
+| `header4` | `level={4}` | Semantic-first |
+| `display` | `level={1} variant="display"` | TBD: add display variant? |
+| `editorialHeader1` | `level={1} variant="editorial"` | Variant-based |
+| `header1_DO_NOT_USE` | Deprecated | Remove in migration |
+
+---
+
+## Open Questions
+
+1. **Display variant for XDSHeading?** — Should we add `variant="display"` for hero/marketing use cases, or use XDSText with size override?
+
+2. **Nested heading context** — Current impl prevents nested headings from both having `role="heading"`. Keep this behavior?
+
+3. **`emphasized` type** — Should we keep as a type, or always use `weight` prop? Current decision: weight prop.
+
+4. **textWrap prop** — Is this needed on XDSHeading, or only XDSText?
+
+---
+
+## Next Steps
+
+1. [ ] Review and finalize type values
+2. [ ] Define theme typography structure with tokens team
+3. [ ] Implement XDSHeading
+4. [ ] Implement XDSText
+5. [ ] Create migration codemod for type changes
+6. [ ] Add lint rule for `size` prop usage
diff --git a/README.md b/README.md
index 46f38671ef..51f07ff9bc 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,82 @@ XDS is an open source design system born from years of building internal tools a
- **Automatic spacing** — Context-aware spacing compensation eliminates "double padding" issues
- **AI-ready** — JSDoc annotations with composition hints designed for LLM-assisted development
+## Getting Started
+
+### Installation
+
+```bash
+npm install @xds/core
+# or
+yarn add @xds/core
+```
+
+### 1. Set Up the Theme Provider
+
+Wrap your application with the `Theme` component. This sets up CSS custom properties used by all XDS components.
+
+```tsx
+import {Theme, defaultTheme} from '@xds/core';
+
+function App() {
+ return (
+ <Theme theme={defaultTheme}>
+ <YourApp />
+ </Theme>
+ );
+}
+```
+
+### 2. Import Typography Styles (Optional)
+
+For styling native HTML elements (h1-h6, p, lists, code blocks, etc.), import the typography stylesheet:
+
+```tsx
+import '@xds/core/typography.css';
+```
+
+Apply to your document body or use `XDSFontWrapper` for scoped sections:
+
+```tsx
+// Option A: Global - apply to body
+<body className="xds-typography">
+
+// Option B: Scoped - wrap specific content
+import { XDSFontWrapper } from '@xds/core';
+
+<XDSFontWrapper>
+ <article dangerouslySetInnerHTML={{ __html: markdownContent }} />
+</XDSFontWrapper>
+```
+
+The typography styles support two heading scales:
+
+- **default** — Dense scale for internal tools (h1: 20px)
+- **editorial** — Larger scale for documentation/content (h1: 32px)
+
+```tsx
+<XDSFontWrapper variant="editorial">
+ <h1>Article Title</h1>
+ <p>Long-form content...</p>
+</XDSFontWrapper>
+```
+
+### 3. Use Components
+
+```tsx
+import {XDSButton, XDSText, XDSHeading} from '@xds/core';
+
+function Example() {
+ return (
+ <>
+ <XDSHeading>Welcome</XDSHeading>
+ <XDSText>Click the button below to get started.</XDSText>
+ <XDSButton label="Get Started" onPress={() => console.log('clicked')} />
+ </>
+ );
+}
+```
+
## Philosophy
- **AI-First** — Built to produce better trajectories in AI-assisted development, with auto-documentation and patterns designed for LLM consumption
@@ -37,12 +113,12 @@ A library of 300+ reusable UI building blocks with full TypeScript support.
## Project Structure
-| Directory | Purpose |
-|-----------|---------|
-| `apps/` | Application packages: documentation site, sandbox, and Storybook |
-| `packages/` | Published packages: core components and utilities |
-| `internal/` | Internal tooling: test utilities and build helpers |
-| `e2e/` | End-to-end tests using Playwright |
+| Directory | Purpose |
+| ----------- | ---------------------------------------------------------------- |
+| `apps/` | Application packages: documentation site, sandbox, and Storybook |
+| `packages/` | Published packages: core components and utilities |
+| `internal/` | Internal tooling: test utilities and build helpers |
+| `e2e/` | End-to-end tests using Playwright |
## Contributing
diff --git a/apps/storybook/stories/FontWrapper.stories.tsx b/apps/storybook/stories/FontWrapper.stories.tsx
new file mode 100644
index 0000000000..7f17c38bcb
--- /dev/null
+++ b/apps/storybook/stories/FontWrapper.stories.tsx
@@ -0,0 +1,279 @@
+import type {Meta, StoryObj} from '@storybook/react';
+import * as stylex from '@stylexjs/stylex';
+import {XDSFontWrapper, useXDSFontWrapperStyles} from '@xds/core';
+
+const meta = {
+ title: 'Typography/XDSFontWrapper',
+ component: XDSFontWrapper,
+ parameters: {
+ layout: 'padded',
+ },
+ tags: ['autodocs'],
+ argTypes: {
+ variant: {
+ control: 'radio',
+ options: ['default', 'editorial'],
+ },
+ },
+} satisfies Meta<typeof XDSFontWrapper>;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+/**
+ * XDSFontWrapper applies base typography styles to native HTML elements.
+ * Uses typography.css which references theme CSS custom properties.
+ */
+export const Default: Story = {
+ args: {
+ variant: 'default',
+ children: (
+ <>
+ <h1>Heading 1 (20px)</h1>
+ <p>
+ XDSFontWrapper automatically styles native HTML elements using the
+ reset.css stylesheet. The styles use CSS custom properties from the
+ theme, so they adapt automatically when you switch themes.
+ </p>
+ <h2>Heading 2 (18px)</h2>
+ <p>
+ This is body text at 14px. The default variant uses a dense heading
+ scale optimized for internal tools and applications.
+ </p>
+ </>
+ ),
+ },
+};
+
+/**
+ * Editorial variant uses larger heading sizes for content-heavy pages
+ */
+export const Editorial: Story = {
+ args: {
+ variant: 'editorial',
+ children: (
+ <>
+ <h1>Article Title (32px)</h1>
+ <p>
+ The editorial variant uses a larger heading scale designed for
+ documentation, blog posts, and other long-form content where
+ readability is the primary concern.
+ </p>
+ <h2>Section Heading (24px)</h2>
+ <p>
+ Body text remains at 14px for consistency, but headings are
+ significantly larger to create clear visual hierarchy.
+ </p>
+ </>
+ ),
+ },
+};
+
+/**
+ * Demonstrates all prose elements with default styling
+ */
+export const AllElements: Story = {
+ args: {
+ variant: 'default',
+ children: (
+ <>
+ <h1>Heading 1</h1>
+ <h2>Heading 2</h2>
+ <h3>Heading 3</h3>
+ <h4>Heading 4</h4>
+ <h5>Heading 5</h5>
+ <h6>Heading 6</h6>
+
+ <p>
+ This is a paragraph with <strong>strong text</strong> and{' '}
+ <em>italic text</em>. You can also include <a href="#">links</a> and{' '}
+ <code>inline code</code>.
+ </p>
+
+ <h3>Lists</h3>
+ <ul>
+ <li>Unordered list item 1</li>
+ <li>Unordered list item 2</li>
+ <li>Unordered list item 3</li>
+ </ul>
+
+ <ol>
+ <li>Ordered list item 1</li>
+ <li>Ordered list item 2</li>
+ <li>Ordered list item 3</li>
+ </ol>
+
+ <h3>Blockquote</h3>
+ <blockquote>
+ Design systems are a set of interconnected patterns and shared
+ practices coherently organized to achieve the purpose of digital
+ products.
+ </blockquote>
+
+ <h3>Code Block</h3>
+ <pre>
+ <code>{`function greet(name: string) {
+ return \`Hello, \${name}!\`;
+}`}</code>
+ </pre>
+
+ <hr />
+
+ <p>Content after a horizontal rule.</p>
+ </>
+ ),
+ },
+};
+
+/**
+ * Comparison of default vs editorial heading scales
+ */
+export const VariantComparison: Story = {
+ render: () => (
+ <div style={{display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 32}}>
+ <div>
+ <p style={{marginBottom: 16, fontWeight: 600}}>Default Variant</p>
+ <XDSFontWrapper variant="default">
+ <h1>Heading 1</h1>
+ <h2>Heading 2</h2>
+ <h3>Heading 3</h3>
+ <h4>Heading 4</h4>
+ <p>Body text paragraph</p>
+ </XDSFontWrapper>
+ </div>
+ <div>
+ <p style={{marginBottom: 16, fontWeight: 600}}>Editorial Variant</p>
+ <XDSFontWrapper variant="editorial">
+ <h1>Heading 1</h1>
+ <h2>Heading 2</h2>
+ <h3>Heading 3</h3>
+ <h4>Heading 4</h4>
+ <p>Body text paragraph</p>
+ </XDSFontWrapper>
+ </div>
+ </div>
+ ),
+};
+
+/**
+ * Example markdown-like content (typical CMS output)
+ */
+export const MarkdownContent: Story = {
+ args: {
+ variant: 'editorial',
+ children: (
+ <>
+ <h1>Getting Started with XDS</h1>
+ <p>
+ XDS is a design system for building internal tools and products. This
+ guide will help you get up and running quickly.
+ </p>
+
+ <h2>Installation</h2>
+ <p>Install the package using your preferred package manager:</p>
+ <pre>
+ <code>npm install @xds/core</code>
+ </pre>
+
+ <h2>Basic Usage</h2>
+ <p>
+ Import the components you need and wrap your app in the Theme
+ provider:
+ </p>
+ <pre>
+ <code>{`import { Theme, defaultTheme, XDSButton } from '@xds/core';
+
+function App() {
+ return (
+ <Theme theme={defaultTheme}>
+ <XDSButton label="Click me" onPress={() => alert('Hello!')} />
+ </Theme>
+ );
+}`}</code>
+ </pre>
+
+ <h2>Available Components</h2>
+ <p>XDS provides the following component categories:</p>
+ <ul>
+ <li>
+ <strong>Typography</strong> — XDSText, XDSHeading, XDSFontWrapper
+ </li>
+ <li>
+ <strong>Inputs</strong> — XDSButton, XDSTextInput, XDSCheckboxInput
+ </li>
+ <li>
+ <strong>Layout</strong> — XDSHStack, XDSVStack, XDSCard, XDSSection
+ </li>
+ <li>
+ <strong>Feedback</strong> — XDSTooltip, XDSHoverCard
+ </li>
+ </ul>
+
+ <h2>Theming</h2>
+ <blockquote>
+ Pro tip: The reset.css styles use CSS custom properties from the
+ theme, so they automatically adapt when you switch themes.
+ </blockquote>
+
+ <hr />
+
+ <h2>Next Steps</h2>
+ <ol>
+ <li>Explore the component documentation in Storybook</li>
+ <li>Check out the example applications</li>
+ <li>Join our Slack channel for support</li>
+ </ol>
+ </>
+ ),
+ },
+};
+
+/**
+ * Alternative approach: Using StyleX styles programmatically via useFontWrapperStyles hook.
+ * This is useful when you need more control over individual elements.
+ */
+function StyleXApproachDemo() {
+ const {headingStyles, proseStyles} = useXDSFontWrapperStyles();
+
+ return (
+ <XDSFontWrapper>
+ <p {...stylex.props(proseStyles?.p)}>
+ While XDSFontWrapper automatically styles native elements via CSS, you
+ can also use the{' '}
+ <code {...stylex.props(proseStyles?.code)}>
+ useXDSFontWrapperStyles
+ </code>{' '}
+ hook to access theme styles programmatically for StyleX-based styling:
+ </p>
+
+ <h2 {...stylex.props(headingStyles?.h2)}>Styled with StyleX</h2>
+ <p {...stylex.props(proseStyles?.p)}>
+ This approach gives you more control and type safety, but requires
+ applying styles to each element individually.
+ </p>
+
+ <pre {...stylex.props(proseStyles?.pre)}>
+ <code
+ {...stylex.props(
+ proseStyles?.preCode,
+ )}>{`import { useFontWrapperStyles } from '@xds/core';
+import * as stylex from '@stylexjs/stylex';
+
+function Article() {
+ const { headingStyles, proseStyles } = useXDSFontWrapperStyles();
+
+ return (
+ <article>
+ <h1 {...stylex.props(headingStyles?.h1)}>Title</h1>
+ <p {...stylex.props(proseStyles?.p)}>Content...</p>
+ </article>
+ );
+}`}</code>
+ </pre>
+ </XDSFontWrapper>
+ );
+}
+
+export const StyleXApproach: Story = {
+ render: () => <StyleXApproachDemo />,
+};
diff --git a/apps/storybook/stories/Heading.stories.tsx b/apps/storybook/stories/Heading.stories.tsx
new file mode 100644
index 0000000000..c1ed730182
--- /dev/null
+++ b/apps/storybook/stories/Heading.stories.tsx
@@ -0,0 +1,635 @@
+import type {Meta, StoryObj} from '@storybook/react';
+import {XDSHeading} from '@xds/core/Text';
+import {XDSText} from '@xds/core/Text';
+
+const meta: Meta<typeof XDSHeading> = {
+ title: 'Typography/XDSHeading',
+ component: XDSHeading,
+ tags: ['autodocs'],
+ argTypes: {
+ level: {
+ control: 'select',
+ options: [1, 2, 3, 4, 5, 6],
+ description: 'Visual heading level (1-6)',
+ },
+ variant: {
+ control: 'select',
+ options: ['default', 'editorial'],
+ description: 'Heading scale variant',
+ },
+ color: {
+ control: 'select',
+ options: [
+ 'primary',
+ 'secondary',
+ 'disabled',
+ 'placeholder',
+ 'active',
+ 'inherit',
+ ],
+ description: 'Text color',
+ },
+ display: {
+ control: 'select',
+ options: ['inline', 'block'],
+ description: 'Display mode',
+ },
+ maxLines: {
+ control: 'number',
+ description: 'Maximum lines before truncation (0 = no truncation)',
+ },
+ textWrap: {
+ control: 'select',
+ options: ['wrap', 'nowrap', 'balance', 'pretty'],
+ description: 'Text wrapping behavior',
+ },
+ wordBreak: {
+ control: 'select',
+ options: ['break-word', 'break-all'],
+ description: 'Word break behavior',
+ },
+ hasStrikethrough: {
+ control: 'boolean',
+ description: 'Apply strikethrough decoration',
+ },
+ hasCapsize: {
+ control: 'boolean',
+ description: 'Enable optical alignment (text-box-trim)',
+ },
+ accessibilityLevel: {
+ control: 'select',
+ options: [1, 2, 3, 4, 5, 6],
+ description: 'Semantic level for accessibility (aria-level)',
+ },
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof XDSHeading>;
+
+// =============================================================================
+// Heading Levels - Default Variant
+// =============================================================================
+
+export const Level1: Story = {
+ args: {
+ level: 1,
+ children: 'Heading Level 1 (20px)',
+ },
+};
+
+export const Level2: Story = {
+ args: {
+ level: 2,
+ children: 'Heading Level 2 (18px)',
+ },
+};
+
+export const Level3: Story = {
+ args: {
+ level: 3,
+ children: 'Heading Level 3 (16px)',
+ },
+};
+
+export const Level4: Story = {
+ args: {
+ level: 4,
+ children: 'Heading Level 4 (14px)',
+ },
+};
+
+export const Level5: Story = {
+ args: {
+ level: 5,
+ children: 'Heading Level 5 (14px)',
+ },
+};
+
+export const Level6: Story = {
+ args: {
+ level: 6,
+ children: 'Heading Level 6 (12px)',
+ },
+};
+
+// =============================================================================
+// All Levels Overview
+// =============================================================================
+
+export const AllLevels: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
+ <div>
+ <XDSText type="label" display="block">
+ Default Variant (Internal Tools):
+ </XDSText>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '8px',
+ marginTop: '8px',
+ }}>
+ <XDSHeading level={1}>Heading 1 - 20px</XDSHeading>
+ <XDSHeading level={2}>Heading 2 - 18px</XDSHeading>
+ <XDSHeading level={3}>Heading 3 - 16px</XDSHeading>
+ <XDSHeading level={4}>Heading 4 - 14px</XDSHeading>
+ <XDSHeading level={5}>Heading 5 - 14px</XDSHeading>
+ <XDSHeading level={6}>Heading 6 - 12px</XDSHeading>
+ </div>
+ </div>
+ <div style={{marginTop: '24px'}}>
+ <XDSText type="label" display="block">
+ Editorial Variant (Content-Heavy Pages):
+ </XDSText>
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '8px',
+ marginTop: '8px',
+ }}>
+ <XDSHeading level={1} variant="editorial">
+ Heading 1 - 32px
+ </XDSHeading>
+ <XDSHeading level={2} variant="editorial">
+ Heading 2 - 24px
+ </XDSHeading>
+ <XDSHeading level={3} variant="editorial">
+ Heading 3 - 20px
+ </XDSHeading>
+ <XDSHeading level={4} variant="editorial">
+ Heading 4 - 16px
+ </XDSHeading>
+ <XDSHeading level={5} variant="editorial">
+ Heading 5 - 14px
+ </XDSHeading>
+ <XDSHeading level={6} variant="editorial">
+ Heading 6 - 12px
+ </XDSHeading>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Variants
+// =============================================================================
+
+export const DefaultVariant: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <XDSText type="supporting" display="block">
+ Default variant uses a denser scale suitable for internal tools and
+ dashboards
+ </XDSText>
+ <XDSHeading level={1}>Page Title (20px)</XDSHeading>
+ <XDSHeading level={2}>Section Title (18px)</XDSHeading>
+ <XDSHeading level={3}>Subsection Title (16px)</XDSHeading>
+ </div>
+ ),
+};
+
+export const EditorialVariant: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <XDSText type="supporting" display="block">
+ Editorial variant uses a larger scale for content-heavy pages like
+ articles
+ </XDSText>
+ <XDSHeading level={1} variant="editorial">
+ Article Title (32px)
+ </XDSHeading>
+ <XDSHeading level={2} variant="editorial">
+ Section Title (24px)
+ </XDSHeading>
+ <XDSHeading level={3} variant="editorial">
+ Subsection Title (20px)
+ </XDSHeading>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Color Variants
+// =============================================================================
+
+export const ColorVariants: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '12px'}}>
+ <XDSHeading level={2} color="primary">
+ Primary heading (default)
+ </XDSHeading>
+ <XDSHeading level={2} color="secondary">
+ Secondary heading
+ </XDSHeading>
+ <XDSHeading level={2} color="disabled">
+ Disabled heading
+ </XDSHeading>
+ <XDSHeading level={2} color="placeholder">
+ Placeholder heading
+ </XDSHeading>
+ <XDSHeading level={2} color="active">
+ Active heading (accent)
+ </XDSHeading>
+ <div style={{color: 'purple'}}>
+ <XDSHeading level={2} color="inherit">
+ Inherit heading (from parent)
+ </XDSHeading>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Display Modes
+// =============================================================================
+
+export const DisplayModes: Story = {
+ render: () => (
+ <div>
+ <div style={{marginBottom: '16px'}}>
+ <XDSHeading level={3} display="inline">
+ Inline H3{' '}
+ </XDSHeading>
+ <XDSHeading level={3} display="inline">
+ flows together{' '}
+ </XDSHeading>
+ <XDSHeading level={3} display="inline">
+ on the same line
+ </XDSHeading>
+ </div>
+ <div>
+ <XDSHeading level={3} display="block">
+ Block H3 (default)
+ </XDSHeading>
+ <XDSHeading level={3} display="block">
+ Each heading on its own line
+ </XDSHeading>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Truncation
+// =============================================================================
+
+export const SingleLineTruncation: Story = {
+ render: () => (
+ <div style={{width: '300px', border: '1px solid #ccc', padding: '12px'}}>
+ <XDSHeading level={2} maxLines={1}>
+ Very Long Heading That Will Be Truncated To One Line With Ellipsis
+ </XDSHeading>
+ </div>
+ ),
+};
+
+export const MultiLineTruncation: Story = {
+ render: () => (
+ <div style={{width: '300px', border: '1px solid #ccc', padding: '12px'}}>
+ <XDSHeading level={2} maxLines={2}>
+ Very Long Heading That Will Be Truncated To Two Lines To Keep Card
+ Layout Compact
+ </XDSHeading>
+ </div>
+ ),
+};
+
+export const TruncationWithoutTooltip: Story = {
+ render: () => (
+ <div style={{width: '300px', border: '1px solid #ccc', padding: '12px'}}>
+ <XDSHeading level={2} maxLines={1} truncateTooltip={false}>
+ Truncated Heading Without Tooltip On Hover
+ </XDSHeading>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Accessibility Level Override
+// =============================================================================
+
+export const AccessibilityLevel: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
+ <div>
+ <XDSText type="supporting" display="block">
+ Normal heading: visual and semantic levels match
+ </XDSText>
+ <XDSHeading level={2}>Section Title (h2, aria-level=2)</XDSHeading>
+ </div>
+ <div style={{marginTop: '16px'}}>
+ <XDSText type="supporting" display="block">
+ Sidebar heading: visual h2 but semantic h3 (doesn't affect main
+ outline)
+ </XDSText>
+ <XDSHeading level={2} accessibilityLevel={3}>
+ Sidebar Section (looks like h2, aria-level=3)
+ </XDSHeading>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Text Wrap
+// =============================================================================
+
+export const TextWrapVariants: Story = {
+ render: () => (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '16px',
+ maxWidth: '300px',
+ }}>
+ <div>
+ <XDSText type="label" display="block">
+ wrap (default):
+ </XDSText>
+ <XDSHeading level={2} textWrap="wrap">
+ This Heading Wraps Normally At Word Boundaries
+ </XDSHeading>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ balance:
+ </XDSText>
+ <XDSHeading level={2} textWrap="balance">
+ This Heading Is Balanced For Better Visual Appearance
+ </XDSHeading>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ pretty:
+ </XDSText>
+ <XDSHeading level={2} textWrap="pretty">
+ This Heading Uses Pretty Wrap To Avoid Orphans
+ </XDSHeading>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Word Break
+// =============================================================================
+
+export const WordBreakVariants: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: '16px'}}>
+ <div style={{flex: 1, maxWidth: '200px'}}>
+ <XDSText type="label" display="block">
+ break-word:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px'}}>
+ <XDSHeading level={3} maxLines={2} wordBreak="break-word">
+ Supercalifragilisticexpialidocious
+ </XDSHeading>
+ </div>
+ </div>
+ <div style={{flex: 1, maxWidth: '200px'}}>
+ <XDSText type="label" display="block">
+ break-all:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px'}}>
+ <XDSHeading level={3} maxLines={2} wordBreak="break-all">
+ Supercalifragilisticexpialidocious
+ </XDSHeading>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Decorations
+// =============================================================================
+
+export const Strikethrough: Story = {
+ args: {
+ level: 2,
+ hasStrikethrough: true,
+ children: 'Deprecated Section',
+ },
+};
+
+export const Capsize: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
+ <div>
+ <XDSText type="label" display="block">
+ Without capsize (red border shows extra space):
+ </XDSText>
+ <div style={{border: '1px solid red', display: 'inline-block'}}>
+ <XDSHeading level={1}>Regular Heading</XDSHeading>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ With capsize (optically aligned):
+ </XDSText>
+ <div style={{border: '1px solid red', display: 'inline-block'}}>
+ <XDSHeading level={1} hasCapsize>
+ Capsize Heading
+ </XDSHeading>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Real-World Examples
+// =============================================================================
+
+export const PageLayout: Story = {
+ render: () => (
+ <div style={{maxWidth: '800px'}}>
+ <XDSHeading level={1}>Dashboard Overview</XDSHeading>
+ <XDSText type="supporting" display="block">
+ Last updated 5 minutes ago
+ </XDSText>
+
+ <div style={{marginTop: '32px'}}>
+ <XDSHeading level={2}>Recent Activity</XDSHeading>
+ <XDSText type="body" display="block">
+ Here's what's been happening in your workspace.
+ </XDSText>
+ </div>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSHeading level={3}>Today</XDSHeading>
+ <XDSText type="body" display="block">
+ • Project Alpha updated
+ <br />
+ • 3 new comments
+ <br />• Task completed
+ </XDSText>
+ </div>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSHeading level={3}>Yesterday</XDSHeading>
+ <XDSText type="body" display="block">
+ • Meeting scheduled
+ <br />
+ • Document shared
+ <br />• Status update posted
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
+
+export const CardGrid: Story = {
+ render: () => (
+ <div
+ style={{
+ display: 'grid',
+ gridTemplateColumns: 'repeat(auto-fill, minmax(250px, 1fr))',
+ gap: '16px',
+ maxWidth: '800px',
+ }}>
+ {[1, 2, 3].map(i => (
+ <div
+ key={i}
+ style={{
+ padding: '16px',
+ borderRadius: '8px',
+ border: '1px solid #e0e0e0',
+ boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
+ }}>
+ <XDSHeading level={3} maxLines={1}>
+ {i === 1 && 'Very Long Card Title That Gets Truncated'}
+ {i === 2 && 'Another Card'}
+ {i === 3 &&
+ 'Third Card With An Even Longer Title That Will Be Truncated'}
+ </XDSHeading>
+ <XDSText type="body" maxLines={2} display="block">
+ This is a card description that might be quite long and needs to be
+ truncated after two lines to keep the card compact and uniform.
+ </XDSText>
+ <XDSText type="supporting" display="block">
+ Updated {i} hour{i > 1 ? 's' : ''} ago
+ </XDSText>
+ </div>
+ ))}
+ </div>
+ ),
+};
+
+export const ArticleLayout: Story = {
+ render: () => (
+ <div style={{maxWidth: '600px'}}>
+ <XDSHeading level={1} variant="editorial">
+ The Future of Design Systems
+ </XDSHeading>
+ <XDSText type="supporting" display="block">
+ Published on January 28, 2026 by Jane Doe
+ </XDSText>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSText type="large" display="block">
+ Design systems are evolving rapidly, and understanding these changes
+ is crucial for modern product development.
+ </XDSText>
+ </div>
+
+ <div style={{marginTop: '32px'}}>
+ <XDSHeading level={2} variant="editorial">
+ Introduction
+ </XDSHeading>
+ <XDSText type="body" display="block">
+ In this article, we'll explore the key trends shaping design systems
+ in 2026 and beyond.
+ </XDSText>
+ </div>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSHeading level={3} variant="editorial">
+ Component Architecture
+ </XDSHeading>
+ <XDSText type="body" display="block">
+ Modern component architecture prioritizes flexibility and consistency.
+ </XDSText>
+ </div>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSHeading level={3} variant="editorial">
+ Token-Based Theming
+ </XDSHeading>
+ <XDSText type="body" display="block">
+ Design tokens enable scalable theming across platforms and products.
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
+
+export const SidebarLayout: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: '24px', maxWidth: '800px'}}>
+ <div style={{flex: 1}}>
+ <XDSHeading level={1}>Main Content</XDSHeading>
+ <XDSText type="body" display="block">
+ This is the main page content with a proper document outline.
+ </XDSText>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSHeading level={2}>Section 1</XDSHeading>
+ <XDSText type="body" display="block">
+ Content for section 1.
+ </XDSText>
+ </div>
+
+ <div style={{marginTop: '24px'}}>
+ <XDSHeading level={2}>Section 2</XDSHeading>
+ <XDSText type="body" display="block">
+ Content for section 2.
+ </XDSText>
+ </div>
+ </div>
+
+ <div
+ style={{
+ width: '200px',
+ padding: '16px',
+ backgroundColor: '#f5f5f5',
+ borderRadius: '8px',
+ }}>
+ <XDSHeading level={2} accessibilityLevel={3}>
+ Sidebar Info
+ </XDSHeading>
+ <XDSText type="supporting" display="block">
+ This heading looks like H2 but is semantically H3 so it doesn't
+ disrupt the main content outline.
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
+
+export const ErrorState: Story = {
+ render: () => (
+ <div
+ style={{
+ padding: '24px',
+ borderRadius: '8px',
+ backgroundColor: '#fff5f5',
+ border: '1px solid #feb2b2',
+ maxWidth: '400px',
+ }}>
+ <XDSHeading level={2} color="active">
+ Error: Connection Failed
+ </XDSHeading>
+ <XDSText type="body" display="block">
+ We couldn't connect to the server. Please check your internet connection
+ and try again.
+ </XDSText>
+ </div>
+ ),
+};
diff --git a/apps/storybook/stories/Text.stories.tsx b/apps/storybook/stories/Text.stories.tsx
new file mode 100644
index 0000000000..d6a9d3edf6
--- /dev/null
+++ b/apps/storybook/stories/Text.stories.tsx
@@ -0,0 +1,587 @@
+import type {Meta, StoryObj} from '@storybook/react';
+import {XDSText} from '@xds/core/Text';
+
+const meta: Meta<typeof XDSText> = {
+ title: 'Typography/XDSText',
+ component: XDSText,
+ tags: ['autodocs'],
+ argTypes: {
+ type: {
+ control: 'select',
+ options: ['body', 'large', 'label', 'supporting', 'code'],
+ description: 'Semantic text type',
+ },
+ color: {
+ control: 'select',
+ options: [
+ 'primary',
+ 'secondary',
+ 'disabled',
+ 'placeholder',
+ 'active',
+ 'inherit',
+ ],
+ description: 'Text color',
+ },
+ weight: {
+ control: 'select',
+ options: ['normal', 'medium', 'semibold', 'bold'],
+ description: 'Font weight override',
+ },
+ display: {
+ control: 'select',
+ options: ['inline', 'block'],
+ description: 'Display mode',
+ },
+ maxLines: {
+ control: 'number',
+ description: 'Maximum lines before truncation (0 = no truncation)',
+ },
+ textWrap: {
+ control: 'select',
+ options: ['wrap', 'nowrap', 'balance', 'pretty'],
+ description: 'Text wrapping behavior',
+ },
+ wordBreak: {
+ control: 'select',
+ options: ['break-word', 'break-all'],
+ description: 'Word break behavior',
+ },
+ hasStrikethrough: {
+ control: 'boolean',
+ description: 'Apply strikethrough decoration',
+ },
+ hasTabularNumbers: {
+ control: 'boolean',
+ description: 'Use tabular (monospace) numbers',
+ },
+ hasCapsize: {
+ control: 'boolean',
+ description: 'Enable optical alignment (text-box-trim)',
+ },
+ as: {
+ control: 'select',
+ options: ['span', 'p', 'div', 'label'],
+ description: 'HTML element to render',
+ },
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof XDSText>;
+
+// =============================================================================
+// Basic Types
+// =============================================================================
+
+export const Body: Story = {
+ args: {
+ type: 'body',
+ children: 'Body text - the bulk of content (14px)',
+ },
+};
+
+export const Large: Story = {
+ args: {
+ type: 'large',
+ children: 'Large text - emphasized content, quotes, descriptions (16px)',
+ },
+};
+
+export const Label: Story = {
+ args: {
+ type: 'label',
+ children: 'Label text - form/chart/table labels (14px medium)',
+ },
+};
+
+export const Supporting: Story = {
+ args: {
+ type: 'supporting',
+ children:
+ 'Supporting text - helper text, supplemental info (12px, secondary color)',
+ },
+};
+
+export const Code: Story = {
+ args: {
+ type: 'code',
+ children: 'const x = 1; // Inline code (14px monospace)',
+ },
+};
+
+// =============================================================================
+// All Types Overview
+// =============================================================================
+
+export const AllTypes: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '12px'}}>
+ <XDSText type="body">Body: The bulk of content (14px)</XDSText>
+ <XDSText type="large">Large: Emphasized content (16px)</XDSText>
+ <XDSText type="label">Label: Form/chart labels (14px medium)</XDSText>
+ <XDSText type="supporting">
+ Supporting: Helper text (12px secondary)
+ </XDSText>
+ <XDSText type="code">Code: const x = 1; (14px monospace)</XDSText>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Color Variants
+// =============================================================================
+
+export const ColorVariants: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <XDSText type="body" color="primary">
+ Primary color (default for body)
+ </XDSText>
+ <XDSText type="body" color="secondary">
+ Secondary color
+ </XDSText>
+ <XDSText type="body" color="disabled">
+ Disabled color
+ </XDSText>
+ <XDSText type="body" color="placeholder">
+ Placeholder color
+ </XDSText>
+ <XDSText type="body" color="active">
+ Active color (accent)
+ </XDSText>
+ <div style={{color: 'purple'}}>
+ <XDSText type="body" color="inherit">
+ Inherit color (from parent)
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Weight Variants
+// =============================================================================
+
+export const WeightVariants: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <XDSText type="body" weight="normal">
+ Normal weight (400)
+ </XDSText>
+ <XDSText type="body" weight="medium">
+ Medium weight (500)
+ </XDSText>
+ <XDSText type="body" weight="semibold">
+ Semibold weight (600)
+ </XDSText>
+ <XDSText type="body" weight="bold">
+ Bold weight (700)
+ </XDSText>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Display Modes
+// =============================================================================
+
+export const DisplayModes: Story = {
+ render: () => (
+ <div>
+ <div style={{marginBottom: '16px'}}>
+ <XDSText type="body" display="inline">
+ Inline text{' '}
+ </XDSText>
+ <XDSText type="body" display="inline">
+ flows together{' '}
+ </XDSText>
+ <XDSText type="body" display="inline">
+ on the same line.
+ </XDSText>
+ </div>
+ <div>
+ <XDSText type="body" display="block">
+ Block text takes its own line.
+ </XDSText>
+ <XDSText type="body" display="block">
+ Each block is on a separate line.
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Truncation
+// =============================================================================
+
+export const SingleLineTruncation: Story = {
+ render: () => (
+ <div style={{width: '300px', border: '1px solid #ccc', padding: '12px'}}>
+ <XDSText type="body" maxLines={1}>
+ This is a very long text that will be truncated to a single line. Hover
+ over it to see the full content in a tooltip.
+ </XDSText>
+ </div>
+ ),
+};
+
+export const MultiLineTruncation: Story = {
+ render: () => (
+ <div style={{width: '300px', border: '1px solid #ccc', padding: '12px'}}>
+ <XDSText type="body" maxLines={2}>
+ This is a very long text that will be truncated to exactly two lines.
+ When you hover over it, a tooltip will appear showing the full text
+ content. This is useful for displaying preview text in cards and lists.
+ </XDSText>
+ </div>
+ ),
+};
+
+export const TruncationWithoutTooltip: Story = {
+ render: () => (
+ <div style={{width: '300px', border: '1px solid #ccc', padding: '12px'}}>
+ <XDSText type="body" maxLines={1} truncateTooltip={false}>
+ This text is truncated but has no tooltip on hover. Sometimes you don't
+ want a tooltip.
+ </XDSText>
+ </div>
+ ),
+};
+
+export const TruncationVariants: Story = {
+ render: () => (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '16px',
+ maxWidth: '300px',
+ }}>
+ <div>
+ <XDSText type="label" display="block">
+ 1 Line:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px'}}>
+ <XDSText type="body" maxLines={1}>
+ This is a very long text that will be truncated to one line with
+ ellipsis.
+ </XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ 2 Lines:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px'}}>
+ <XDSText type="body" maxLines={2}>
+ This is a very long text that will be truncated to two lines. The
+ second line will end with an ellipsis if the content is too long.
+ </XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ 3 Lines:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px'}}>
+ <XDSText type="body" maxLines={3}>
+ This is a very long text that will be truncated to three lines. It
+ allows for more content to be shown but still limits the vertical
+ space. The third line will end with an ellipsis.
+ </XDSText>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Word Break
+// =============================================================================
+
+export const WordBreakVariants: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: '16px', maxWidth: '600px'}}>
+ <div style={{flex: 1}}>
+ <XDSText type="label" display="block">
+ break-word (default for multi-line):
+ </XDSText>
+ <div style={{width: '150px', border: '1px solid #ccc', padding: '8px'}}>
+ <XDSText type="body" maxLines={2} wordBreak="break-word">
+ Thisisaverylongwordthatneedstobreakatwordlevel
+ </XDSText>
+ </div>
+ </div>
+ <div style={{flex: 1}}>
+ <XDSText type="label" display="block">
+ break-all (default for single-line):
+ </XDSText>
+ <div style={{width: '150px', border: '1px solid #ccc', padding: '8px'}}>
+ <XDSText type="body" maxLines={2} wordBreak="break-all">
+ Thisisaverylongwordthatneedstobreakatanylevel
+ </XDSText>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Text Wrap
+// =============================================================================
+
+export const TextWrapVariants: Story = {
+ render: () => (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '16px',
+ maxWidth: '400px',
+ }}>
+ <div>
+ <XDSText type="label" display="block">
+ wrap (default):
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px', width: '200px'}}>
+ <XDSText type="body" textWrap="wrap">
+ This text wraps normally at word boundaries when it reaches the
+ edge.
+ </XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ nowrap:
+ </XDSText>
+ <div
+ style={{
+ border: '1px solid #ccc',
+ padding: '8px',
+ width: '200px',
+ overflow: 'hidden',
+ }}>
+ <XDSText type="body" textWrap="nowrap">
+ This text does not wrap and will overflow its container.
+ </XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ balance:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px', width: '200px'}}>
+ <XDSText type="body" textWrap="balance">
+ This text is balanced for better visual appearance across lines.
+ </XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ pretty:
+ </XDSText>
+ <div style={{border: '1px solid #ccc', padding: '8px', width: '200px'}}>
+ <XDSText type="body" textWrap="pretty">
+ This text uses pretty wrap to avoid orphans at the end of
+ paragraphs.
+ </XDSText>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Decorations
+// =============================================================================
+
+export const Strikethrough: Story = {
+ args: {
+ type: 'body',
+ hasStrikethrough: true,
+ children: 'This text has a strikethrough decoration',
+ },
+};
+
+export const TabularNumbers: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <div>
+ <XDSText type="label" display="block">
+ Without tabular numbers:
+ </XDSText>
+ <div style={{display: 'flex', flexDirection: 'column'}}>
+ <XDSText type="body">1,234.56</XDSText>
+ <XDSText type="body">99,999.99</XDSText>
+ <XDSText type="body">111.11</XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ With tabular numbers:
+ </XDSText>
+ <div style={{display: 'flex', flexDirection: 'column'}}>
+ <XDSText type="body" hasTabularNumbers>
+ 1,234.56
+ </XDSText>
+ <XDSText type="body" hasTabularNumbers>
+ 99,999.99
+ </XDSText>
+ <XDSText type="body" hasTabularNumbers>
+ 111.11
+ </XDSText>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Capsize (Optical Alignment)
+// =============================================================================
+
+export const Capsize: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '16px'}}>
+ <div>
+ <XDSText type="label" display="block">
+ Without capsize (red border shows extra space):
+ </XDSText>
+ <div style={{border: '1px solid red', display: 'inline-block'}}>
+ <XDSText type="large">Regular text with line-height space</XDSText>
+ </div>
+ </div>
+ <div>
+ <XDSText type="label" display="block">
+ With capsize (optically aligned):
+ </XDSText>
+ <div style={{border: '1px solid red', display: 'inline-block'}}>
+ <XDSText type="large" hasCapsize>
+ Capsize removes extra space
+ </XDSText>
+ </div>
+ </div>
+ </div>
+ ),
+};
+
+// =============================================================================
+// As Different Elements
+// =============================================================================
+
+export const AsElements: Story = {
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <XDSText type="body" as="span">
+ As span (default, inline)
+ </XDSText>
+ <XDSText type="body" as="p">
+ As paragraph element
+ </XDSText>
+ <XDSText type="body" as="div">
+ As div element
+ </XDSText>
+ <XDSText type="body" as="label">
+ As label element
+ </XDSText>
+ </div>
+ ),
+};
+
+// =============================================================================
+// Real-World Examples
+// =============================================================================
+
+export const CardExample: Story = {
+ render: () => (
+ <div
+ style={{
+ maxWidth: '300px',
+ padding: '16px',
+ borderRadius: '8px',
+ border: '1px solid #e0e0e0',
+ boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
+ }}>
+ <XDSText type="label" display="block">
+ Product Name
+ </XDSText>
+ <XDSText type="body" maxLines={2} display="block">
+ This is a product description that might be quite long and needs to be
+ truncated after two lines to keep the card compact.
+ </XDSText>
+ <XDSText type="supporting" display="block">
+ Updated 5 minutes ago
+ </XDSText>
+ </div>
+ ),
+};
+
+export const MetricsExample: Story = {
+ render: () => (
+ <div style={{display: 'flex', gap: '24px'}}>
+ <div style={{textAlign: 'center'}}>
+ <XDSText type="body" color="secondary" display="block">
+ Revenue
+ </XDSText>
+ <XDSText type="large" weight="bold" hasTabularNumbers>
+ $1,234,567.89
+ </XDSText>
+ </div>
+ <div style={{textAlign: 'center'}}>
+ <XDSText type="body" color="secondary" display="block">
+ Users
+ </XDSText>
+ <XDSText type="large" weight="bold" hasTabularNumbers>
+ 12,345
+ </XDSText>
+ </div>
+ <div style={{textAlign: 'center'}}>
+ <XDSText type="body" color="secondary" display="block">
+ Conversion
+ </XDSText>
+ <XDSText type="large" weight="bold" color="active" hasTabularNumbers>
+ 23.4%
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
+
+export const FormExample: Story = {
+ render: () => (
+ <div
+ style={{
+ maxWidth: '300px',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: '16px',
+ }}>
+ <div>
+ <XDSText type="label" as="label" display="block">
+ Email address
+ </XDSText>
+ <input
+ type="email"
+ style={{width: '100%', padding: '8px', marginTop: '4px'}}
+ />
+ <XDSText type="supporting" display="block">
+ We'll never share your email.
+ </XDSText>
+ </div>
+ <div>
+ <XDSText type="label" as="label" display="block">
+ Password
+ </XDSText>
+ <input
+ type="password"
+ style={{width: '100%', padding: '8px', marginTop: '4px'}}
+ />
+ <XDSText type="supporting" color="active" display="block">
+ Must be at least 8 characters.
+ </XDSText>
+ </div>
+ </div>
+ ),
+};
diff --git a/packages/core/README.md b/packages/core/README.md
index 745208e91d..07a20e0cb4 100644
--- a/packages/core/README.md
+++ b/packages/core/README.md
@@ -10,3 +10,26 @@ Core UI components library for the XDS design system (`@xds/core`).
| `package.json` | Config | Package configuration and dependencies |
| `tsconfig.json` | Config | TypeScript compiler configuration |
| `tsup.config.ts` | Build | Bundle configuration using tsup |
+
+## Key Exports
+
+### Components
+
+- **Typography**: `XDSText`, `XDSHeading`, `XDSFontWrapper`
+- **Inputs**: `XDSButton`, `XDSTextInput`, `XDSTextArea`, `XDSCheckboxInput`
+- **Layout**: `XDSHStack`, `XDSVStack`, `XDSCard`, `XDSSection`
+- **Feedback**: `XDSTooltip`, `XDSHoverCard`
+
+### Theme
+
+- `Theme` — Provider component that sets CSS custom properties
+- `defaultTheme`, `neutralTheme` — Pre-built themes
+- `useTheme` — Hook to access current theme
+
+### Stylesheets
+
+- `@xds/core/typography.css` — Base typography styles for native HTML elements (h1-h6, p, lists, blockquotes, code, etc.). Uses CSS custom properties from the theme.
+
+## Usage
+
+See the [Getting Started guide](/README.md#getting-started) in the root README.
diff --git a/packages/core/package.json b/packages/core/package.json
index e43067cbca..5fa7251907 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -9,7 +9,8 @@
"**/*.stylex.ts",
"**/*.stylex.js",
"**/*.stylex.mjs",
- "**/componentStyles.ts"
+ "**/componentStyles.ts",
+ "**/*.css"
],
"exports": {
".": {
@@ -17,6 +18,7 @@
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
+ "./typography.css": "./src/typography.css",
"./Avatar": {
"types": "./dist/Avatar/index.d.ts",
"import": "./dist/Avatar/index.mjs",
@@ -52,6 +54,11 @@
"import": "./dist/Skeleton/index.mjs",
"require": "./dist/Skeleton/index.js"
},
+ "./Text": {
+ "types": "./dist/Text/index.d.ts",
+ "import": "./dist/Text/index.mjs",
+ "require": "./dist/Text/index.js"
+ },
"./TextInput": {
"types": "./dist/TextInput/index.d.ts",
"import": "./dist/TextInput/index.mjs",
diff --git a/packages/core/src/Layer/useXDSTooltip.tsx b/packages/core/src/Layer/useXDSTooltip.tsx
index f34337c983..bd3ea77e1e 100644
--- a/packages/core/src/Layer/useXDSTooltip.tsx
+++ b/packages/core/src/Layer/useXDSTooltip.tsx
@@ -83,6 +83,8 @@ const styles = stylex.create({
paddingBlockEnd: spacingVars['--spacing-1'],
paddingInlineStart: spacingVars['--spacing-2'],
paddingInlineEnd: spacingVars['--spacing-2'],
+ maxWidth: 300,
+ wordBreak: 'break-word',
},
});
diff --git a/packages/core/src/Text/README.md b/packages/core/src/Text/README.md
new file mode 100644
index 0000000000..b1379c1a06
--- /dev/null
+++ b/packages/core/src/Text/README.md
@@ -0,0 +1,68 @@
+# /packages/core/src/Text
+
+Typography components for the XDS design system.
+
+<!-- SYNC: When files in this directory change, update this document. -->
+
+## Components
+
+| File | Export | Purpose |
+| -------------------- | ------------------------- | ---------------------------------------------------------- |
+| `XDSText.tsx` | `XDSText` | Body text with semantic variants (body, supporting, label) |
+| `XDSHeading.tsx` | `XDSHeading` | Headings with level and size props |
+| `XDSFontWrapper.tsx` | `XDSFontWrapper` | Wrapper that applies typography styles to native HTML |
+| `XDSFontWrapper.tsx` | `useXDSFontWrapperStyles` | Hook for programmatic StyleX access to typography styles |
+
+## Utilities
+
+| File | Export | Purpose |
+| ------------------ | --------------- | ---------------------------------------------------------- |
+| `text.stylex.ts` | Various | StyleX styles for color, weight, display, truncation, etc. |
+| `useTruncation.ts` | `useTruncation` | Hook for detecting text overflow |
+
+## Usage Patterns
+
+### XDSText / XDSHeading
+
+Use for explicit typography control with full type safety:
+
+```tsx
+<XDSHeading level={1} size="2xl">Page Title</XDSHeading>
+<XDSText type="body" color="primary">Body text content.</XDSText>
+<XDSText type="supporting" color="secondary">Helper text.</XDSText>
+```
+
+### XDSFontWrapper
+
+Use when rendering user content or markdown where you can't control the elements:
+
+```tsx
+<XDSFontWrapper variant="editorial">
+ <article dangerouslySetInnerHTML={{__html: markdownContent}} />
+</XDSFontWrapper>
+```
+
+### useXDSFontWrapperStyles
+
+Use when you want StyleX-based styling with theme tokens:
+
+```tsx
+import {useXDSFontWrapperStyles} from '@xds/core';
+import * as stylex from '@stylexjs/stylex';
+
+function Article() {
+ const {headingStyles, proseStyles} = useXDSFontWrapperStyles();
+
+ return (
+ <article>
+ <h1 {...stylex.props(headingStyles?.h1)}>Title</h1>
+ <p {...stylex.props(proseStyles?.p)}>Content...</p>
+ </article>
+ );
+}
+```
+
+## Related Files
+
+- `/packages/core/src/typography.css` — CSS stylesheet for native element styling
+- `/packages/core/src/theme/types.ts` — Type definitions for `ProseElement` and component styles
diff --git a/packages/core/src/Text/XDSFontWrapper.test.tsx b/packages/core/src/Text/XDSFontWrapper.test.tsx
new file mode 100644
index 0000000000..721b3e5a5c
--- /dev/null
+++ b/packages/core/src/Text/XDSFontWrapper.test.tsx
@@ -0,0 +1,94 @@
+/**
+ * @file XDSFontWrapper.test.tsx
+ * @input Uses Vitest, React Testing Library
+ * @output Tests for XDSFontWrapper component
+ */
+
+import {describe, it, expect} from 'vitest';
+import {render, screen} from '@testing-library/react';
+import {XDSFontWrapper} from './XDSFontWrapper';
+import {Theme} from '../theme/Theme';
+import {defaultTheme} from '../theme/defaultTheme.stylex';
+
+// Helper to wrap with theme
+function renderWithTheme(ui: React.ReactElement) {
+ return render(<Theme theme={defaultTheme}>{ui}</Theme>);
+}
+
+describe('XDSFontWrapper', () => {
+ it('renders children', () => {
+ renderWithTheme(
+ <XDSFontWrapper>
+ <h1>Test Heading</h1>
+ <p>Test paragraph</p>
+ </XDSFontWrapper>,
+ );
+
+ expect(screen.getByText('Test Heading')).toBeInTheDocument();
+ expect(screen.getByText('Test paragraph')).toBeInTheDocument();
+ });
+
+ it('applies default variant classes', () => {
+ renderWithTheme(
+ <XDSFontWrapper data-testid="wrapper">
+ <p>Content</p>
+ </XDSFontWrapper>,
+ );
+
+ const wrapper = screen.getByTestId('wrapper');
+ expect(wrapper).toBeInTheDocument();
+ expect(wrapper).toHaveClass('xds-typography');
+ expect(wrapper).toHaveClass('xds-typography--default');
+ });
+
+ it('applies editorial variant classes', () => {
+ renderWithTheme(
+ <XDSFontWrapper variant="editorial" data-testid="wrapper">
+ <p>Content</p>
+ </XDSFontWrapper>,
+ );
+
+ const wrapper = screen.getByTestId('wrapper');
+ expect(wrapper).toBeInTheDocument();
+ expect(wrapper).toHaveClass('xds-typography');
+ expect(wrapper).toHaveClass('xds-typography--editorial');
+ });
+
+ it('renders all prose elements', () => {
+ renderWithTheme(
+ <XDSFontWrapper>
+ <h1>Heading 1</h1>
+ <h2>Heading 2</h2>
+ <h3>Heading 3</h3>
+ <h4>Heading 4</h4>
+ <h5>Heading 5</h5>
+ <h6>Heading 6</h6>
+ <p>Paragraph</p>
+ <ul>
+ <li>List item</li>
+ </ul>
+ <ol>
+ <li>Ordered item</li>
+ </ol>
+ <blockquote>Quote</blockquote>
+ <pre>
+ <code>code block</code>
+ </pre>
+ <hr />
+ </XDSFontWrapper>,
+ );
+
+ expect(screen.getByRole('heading', {level: 1})).toBeInTheDocument();
+ expect(screen.getByRole('heading', {level: 2})).toBeInTheDocument();
+ expect(screen.getByRole('heading', {level: 3})).toBeInTheDocument();
+ expect(screen.getByRole('heading', {level: 4})).toBeInTheDocument();
+ expect(screen.getByRole('heading', {level: 5})).toBeInTheDocument();
+ expect(screen.getByRole('heading', {level: 6})).toBeInTheDocument();
+ expect(screen.getByText('Paragraph')).toBeInTheDocument();
+ expect(screen.getByText('List item')).toBeInTheDocument();
+ expect(screen.getByText('Ordered item')).toBeInTheDocument();
+ expect(screen.getByText('Quote')).toBeInTheDocument();
+ expect(screen.getByText('code block')).toBeInTheDocument();
+ expect(screen.getByRole('separator')).toBeInTheDocument();
+ });
+});
diff --git a/packages/core/src/Text/XDSFontWrapper.tsx b/packages/core/src/Text/XDSFontWrapper.tsx
new file mode 100644
index 0000000000..8e5cd85491
--- /dev/null
+++ b/packages/core/src/Text/XDSFontWrapper.tsx
@@ -0,0 +1,123 @@
+/**
+ * @file XDSFontWrapper.tsx
+ * @input Uses React, StyleX, Theme, reset.css
+ * @output Exports XDSFontWrapper component
+ * @position Typography component; provides base styles for wrapped content
+ *
+ * SYNC: When modified, update:
+ * - /packages/core/src/Text/README.md
+ * - /packages/core/src/Text/index.ts
+ */
+
+import * as React from 'react';
+import * as stylex from '@stylexjs/stylex';
+import {useTheme} from '../theme/Theme';
+import '../typography.css';
+
+/**
+ * Heading scale variant
+ */
+export type XDSFontWrapperVariant = 'default' | 'editorial';
+
+/**
+ * Props for XDSFontWrapper
+ */
+export interface XDSFontWrapperProps {
+ /**
+ * Heading scale variant
+ * - 'default': Dense scale for internal tools (h1: 20px)
+ * - 'editorial': Larger scale for content-heavy pages (h1: 32px)
+ * @default 'default'
+ */
+ variant?: XDSFontWrapperVariant;
+
+ /**
+ * Children to render
+ */
+ children: React.ReactNode;
+
+ /**
+ * Test ID for testing
+ */
+ 'data-testid'?: string;
+}
+
+/**
+ * XDSFontWrapper
+ *
+ * Applies base typography styles to native HTML elements within its scope.
+ * Uses the reset.css stylesheet which references theme CSS custom properties.
+ *
+ * @example
+ * // Default variant (dense scale)
+ * <XDSFontWrapper>
+ * <h1>Page Title</h1>
+ * <p>Body text with <strong>bold</strong> and <em>italic</em>.</p>
+ * <ul>
+ * <li>List item 1</li>
+ * <li>List item 2</li>
+ * </ul>
+ * </XDSFontWrapper>
+ *
+ * @example
+ * // Editorial variant (larger heading scale)
+ * <XDSFontWrapper variant="editorial">
+ * <h1>Article Title</h1>
+ * <p>Body text for long-form content.</p>
+ * </XDSFontWrapper>
+ *
+ * @example
+ * // For global usage, apply to body:
+ * // import '@xds/core/typography.css';
+ * // <body className="xds-typography">
+ */
+export function XDSFontWrapper({
+ variant = 'default',
+ children,
+ 'data-testid': testId,
+}: XDSFontWrapperProps): React.ReactElement {
+ const {theme} = useTheme();
+ const proseBase = theme.components?.prose?.base;
+
+ // Combine StyleX base styles with CSS typography class
+ const typographyClass =
+ variant === 'editorial'
+ ? 'xds-typography xds-typography--editorial'
+ : 'xds-typography xds-typography--default';
+
+ const stylexProps = stylex.props(proseBase);
+
+ return (
+ <div
+ className={`${typographyClass} ${stylexProps.className ?? ''}`.trim()}
+ style={stylexProps.style}
+ data-testid={testId}>
+ {children}
+ </div>
+ );
+}
+
+/**
+ * Hook to access font wrapper styles from the current theme.
+ * Use this for applying styles to native HTML elements programmatically.
+ *
+ * @example
+ * const { headingStyles, proseStyles } = useXDSFontWrapperStyles();
+ *
+ * <h1 {...stylex.props(headingStyles?.h1)}>Title</h1>
+ * <p {...stylex.props(proseStyles?.p)}>Paragraph</p>
+ */
+export function useXDSFontWrapperStyles() {
+ const {theme} = useTheme();
+
+ return {
+ /** Base wrapper styles */
+ base: theme.components?.prose?.base,
+ /** Default heading styles (h1-h6) */
+ headingStyles: theme.components?.heading?.styles,
+ /** Editorial heading styles (h1-h6, larger scale) */
+ editorialHeadingStyles: theme.components?.heading?.editorialStyles,
+ /** Prose element styles (p, ul, ol, li, blockquote, code, pre, hr, etc.) */
+ proseStyles: theme.components?.prose?.styles,
+ };
+}
diff --git a/packages/core/src/Text/XDSHeading.test.tsx b/packages/core/src/Text/XDSHeading.test.tsx
new file mode 100644
index 0000000000..2f6e580e47
--- /dev/null
+++ b/packages/core/src/Text/XDSHeading.test.tsx
@@ -0,0 +1,199 @@
+/**
+ * @file XDSHeading.test.tsx
+ * Tests for XDSHeading component
+ */
+
+import {render, screen} from '@testing-library/react';
+import {describe, it, expect} from 'vitest';
+import {XDSHeading} from './XDSHeading';
+import {Theme} from '../theme/Theme';
+import {defaultTheme} from '../theme/defaultTheme.stylex';
+
+describe('XDSHeading', () => {
+ describe('rendering', () => {
+ it('renders children correctly', () => {
+ render(<XDSHeading level={1}>Page Title</XDSHeading>);
+ expect(screen.getByText('Page Title')).toBeInTheDocument();
+ });
+
+ it('renders h1 for level 1', () => {
+ render(<XDSHeading level={1}>H1</XDSHeading>);
+ const element = screen.getByText('H1');
+ expect(element.tagName).toBe('H1');
+ });
+
+ it('renders h2 for level 2', () => {
+ render(<XDSHeading level={2}>H2</XDSHeading>);
+ const element = screen.getByText('H2');
+ expect(element.tagName).toBe('H2');
+ });
+
+ it('renders h3 for level 3', () => {
+ render(<XDSHeading level={3}>H3</XDSHeading>);
+ const element = screen.getByText('H3');
+ expect(element.tagName).toBe('H3');
+ });
+
+ it('renders h4 for level 4', () => {
+ render(<XDSHeading level={4}>H4</XDSHeading>);
+ const element = screen.getByText('H4');
+ expect(element.tagName).toBe('H4');
+ });
+
+ it('renders h5 for level 5', () => {
+ render(<XDSHeading level={5}>H5</XDSHeading>);
+ const element = screen.getByText('H5');
+ expect(element.tagName).toBe('H5');
+ });
+
+ it('renders h6 for level 6', () => {
+ render(<XDSHeading level={6}>H6</XDSHeading>);
+ const element = screen.getByText('H6');
+ expect(element.tagName).toBe('H6');
+ });
+ });
+
+ describe('variants', () => {
+ it('uses default variant by default', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1}>Default Heading</XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Default Heading')).toBeInTheDocument();
+ });
+
+ it('supports editorial variant', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} variant="editorial">
+ Editorial Heading
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Editorial Heading')).toBeInTheDocument();
+ });
+ });
+
+ describe('props', () => {
+ it('forwards additional props', () => {
+ render(
+ <XDSHeading level={1} data-testid="custom-heading">
+ Title
+ </XDSHeading>,
+ );
+ expect(screen.getByTestId('custom-heading')).toBeInTheDocument();
+ });
+
+ it('supports id', () => {
+ render(
+ <XDSHeading level={2} id="section-title">
+ Section
+ </XDSHeading>,
+ );
+ const element = screen.getByText('Section');
+ expect(element).toHaveAttribute('id', 'section-title');
+ });
+
+ it('accepts color prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} color="secondary">
+ Secondary heading
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Secondary heading')).toBeInTheDocument();
+ });
+
+ it('accepts display prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} display="inline">
+ Inline heading
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Inline heading')).toBeInTheDocument();
+ });
+
+ it('accepts hasStrikethrough prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} hasStrikethrough>
+ Strikethrough heading
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Strikethrough heading')).toBeInTheDocument();
+ });
+
+ it('accepts hasCapsize prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} hasCapsize>
+ Capsize heading
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Capsize heading')).toBeInTheDocument();
+ });
+
+ it('accepts textWrap prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} textWrap="balance">
+ Balanced heading
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Balanced heading')).toBeInTheDocument();
+ });
+
+ it('accepts maxLines prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} maxLines={1}>
+ Very long heading that should be truncated
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(
+ screen.getByText('Very long heading that should be truncated'),
+ ).toBeInTheDocument();
+ });
+
+ it('accepts wordBreak prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} maxLines={1} wordBreak="break-word">
+ Heading with word break
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('Heading with word break')).toBeInTheDocument();
+ });
+
+ it('accepts truncateTooltip=false to disable tooltip', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSHeading level={1} maxLines={1} truncateTooltip={false}>
+ No tooltip
+ </XDSHeading>
+ </Theme>,
+ );
+ expect(screen.getByText('No tooltip')).toBeInTheDocument();
+ });
+
+ it('accepts accessibilityLevel prop', () => {
+ render(
+ <XDSHeading level={2} accessibilityLevel={3}>
+ Sidebar Section
+ </XDSHeading>,
+ );
+ const element = screen.getByText('Sidebar Section');
+ expect(element).toHaveAttribute('aria-level', '3');
+ expect(element.tagName).toBe('H2');
+ });
+ });
+});
diff --git a/packages/core/src/Text/XDSHeading.tsx b/packages/core/src/Text/XDSHeading.tsx
new file mode 100644
index 0000000000..705dd77547
--- /dev/null
+++ b/packages/core/src/Text/XDSHeading.tsx
@@ -0,0 +1,302 @@
+/**
+ * @file XDSHeading.tsx
+ * @input Uses React forwardRef, HTMLAttributes, ReactNode
+ * @output Exports XDSHeading component, XDSHeadingProps, XDSHeadingLevel, XDSHeadingVariant types
+ * @position Core implementation; consumed by index.ts, tested by XDSHeading.test.tsx
+ *
+ * SYNC: When modified, update these files to stay in sync:
+ * - /packages/core/src/Text/README.md (props table, features, implementation notes)
+ * - /packages/core/src/Text/XDSHeading.test.tsx (tests for new/changed behavior)
+ * - /packages/core/src/Text/index.ts (exports if types change)
+ * - /apps/storybook/stories/Text.stories.tsx (storybook stories)
+ */
+
+import {forwardRef, useCallback, useContext, type ReactNode} from 'react';
+import * as stylex from '@stylexjs/stylex';
+import type {StyleXStyles} from '@stylexjs/stylex';
+import {ThemeContext} from '../theme/ThemeContext';
+import type {
+ HeadingLevel,
+ XDSTextColor,
+ XDSTextDisplay,
+ XDSWordBreak,
+ XDSTextWrap,
+} from '../theme/types';
+import {
+ colorStyles,
+ displayStyles,
+ truncationStyles,
+ wordBreakStyles,
+ textWrapStyles,
+ capsizeStyles,
+ decorationStyles,
+ truncationTooltipStyles,
+} from './text.stylex';
+import {useTruncation} from './useTruncation';
+import {useXDSTooltip, type LayerPlacement} from '../Layer';
+
+/**
+ * Heading level (1-6). Determines both visual styling and semantic HTML element.
+ */
+export type XDSHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
+
+/**
+ * Heading variant determines the size scale used
+ */
+export type XDSHeadingVariant = 'default' | 'editorial';
+
+export interface XDSHeadingProps {
+ /**
+ * Visual heading level (1-6). Determines styling from theme.
+ * Required to ensure intentional visual hierarchy.
+ */
+ level: XDSHeadingLevel;
+
+ /**
+ * Accessibility level override. When set, the `aria-level` will differ
+ * from the visual `level`. Use this when the visual hierarchy doesn't
+ * match the document outline (e.g., sidebar headings, reused components).
+ *
+ * @default Same as `level`
+ *
+ * @example
+ * // Visually styled as h2, but semantically h3 in document outline
+ * <XDSHeading level={2} accessibilityLevel={3}>Sidebar Section</XDSHeading>
+ */
+ accessibilityLevel?: XDSHeadingLevel;
+
+ /**
+ * Visual variant. Themes define different scales for each variant.
+ * - 'default': Dense scale for internal tools (h1: 20px)
+ * - 'editorial': Larger scale for content-heavy pages (h1: 32px)
+ * @default 'default'
+ */
+ variant?: XDSHeadingVariant;
+
+ /**
+ * Text color.
+ * @default 'primary'
+ */
+ color?: XDSTextColor;
+
+ /**
+ * Display type. Headings default to block.
+ * Note: Silently overridden to 'block' when maxLines > 0 or hasCapsize is true.
+ * @default 'block'
+ */
+ display?: XDSTextDisplay;
+
+ /**
+ * Maximum lines before truncation. 0 = no truncation.
+ * When set, shows tooltip on hover if content is truncated.
+ * @default 0
+ */
+ maxLines?: number;
+
+ /**
+ * Control tooltip behavior for truncated text.
+ * - `true` (default when maxLines > 0): show tooltip at default position
+ * - `false`: disable tooltip
+ * - Position value: show tooltip at specific position
+ * @default true
+ */
+ truncateTooltip?: boolean | LayerPlacement;
+
+ /**
+ * Word break behavior for truncated text.
+ * @default 'break-all' for maxLines=1, 'break-word' otherwise
+ */
+ wordBreak?: XDSWordBreak;
+
+ /**
+ * Text wrapping behavior.
+ */
+ textWrap?: XDSTextWrap;
+
+ /**
+ * Enable optical alignment (text-box-trim).
+ * Forces block display.
+ * @default false
+ */
+ hasCapsize?: boolean;
+
+ /**
+ * Strikethrough decoration.
+ * @default false
+ */
+ hasStrikethrough?: boolean;
+
+ /**
+ * Constrained styles for layout integration.
+ * Allows margins, width constraints, flex child props, text alignment.
+ * Typography properties (fontSize, fontWeight, color, etc.) should NOT be used.
+ */
+ xstyle?: StyleXStyles;
+
+ /**
+ * Heading content
+ */
+ children: ReactNode;
+
+ 'data-testid'?: string;
+ id?: string;
+}
+
+const levelToTag = {
+ 1: 'h1',
+ 2: 'h2',
+ 3: 'h3',
+ 4: 'h4',
+ 5: 'h5',
+ 6: 'h6',
+} as const;
+
+const levelToKey: Record<XDSHeadingLevel, HeadingLevel> = {
+ 1: 'h1',
+ 2: 'h2',
+ 3: 'h3',
+ 4: 'h4',
+ 5: 'h5',
+ 6: 'h6',
+};
+
+/**
+ * XDSHeading - Semantic heading component
+ *
+ * Renders headings with semantic HTML (h1-h6) and themed styling.
+ *
+ * @example
+ * ```tsx
+ * <XDSHeading level={1}>Page Title</XDSHeading>
+ * <XDSHeading level={2}>Section</XDSHeading>
+ * <XDSHeading level={1} variant="editorial">Article Title</XDSHeading>
+ * <XDSHeading level={2} accessibilityLevel={3}>Sidebar Section</XDSHeading>
+ *
+ * // With truncation
+ * <XDSHeading level={2} maxLines={1}>Very Long Section Title...</XDSHeading>
+ *
+ * // With color
+ * <XDSHeading level={3} color="secondary">Muted Heading</XDSHeading>
+ * ```
+ */
+export const XDSHeading = forwardRef<HTMLHeadingElement, XDSHeadingProps>(
+ function XDSHeading(
+ {
+ level,
+ accessibilityLevel,
+ variant = 'default',
+ color = 'primary',
+ display = 'block',
+ maxLines = 0,
+ truncateTooltip = true,
+ wordBreak,
+ textWrap,
+ hasCapsize = false,
+ hasStrikethrough = false,
+ xstyle,
+ children,
+ ...props
+ },
+ forwardedRef,
+ ) {
+ const themeContext = useContext(ThemeContext);
+ const Component = levelToTag[level];
+ const levelKey = levelToKey[level];
+
+ const headingConfig = themeContext?.theme?.components?.heading;
+ const headingStyles =
+ variant === 'editorial'
+ ? headingConfig?.editorialStyles
+ : headingConfig?.styles;
+ const levelStyle = headingStyles?.[levelKey];
+
+ // If accessibilityLevel differs from visual level, use aria-level
+ const ariaProps =
+ accessibilityLevel && accessibilityLevel !== level
+ ? {'aria-level': accessibilityLevel}
+ : {};
+
+ // Resolve wordBreak with smart default
+ const resolvedWordBreak =
+ wordBreak ?? (maxLines === 1 ? 'break-all' : 'break-word');
+
+ // Resolve display - force block when maxLines > 0 or hasCapsize
+ const resolvedDisplay =
+ maxLines > 0 || hasCapsize ? 'block' : display;
+
+ // Truncation detection
+ const truncation = useTruncation({maxLines});
+
+ // Tooltip for truncated text
+ const tooltipPlacement: LayerPlacement =
+ typeof truncateTooltip === 'string' ? truncateTooltip : 'above';
+ const tooltipEnabled =
+ maxLines > 0 && truncateTooltip !== false && truncation.isTruncated;
+
+ const tooltip = useXDSTooltip({
+ placement: tooltipPlacement,
+ isEnabled: tooltipEnabled,
+ });
+
+ // Merge refs: forwardedRef, truncation.ref, tooltip.ref
+ const mergedRef = useCallback(
+ (element: HTMLHeadingElement | null) => {
+ // Forward ref
+ if (typeof forwardedRef === 'function') {
+ forwardedRef(element);
+ } else if (forwardedRef) {
+ forwardedRef.current = element;
+ }
+ // Truncation ref
+ truncation.ref(element);
+ // Tooltip ref
+ tooltip.ref(element);
+ },
+ [forwardedRef, truncation.ref, tooltip.ref],
+ );
+
+ // Build inline style for -webkit-line-clamp (dynamic value)
+ const inlineStyle =
+ maxLines > 1 ? {WebkitLineClamp: maxLines} : undefined;
+
+ return (
+ <>
+ <Component
+ ref={mergedRef}
+ {...stylex.props(
+ levelStyle,
+ colorStyles[color],
+ // Display: use truncation styles when maxLines > 0
+ maxLines === 1
+ ? truncationStyles.singleLine
+ : maxLines > 1
+ ? truncationStyles.multiLine
+ : displayStyles[resolvedDisplay],
+ // Word break when truncating
+ maxLines > 0 && wordBreakStyles[resolvedWordBreak],
+ // Text wrap
+ textWrap && textWrapStyles[textWrap],
+ // Capsize
+ hasCapsize && capsizeStyles.enabled,
+ // Decorations
+ hasStrikethrough && decorationStyles.strikethrough,
+ // User xstyle
+ xstyle,
+ )}
+ style={inlineStyle}
+ aria-describedby={tooltipEnabled ? tooltip.describedBy : undefined}
+ {...ariaProps}
+ {...props}
+ >
+ {children}
+ </Component>
+ {tooltipEnabled &&
+ tooltip.renderTooltip(
+ <span {...stylex.props(truncationTooltipStyles.content)}>
+ {truncation.fullText}
+ </span>,
+ )}
+ </>
+ );
+ },
+);
diff --git a/packages/core/src/Text/XDSText.test.tsx b/packages/core/src/Text/XDSText.test.tsx
new file mode 100644
index 0000000000..f5ae00a1a5
--- /dev/null
+++ b/packages/core/src/Text/XDSText.test.tsx
@@ -0,0 +1,211 @@
+/**
+ * @file XDSText.test.tsx
+ * Tests for XDSText component
+ */
+
+import {render, screen} from '@testing-library/react';
+import {describe, it, expect} from 'vitest';
+import {XDSText} from './XDSText';
+import {Theme} from '../theme/Theme';
+import {defaultTheme} from '../theme/defaultTheme.stylex';
+
+describe('XDSText', () => {
+ describe('rendering', () => {
+ it('renders children correctly', () => {
+ render(<XDSText type="body">Hello World</XDSText>);
+ expect(screen.getByText('Hello World')).toBeInTheDocument();
+ });
+
+ it('renders as span by default', () => {
+ render(<XDSText type="body">Text</XDSText>);
+ const element = screen.getByText('Text');
+ expect(element.tagName).toBe('SPAN');
+ });
+
+ it('renders as paragraph when as="p"', () => {
+ render(<XDSText type="body" as="p">Paragraph</XDSText>);
+ const element = screen.getByText('Paragraph');
+ expect(element.tagName).toBe('P');
+ });
+
+ it('renders as div when as="div"', () => {
+ render(<XDSText type="body" as="div">Div</XDSText>);
+ const element = screen.getByText('Div');
+ expect(element.tagName).toBe('DIV');
+ });
+
+ it('renders as label when as="label"', () => {
+ render(<XDSText type="body" as="label">Label</XDSText>);
+ const element = screen.getByText('Label');
+ expect(element.tagName).toBe('LABEL');
+ });
+ });
+
+ describe('types', () => {
+ it('renders body type', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body">Body text</XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Body text')).toBeInTheDocument();
+ });
+
+ it('renders large type', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="large">Large text</XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Large text')).toBeInTheDocument();
+ });
+
+ it('renders supporting type', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="supporting">Supporting text</XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Supporting text')).toBeInTheDocument();
+ });
+
+ it('renders code type', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="code">const x = 1;</XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('const x = 1;')).toBeInTheDocument();
+ });
+
+ it('renders label type', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="label">Label text</XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Label text')).toBeInTheDocument();
+ });
+ });
+
+ describe('props', () => {
+ it('forwards additional props', () => {
+ render(<XDSText type="body" data-testid="custom-text">Text</XDSText>);
+ expect(screen.getByTestId('custom-text')).toBeInTheDocument();
+ });
+
+ it('accepts color prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" color="secondary">
+ Secondary text
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Secondary text')).toBeInTheDocument();
+ });
+
+ it('accepts weight prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" weight="bold">
+ Bold text
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Bold text')).toBeInTheDocument();
+ });
+
+ it('accepts display prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" display="block">
+ Block text
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Block text')).toBeInTheDocument();
+ });
+
+ it('accepts hasStrikethrough prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" hasStrikethrough>
+ Strikethrough text
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Strikethrough text')).toBeInTheDocument();
+ });
+
+ it('accepts hasTabularNumbers prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" hasTabularNumbers>
+ 12345
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('12345')).toBeInTheDocument();
+ });
+
+ it('accepts hasCapsize prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" hasCapsize>
+ Capsize text
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Capsize text')).toBeInTheDocument();
+ });
+
+ it('accepts textWrap prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" textWrap="balance">
+ Balanced text wrap
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Balanced text wrap')).toBeInTheDocument();
+ });
+
+ it('accepts maxLines prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" maxLines={2}>
+ This is a long text that should be truncated to two lines
+ </XDSText>
+ </Theme>,
+ );
+ expect(
+ screen.getByText(
+ 'This is a long text that should be truncated to two lines',
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it('accepts wordBreak prop', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" maxLines={1} wordBreak="break-word">
+ Text with word break
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('Text with word break')).toBeInTheDocument();
+ });
+
+ it('accepts truncateTooltip=false to disable tooltip', () => {
+ render(
+ <Theme theme={defaultTheme}>
+ <XDSText type="body" maxLines={1} truncateTooltip={false}>
+ No tooltip
+ </XDSText>
+ </Theme>,
+ );
+ expect(screen.getByText('No tooltip')).toBeInTheDocument();
+ });
+ });
+});
diff --git a/packages/core/src/Text/XDSText.tsx b/packages/core/src/Text/XDSText.tsx
new file mode 100644
index 0000000000..cf6a7e2a0a
--- /dev/null
+++ b/packages/core/src/Text/XDSText.tsx
@@ -0,0 +1,288 @@
+/**
+ * @file XDSText.tsx
+ * @input Uses React forwardRef, HTMLAttributes, ReactNode
+ * @output Exports XDSText component, XDSTextProps, XDSTextType, XDSTextSize types
+ * @position Core implementation; consumed by index.ts, tested by XDSText.test.tsx
+ *
+ * SYNC: When modified, update these files to stay in sync:
+ * - /packages/core/src/Text/README.md (props table, features, implementation notes)
+ * - /packages/core/src/Text/XDSText.test.tsx (tests for new/changed behavior)
+ * - /packages/core/src/Text/index.ts (exports if types change)
+ * - /apps/storybook/stories/Text.stories.tsx (storybook stories)
+ */
+
+import {forwardRef, useCallback, useContext, type ReactNode} from 'react';
+import * as stylex from '@stylexjs/stylex';
+import type {StyleXStyles} from '@stylexjs/stylex';
+import {ThemeContext} from '../theme/ThemeContext';
+import type {
+ XDSTextType,
+ XDSTextSize,
+ XDSTextColor,
+ XDSTextWeight,
+ XDSTextDisplay,
+ XDSWordBreak,
+ XDSTextWrap,
+} from '../theme/types';
+import {
+ colorStyles,
+ weightStyles,
+ displayStyles,
+ truncationStyles,
+ wordBreakStyles,
+ textWrapStyles,
+ capsizeStyles,
+ decorationStyles,
+ tabularNumbersStyle,
+ truncationTooltipStyles,
+} from './text.stylex';
+import {useTruncation} from './useTruncation';
+import {useXDSTooltip, type LayerPlacement} from '../Layer';
+
+export type {XDSTextType, XDSTextSize};
+
+export interface XDSTextProps {
+ /**
+ * Semantic text type. Determines size, weight, and line-height from theme.
+ * Required to ensure semantic usage.
+ */
+ type: XDSTextType;
+
+ /**
+ * Explicit font size override. When set, overrides the size from `type`
+ * but preserves other type properties (font-family, default color).
+ *
+ * ⚠️ Lint rule: Prefer using `type` alone. Use `size` only for custom
+ * UI elements that need explicit size control (metrics, callouts).
+ */
+ size?: XDSTextSize;
+
+ /**
+ * Text color. Defaults vary by type:
+ * - 'supporting' → 'secondary'
+ * - others → 'primary'
+ */
+ color?: XDSTextColor;
+
+ /**
+ * Font weight override.
+ */
+ weight?: XDSTextWeight;
+
+ /**
+ * Display type. Text defaults to inline.
+ * Note: Silently overridden to 'block' when maxLines > 0 or hasCapsize is true.
+ * @default 'inline'
+ */
+ display?: XDSTextDisplay;
+
+ /**
+ * Maximum lines before truncation. 0 = no truncation.
+ * When set, shows tooltip on hover if content is truncated.
+ * @default 0
+ */
+ maxLines?: number;
+
+ /**
+ * Control tooltip behavior for truncated text.
+ * - `true` (default when maxLines > 0): show tooltip at default position
+ * - `false`: disable tooltip
+ * - Position value: show tooltip at specific position
+ * @default true
+ */
+ truncateTooltip?: boolean | LayerPlacement;
+
+ /**
+ * Word break behavior for truncated text.
+ * @default 'break-all' for maxLines=1, 'break-word' otherwise
+ */
+ wordBreak?: XDSWordBreak;
+
+ /**
+ * Text wrapping behavior.
+ */
+ textWrap?: XDSTextWrap;
+
+ /**
+ * Enable optical alignment (text-box-trim).
+ * Forces block display.
+ * @default false
+ */
+ hasCapsize?: boolean;
+
+ /**
+ * Strikethrough decoration.
+ * @default false
+ */
+ hasStrikethrough?: boolean;
+
+ /**
+ * Use tabular (monospace) numbers for alignment.
+ * @default false
+ */
+ hasTabularNumbers?: boolean;
+
+ /**
+ * Constrained styles for layout integration.
+ * Allows margins, width constraints, flex child props, text alignment.
+ * Typography properties (fontSize, fontWeight, color, etc.) should NOT be used.
+ */
+ xstyle?: StyleXStyles;
+
+ /**
+ * Text content
+ */
+ children: ReactNode;
+
+ /**
+ * HTML element to render
+ * @default 'span'
+ */
+ as?: 'span' | 'p' | 'div' | 'label';
+
+ 'data-testid'?: string;
+ id?: string;
+}
+
+// Default color by text type
+const defaultColorByType: Record<XDSTextType, XDSTextColor> = {
+ body: 'primary',
+ large: 'primary',
+ label: 'primary',
+ supporting: 'secondary',
+ code: 'primary',
+};
+
+/**
+ * XDSText - Semantic text component
+ *
+ * Renders text with semantic styling from the theme.
+ *
+ * @example
+ * ```tsx
+ * <XDSText type="body">Body text</XDSText>
+ * <XDSText type="large">Large body text</XDSText>
+ * <XDSText type="label">Form label</XDSText>
+ * <XDSText type="large-label">Empty state label</XDSText>
+ * <XDSText type="supporting">Helper text</XDSText>
+ * <XDSText type="code">const x = 1;</XDSText>
+ *
+ * // With truncation
+ * <XDSText type="body" maxLines={2}>Long text that will be clamped...</XDSText>
+ *
+ * // With color and weight
+ * <XDSText type="body" color="secondary" weight="bold">Styled text</XDSText>
+ * ```
+ */
+export const XDSText = forwardRef<HTMLElement, XDSTextProps>(function XDSText(
+ {
+ type,
+ size,
+ color,
+ weight,
+ display = 'inline',
+ maxLines = 0,
+ truncateTooltip = true,
+ wordBreak,
+ textWrap,
+ hasCapsize = false,
+ hasStrikethrough = false,
+ hasTabularNumbers = false,
+ xstyle,
+ as: Component = 'span',
+ children,
+ ...props
+ },
+ forwardedRef,
+) {
+ const themeContext = useContext(ThemeContext);
+ const textStyles = themeContext?.theme?.components?.text?.styles;
+ const typeStyle = textStyles?.[type];
+
+ // Resolve color with type-based default
+ const resolvedColor = color ?? defaultColorByType[type];
+
+ // Resolve wordBreak with smart default
+ const resolvedWordBreak =
+ wordBreak ?? (maxLines === 1 ? 'break-all' : 'break-word');
+
+ // Resolve display - force block when maxLines > 0 or hasCapsize
+ const resolvedDisplay =
+ maxLines > 0 || hasCapsize ? 'block' : display;
+
+ // Truncation detection
+ const truncation = useTruncation({maxLines});
+
+ // Tooltip for truncated text
+ const tooltipPlacement: LayerPlacement =
+ typeof truncateTooltip === 'string' ? truncateTooltip : 'above';
+ const tooltipEnabled =
+ maxLines > 0 && truncateTooltip !== false && truncation.isTruncated;
+
+ const tooltip = useXDSTooltip({
+ placement: tooltipPlacement,
+ isEnabled: tooltipEnabled,
+ });
+
+ // Merge refs: forwardedRef, truncation.ref, tooltip.ref
+ const mergedRef = useCallback(
+ (element: HTMLElement | null) => {
+ // Forward ref
+ if (typeof forwardedRef === 'function') {
+ forwardedRef(element);
+ } else if (forwardedRef) {
+ forwardedRef.current = element;
+ }
+ // Truncation ref
+ truncation.ref(element);
+ // Tooltip ref
+ tooltip.ref(element);
+ },
+ [forwardedRef, truncation.ref, tooltip.ref],
+ );
+
+ // Build inline style for -webkit-line-clamp (dynamic value)
+ const inlineStyle =
+ maxLines > 1 ? {WebkitLineClamp: maxLines} : undefined;
+
+ return (
+ <>
+ <Component
+ ref={mergedRef}
+ {...stylex.props(
+ typeStyle,
+ colorStyles[resolvedColor],
+ weight && weightStyles[weight],
+ // Display: use truncation styles when maxLines > 0
+ maxLines === 1
+ ? truncationStyles.singleLine
+ : maxLines > 1
+ ? truncationStyles.multiLine
+ : displayStyles[resolvedDisplay],
+ // Word break when truncating
+ maxLines > 0 && wordBreakStyles[resolvedWordBreak],
+ // Text wrap
+ textWrap && textWrapStyles[textWrap],
+ // Capsize
+ hasCapsize && capsizeStyles.enabled,
+ // Decorations
+ hasStrikethrough && decorationStyles.strikethrough,
+ hasTabularNumbers && tabularNumbersStyle.enabled,
+ // User xstyle
+ xstyle,
+ )}
+ style={inlineStyle}
+ aria-describedby={tooltipEnabled ? tooltip.describedBy : undefined}
+ {...props}
+ >
+ {children}
+ </Component>
+ {tooltipEnabled &&
+ tooltip.renderTooltip(
+ <span {...stylex.props(truncationTooltipStyles.content)}>
+ {truncation.fullText}
+ </span>,
+ )}
+ </>
+ );
+});
diff --git a/packages/core/src/Text/index.ts b/packages/core/src/Text/index.ts
new file mode 100644
index 0000000000..4368aa7157
--- /dev/null
+++ b/packages/core/src/Text/index.ts
@@ -0,0 +1,41 @@
+/**
+ * @file Text component exports
+ * @position Entry point for Text components
+ */
+
+export {
+ XDSText,
+ type XDSTextProps,
+ type XDSTextType,
+ type XDSTextSize,
+} from './XDSText';
+export {
+ XDSHeading,
+ type XDSHeadingProps,
+ type XDSHeadingLevel,
+ type XDSHeadingVariant,
+} from './XDSHeading';
+export {
+ XDSFontWrapper,
+ useXDSFontWrapperStyles,
+ type XDSFontWrapperProps,
+ type XDSFontWrapperVariant,
+} from './XDSFontWrapper';
+
+// Re-export shared types from theme for convenience
+export type {
+ XDSTextColor,
+ XDSTextWeight,
+ XDSTextDisplay,
+ XDSWordBreak,
+ XDSTextWrap,
+ XDSTextXStyleAllowed,
+ ProseElement,
+} from '../theme/types';
+
+// Re-export useTruncation for advanced use cases
+export {
+ useTruncation,
+ type UseTruncationOptions,
+ type UseTruncationReturn,
+} from './useTruncation';
diff --git a/packages/core/src/Text/text.stylex.ts b/packages/core/src/Text/text.stylex.ts
new file mode 100644
index 0000000000..7a8127f751
--- /dev/null
+++ b/packages/core/src/Text/text.stylex.ts
@@ -0,0 +1,169 @@
+/**
+ * @file text.stylex.ts
+ * @input Uses StyleX, theme tokens
+ * @output Exports StyleX styles for XDSText and XDSHeading props
+ * @position Styles module; consumed by XDSText.tsx, XDSHeading.tsx
+ *
+ * SYNC: When modified, update:
+ * - /packages/core/src/Text/README.md
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {
+ colorVars,
+ fontWeightVars,
+} from '../theme/tokens.stylex';
+
+// =============================================================================
+// Color Styles
+// =============================================================================
+
+export const colorStyles = stylex.create({
+ primary: {
+ color: colorVars['--color-text-primary'],
+ },
+ secondary: {
+ color: colorVars['--color-text-secondary'],
+ },
+ disabled: {
+ color: colorVars['--color-text-disabled'],
+ },
+ placeholder: {
+ color: colorVars['--color-text-placeholder'],
+ },
+ active: {
+ color: colorVars['--color-accent'],
+ },
+ inherit: {
+ color: 'inherit',
+ },
+});
+
+// =============================================================================
+// Weight Styles
+// =============================================================================
+
+export const weightStyles = stylex.create({
+ normal: {
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ },
+ medium: {
+ fontWeight: fontWeightVars['--font-weight-medium'],
+ },
+ semibold: {
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ },
+ bold: {
+ fontWeight: fontWeightVars['--font-weight-bold'],
+ },
+});
+
+// =============================================================================
+// Display Styles
+// =============================================================================
+
+export const displayStyles = stylex.create({
+ inline: {
+ display: 'inline',
+ },
+ block: {
+ display: 'block',
+ },
+});
+
+// =============================================================================
+// Truncation Styles
+// =============================================================================
+
+export const truncationStyles = stylex.create({
+ // Single-line truncation (maxLines=1)
+ singleLine: {
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ display: 'block',
+ },
+ // Multi-line truncation base (maxLines>1)
+ // Note: -webkit-line-clamp value is set via inline style
+ multiLine: {
+ overflow: 'hidden',
+ display: '-webkit-box',
+ WebkitBoxOrient: 'vertical',
+ },
+});
+
+// =============================================================================
+// Word Break Styles
+// =============================================================================
+
+export const wordBreakStyles = stylex.create({
+ 'break-word': {
+ wordBreak: 'normal',
+ overflowWrap: 'break-word',
+ },
+ 'break-all': {
+ wordBreak: 'break-all',
+ },
+});
+
+// =============================================================================
+// Text Wrap Styles
+// =============================================================================
+
+export const textWrapStyles = stylex.create({
+ wrap: {
+ textWrap: 'wrap',
+ },
+ nowrap: {
+ textWrap: 'nowrap',
+ },
+ balance: {
+ textWrap: 'balance',
+ },
+ pretty: {
+ textWrap: 'pretty',
+ },
+});
+
+// =============================================================================
+// Capsize Styles (Text Box Trim)
+// =============================================================================
+
+export const capsizeStyles = stylex.create({
+ enabled: {
+ textBoxEdge: 'cap alphabetic',
+ textBoxTrim: 'trim-both',
+ display: 'block',
+ },
+});
+
+// =============================================================================
+// Decoration Styles
+// =============================================================================
+
+export const decorationStyles = stylex.create({
+ strikethrough: {
+ textDecoration: 'line-through',
+ },
+});
+
+// =============================================================================
+// Tabular Numbers Style
+// =============================================================================
+
+export const tabularNumbersStyle = stylex.create({
+ enabled: {
+ fontVariantNumeric: 'tabular-nums',
+ },
+});
+
+// =============================================================================
+// Truncation Tooltip Content Style
+// =============================================================================
+
+export const truncationTooltipStyles = stylex.create({
+ content: {
+ maxWidth: '300px',
+ wordBreak: 'break-word',
+ },
+});
diff --git a/packages/core/src/Text/useTruncation.ts b/packages/core/src/Text/useTruncation.ts
new file mode 100644
index 0000000000..cf42801448
--- /dev/null
+++ b/packages/core/src/Text/useTruncation.ts
@@ -0,0 +1,121 @@
+/**
+ * @file useTruncation.ts
+ * @input Uses React hooks, ResizeObserver
+ * @output Exports useTruncation hook for detecting text overflow
+ * @position Hook; consumed by XDSText.tsx, XDSHeading.tsx
+ *
+ * SYNC: When modified, update:
+ * - /packages/core/src/Text/README.md
+ */
+
+import {useCallback, useRef, useState, type RefCallback} from 'react';
+
+export interface UseTruncationOptions {
+ /**
+ * Maximum number of lines before truncation.
+ * 0 = no truncation, hook returns isTruncated: false
+ */
+ maxLines: number;
+}
+
+export interface UseTruncationReturn {
+ /**
+ * Ref callback to attach to the text element
+ */
+ ref: RefCallback<HTMLElement>;
+
+ /**
+ * Whether the text is currently truncated (overflowing)
+ */
+ isTruncated: boolean;
+
+ /**
+ * Full text content for tooltip display
+ */
+ fullText: string;
+}
+
+/**
+ * Hook for detecting text overflow/truncation.
+ *
+ * Uses ResizeObserver for efficient detection when content or container changes.
+ * - Single-line: compares scrollWidth > offsetWidth
+ * - Multi-line: compares scrollHeight > offsetHeight
+ *
+ * @example
+ * ```tsx
+ * const truncation = useTruncation({ maxLines: 2 });
+ *
+ * <div ref={truncation.ref} style={{ WebkitLineClamp: 2 }}>
+ * {text}
+ * </div>
+ *
+ * {truncation.isTruncated && <Tooltip>{truncation.fullText}</Tooltip>}
+ * ```
+ */
+export function useTruncation(
+ options: UseTruncationOptions,
+): UseTruncationReturn {
+ const {maxLines} = options;
+ const [isTruncated, setIsTruncated] = useState(false);
+ const [fullText, setFullText] = useState('');
+ const elementRef = useRef<HTMLElement | null>(null);
+ const observerRef = useRef<ResizeObserver | null>(null);
+
+ const checkTruncation = useCallback(
+ (element: HTMLElement) => {
+ if (maxLines === 0) {
+ setIsTruncated(false);
+ return;
+ }
+
+ // Capture full text content
+ setFullText(element.textContent ?? '');
+
+ // Check for overflow
+ if (maxLines === 1) {
+ // Single-line: check horizontal overflow
+ setIsTruncated(element.scrollWidth > element.offsetWidth);
+ } else {
+ // Multi-line: check vertical overflow
+ setIsTruncated(element.scrollHeight > element.offsetHeight);
+ }
+ },
+ [maxLines],
+ );
+
+ const ref: RefCallback<HTMLElement> = useCallback(
+ (element: HTMLElement | null) => {
+ // Cleanup previous observer
+ if (observerRef.current) {
+ observerRef.current.disconnect();
+ observerRef.current = null;
+ }
+
+ elementRef.current = element;
+
+ if (element && maxLines > 0) {
+ // Initial check
+ checkTruncation(element);
+
+ // Setup ResizeObserver for dynamic updates (if available)
+ if (typeof ResizeObserver !== 'undefined') {
+ observerRef.current = new ResizeObserver(() => {
+ checkTruncation(element);
+ });
+ observerRef.current.observe(element);
+ }
+ } else {
+ setIsTruncated(false);
+ setFullText('');
+ }
+ },
+ [maxLines, checkTruncation],
+ );
+
+ return {
+ ref,
+ isTruncated,
+ fullText,
+ };
+}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 12e6cdd829..fd61e597c2 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -13,6 +13,7 @@ export * from './Button';
export * from './CheckboxInput';
export * from './Field';
export * from './Icon';
+export * from './Text';
export * from './TextInput';
export * from './TextArea';
diff --git a/packages/core/src/theme/defaultTheme.stylex.ts b/packages/core/src/theme/defaultTheme.stylex.ts
index 3304c7f6ec..cefb6b17dc 100644
--- a/packages/core/src/theme/defaultTheme.stylex.ts
+++ b/packages/core/src/theme/defaultTheme.stylex.ts
@@ -20,6 +20,9 @@ import {
elevationVars,
transitionVars,
typographyVars,
+ textSizeVars,
+ lineHeightVars,
+ fontWeightVars,
} from './tokens.stylex';
import type {
ColorVarName,
@@ -28,12 +31,18 @@ import type {
ElevationVarName,
TransitionVarName,
TypographyVarName,
+ TextSizeVarName,
+ LineHeightVarName,
+ FontWeightVarName,
BaseColorRaw,
BaseSpacingRaw,
BaseRadiusRaw,
BaseElevationRaw,
BaseTransitionRaw,
BaseTypographyRaw,
+ BaseTextSizeRaw,
+ BaseLineHeightRaw,
+ BaseFontWeightRaw,
} from './tokens.stylex';
// =============================================================================
@@ -201,6 +210,34 @@ const typographyRaw = {
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
} as const satisfies Record<TypographyVarName, string>;
+const textSizeRaw = {
+ '--text-4xs': '0.5rem', // 8px - citation
+ '--text-3xs': '0.625rem', // 10px - micro
+ '--text-2xs': '0.6875rem', // 11px - small micro
+ '--text-xsm': '0.75rem', // 12px - supporting, badge
+ '--text-sm': '0.8125rem', // 13px - secondary text
+ '--text-base': '0.875rem', // 14px - body text (XDS default)
+ '--text-lg': '1rem', // 16px - large body
+ '--text-xl': '1.125rem', // 18px - h2
+ '--text-2xl': '1.25rem', // 20px - h1
+ '--text-3xl': '1.5rem', // 24px - editorial h2
+ '--text-4xl': '2rem', // 32px - editorial h1, data viz
+} as const satisfies Record<TextSizeVarName, string>;
+
+const lineHeightRaw = {
+ '--leading-tight': '1.25', // Display text, headings
+ '--leading-snug': '1.375', // Compact body text, headings
+ '--leading-normal': '1.5', // Body text, large body
+ '--leading-relaxed': '1.625', // Editorial body, reading text
+} as const satisfies Record<LineHeightVarName, string>;
+
+const fontWeightRaw = {
+ '--font-weight-normal': '400', // body, captions, code
+ '--font-weight-medium': '500', // subheadlines, data viz
+ '--font-weight-semibold': '600', // emphasized body, titles
+ '--font-weight-bold': '700', // strong emphasis, headings
+} as const satisfies Record<FontWeightVarName, string>;
+
// =============================================================================
// Theme Overrides using createTheme
// =============================================================================
@@ -235,6 +272,21 @@ const typographyTheme = stylex.createTheme(
typographyRaw as unknown as BaseTypographyRaw,
);
+const textSizeTheme = stylex.createTheme(
+ textSizeVars,
+ textSizeRaw as unknown as BaseTextSizeRaw,
+);
+
+const lineHeightTheme = stylex.createTheme(
+ lineHeightVars,
+ lineHeightRaw as unknown as BaseLineHeightRaw,
+);
+
+const fontWeightTheme = stylex.createTheme(
+ fontWeightVars,
+ fontWeightRaw as unknown as BaseFontWeightRaw,
+);
+
// =============================================================================
// Component Style Overrides
// =============================================================================
@@ -246,6 +298,271 @@ const buttonVariants = stylex.create({
},
});
+/**
+ * Semantic heading styles (h1-h6) - default variant
+ * Uses XDS dense scale for internal tools
+ */
+const headingStyles = stylex.create({
+ // Default variant (dense scale for internal tools)
+ h1: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-2xl'], // 20px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.2, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h2: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-xl'], // 18px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h3: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-lg'], // 16px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.25, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h4: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h5: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-base'], // 14px (same as h4)
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h6: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-xsm'], // 12px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 16px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+});
+
+/**
+ * Editorial heading styles (h1-h4) - larger scale for content-heavy pages
+ */
+const headingEditorialStyles = stylex.create({
+ h1: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-4xl'], // 32px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.5, // 48px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h2: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-3xl'], // 24px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 32px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h3: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-2xl'], // 20px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.4, // 28px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h4: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-lg'], // 16px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.5, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ // h5 and h6 fall back to default variant
+ h5: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h6: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-xsm'], // 12px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 16px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+});
+
+/**
+ * Semantic text styles for body content
+ */
+const textStyles = stylex.create({
+ /** Body text (14px, regular) - The bulk of content */
+ body: {
+ fontFamily: typographyVars['--font-heading'], // Optimistic
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ /** Large body text (16px, regular) - Emphasized content, quotes */
+ large: {
+ fontFamily: typographyVars['--font-heading'], // Optimistic
+ fontSize: textSizeVars['--text-lg'], // 16px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.5, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ /** Emphasized text (14px, medium) - Labels for form/chart/table columns */
+ label: {
+ fontFamily: typographyVars['--font-heading'], // Optimistic
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-medium'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ /** Supporting/helper text (12px, regular) - Supplemental info */
+ supporting: {
+ fontFamily: typographyVars['--font-heading'], // Optimistic
+ fontSize: textSizeVars['--text-xsm'], // 12px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.3333333333333333, // 16px
+ color: colorVars['--color-text-secondary'],
+ margin: 0,
+ },
+ /** Code/monospace text (14px, regular) */
+ code: {
+ fontFamily: typographyVars['--font-code'], // Menlo
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+});
+
+/**
+ * Prose base styles for XDSFontWrapper
+ */
+const proseBaseStyles = stylex.create({
+ base: {
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontFamily: typographyVars['--font-body'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ },
+});
+
+/**
+ * Prose element styles for XDSFontWrapper
+ */
+const proseElementStyles = stylex.create({
+ p: {
+ marginTop: 0,
+ marginBottom: spacingVars['--spacing-3'], // 12px
+ },
+ ul: {
+ marginTop: 0,
+ marginBottom: spacingVars['--spacing-3'], // 12px
+ paddingInlineStart: spacingVars['--spacing-5'], // 20px
+ },
+ ol: {
+ marginTop: 0,
+ marginBottom: spacingVars['--spacing-3'], // 12px
+ paddingInlineStart: spacingVars['--spacing-5'], // 20px
+ },
+ li: {
+ marginBottom: spacingVars['--spacing-1'], // 4px
+ },
+ liLast: {
+ marginBottom: 0,
+ },
+ blockquote: {
+ marginTop: 0,
+ marginBottom: spacingVars['--spacing-3'], // 12px
+ marginInlineStart: 0,
+ marginInlineEnd: 0,
+ paddingInlineStart: spacingVars['--spacing-4'], // 16px
+ borderInlineStartWidth: '3px',
+ borderInlineStartStyle: 'solid',
+ borderInlineStartColor: colorVars['--color-divider-emphasized'],
+ color: colorVars['--color-text-secondary'],
+ fontStyle: 'italic',
+ },
+ code: {
+ fontFamily: typographyVars['--font-code'],
+ fontSize: '0.9em',
+ backgroundColor: colorVars['--color-wash'],
+ paddingBlock: spacingVars['--spacing-0-5'], // 2px
+ paddingInline: spacingVars['--spacing-1'], // 4px
+ borderRadius: radiusVars['--radius-content'], // 4px
+ },
+ pre: {
+ fontFamily: typographyVars['--font-code'],
+ fontSize: textSizeVars['--text-sm'], // 13px
+ lineHeight: 1.5,
+ marginTop: 0,
+ marginBottom: spacingVars['--spacing-3'], // 12px
+ padding: spacingVars['--spacing-3'], // 12px
+ backgroundColor: colorVars['--color-wash'],
+ borderRadius: radiusVars['--radius-element'], // 8px
+ overflow: 'auto',
+ whiteSpace: 'pre',
+ },
+ preCode: {
+ backgroundColor: 'transparent',
+ padding: 0,
+ borderRadius: 0,
+ fontSize: 'inherit',
+ },
+ hr: {
+ marginBlock: spacingVars['--spacing-4'], // 16px
+ border: 'none',
+ borderTopWidth: '1px',
+ borderTopStyle: 'solid',
+ borderTopColor: colorVars['--color-divider'],
+ },
+ strong: {
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ },
+ em: {
+ fontStyle: 'italic',
+ },
+ a: {
+ color: colorVars['--color-text-link'],
+ textDecoration: 'underline',
+ textUnderlineOffset: '2px',
+ },
+ aHover: {
+ textDecorationThickness: '2px',
+ },
+ firstChild: {
+ marginTop: 0,
+ },
+ lastChild: {
+ marginBottom: 0,
+ },
+});
+
// =============================================================================
// Theme Export
// =============================================================================
@@ -259,6 +576,9 @@ export const defaultTheme: Theme = {
elevation: elevationTheme,
transition: transitionTheme,
typography: typographyTheme,
+ textSize: textSizeTheme,
+ lineHeight: lineHeightTheme,
+ fontWeight: fontWeightTheme,
},
raw: {
colors: colorRaw,
@@ -267,10 +587,24 @@ export const defaultTheme: Theme = {
elevation: elevationRaw,
transition: transitionRaw,
typography: typographyRaw,
+ textSize: textSizeRaw,
+ lineHeight: lineHeightRaw,
+ fontWeight: fontWeightRaw,
},
components: {
button: {
variants: buttonVariants,
},
+ heading: {
+ styles: headingStyles,
+ editorialStyles: headingEditorialStyles,
+ },
+ text: {
+ styles: textStyles,
+ },
+ prose: {
+ base: proseBaseStyles.base,
+ styles: proseElementStyles,
+ },
},
};
diff --git a/packages/core/src/theme/index.ts b/packages/core/src/theme/index.ts
index 42f44d11b9..35509dae84 100644
--- a/packages/core/src/theme/index.ts
+++ b/packages/core/src/theme/index.ts
@@ -21,12 +21,18 @@ export {
elevationRaw,
transitionRaw,
typographyRaw,
+ textSizeRaw,
+ lineHeightRaw,
+ fontWeightRaw,
colorVars,
spacingVars,
radiusVars,
elevationVars,
transitionVars,
typographyVars,
+ textSizeVars,
+ lineHeightVars,
+ fontWeightVars,
} from './tokens.stylex';
// Export token key types for theme authoring
@@ -37,12 +43,18 @@ export type {
ElevationVarName,
TransitionVarName,
TypographyVarName,
+ TextSizeVarName,
+ LineHeightVarName,
+ FontWeightVarName,
BaseColorRaw,
BaseSpacingRaw,
BaseRadiusRaw,
BaseElevationRaw,
BaseTransitionRaw,
BaseTypographyRaw,
+ BaseTextSizeRaw,
+ BaseLineHeightRaw,
+ BaseFontWeightRaw,
} from './tokens.stylex';
export type {
@@ -51,4 +63,9 @@ export type {
ThemeRaw,
ComponentStyles,
ThemeStyles,
+ HeadingLevel,
+ XDSTextType,
+ XDSTextSize,
+ XDSTextWeight,
+ XDSTextColor,
} from './types';
diff --git a/packages/core/src/theme/neutralTheme.stylex.ts b/packages/core/src/theme/neutralTheme.stylex.ts
index 2982b64335..8330a52a4a 100644
--- a/packages/core/src/theme/neutralTheme.stylex.ts
+++ b/packages/core/src/theme/neutralTheme.stylex.ts
@@ -22,6 +22,9 @@ import {
elevationVars,
transitionVars,
typographyVars,
+ textSizeVars,
+ lineHeightVars,
+ fontWeightVars,
} from './tokens.stylex';
import type {
ColorVarName,
@@ -30,12 +33,18 @@ import type {
ElevationVarName,
TransitionVarName,
TypographyVarName,
+ TextSizeVarName,
+ LineHeightVarName,
+ FontWeightVarName,
BaseColorRaw,
BaseSpacingRaw,
BaseRadiusRaw,
BaseElevationRaw,
BaseTransitionRaw,
BaseTypographyRaw,
+ BaseTextSizeRaw,
+ BaseLineHeightRaw,
+ BaseFontWeightRaw,
} from './tokens.stylex';
// =============================================================================
@@ -244,6 +253,34 @@ const typographyRaw = {
'Geist, "Geist Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
} as const satisfies Record<TypographyVarName, string>;
+const textSizeRaw = {
+ '--text-4xs': '0.5rem', // 8px - citation
+ '--text-3xs': '0.625rem', // 10px - micro
+ '--text-2xs': '0.6875rem', // 11px - small micro
+ '--text-xsm': '0.75rem', // 12px - supporting, badge
+ '--text-sm': '0.8125rem', // 13px - secondary text
+ '--text-base': '0.875rem', // 14px - body text (XDS default)
+ '--text-lg': '1rem', // 16px - large body
+ '--text-xl': '1.125rem', // 18px - h2
+ '--text-2xl': '1.25rem', // 20px - h1
+ '--text-3xl': '1.5rem', // 24px - editorial h2
+ '--text-4xl': '2rem', // 32px - editorial h1, data viz
+} as const satisfies Record<TextSizeVarName, string>;
+
+const lineHeightRaw = {
+ '--leading-tight': '1.25', // Display text, headings
+ '--leading-snug': '1.375', // Compact body text, headings
+ '--leading-normal': '1.5', // Body text, large body
+ '--leading-relaxed': '1.625', // Editorial body, reading text
+} as const satisfies Record<LineHeightVarName, string>;
+
+const fontWeightRaw = {
+ '--font-weight-normal': '400', // body, captions, code
+ '--font-weight-medium': '500', // subheadlines, data viz
+ '--font-weight-semibold': '600', // emphasized body, titles
+ '--font-weight-bold': '700', // strong emphasis, headings
+} as const satisfies Record<FontWeightVarName, string>;
+
// =============================================================================
// Theme Overrides using createTheme
// =============================================================================
@@ -278,6 +315,21 @@ const typographyTheme = stylex.createTheme(
typographyRaw as unknown as BaseTypographyRaw,
);
+const textSizeTheme = stylex.createTheme(
+ textSizeVars,
+ textSizeRaw as unknown as BaseTextSizeRaw,
+);
+
+const lineHeightTheme = stylex.createTheme(
+ lineHeightVars,
+ lineHeightRaw as unknown as BaseLineHeightRaw,
+);
+
+const fontWeightTheme = stylex.createTheme(
+ fontWeightVars,
+ fontWeightRaw as unknown as BaseFontWeightRaw,
+);
+
// =============================================================================
// Component Style Overrides
// =============================================================================
@@ -318,6 +370,166 @@ const sectionStyles = stylex.create({
},
});
+/**
+ * Semantic heading styles (h1-h6) - default variant
+ * Uses XDS dense scale for internal tools
+ */
+const headingStyles = stylex.create({
+ h1: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-2xl'], // 20px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.2, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h2: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-xl'], // 18px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h3: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-lg'], // 16px
+ fontWeight: fontWeightVars['--font-weight-bold'],
+ lineHeight: 1.25, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h4: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-bold'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h5: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-base'], // 14px (same as h4)
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h6: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-xsm'], // 12px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 16px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+});
+
+/**
+ * Editorial heading styles (h1-h4) - larger scale for content-heavy pages
+ */
+const headingEditorialStyles = stylex.create({
+ h1: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-4xl'], // 32px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.5, // 48px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h2: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-3xl'], // 24px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 32px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h3: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-2xl'], // 20px
+ fontWeight: fontWeightVars['--font-weight-bold'],
+ lineHeight: 1.4, // 28px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h4: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-lg'], // 16px
+ fontWeight: fontWeightVars['--font-weight-bold'],
+ lineHeight: 1.5, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h5: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ h6: {
+ fontFamily: typographyVars['--font-heading'],
+ fontSize: textSizeVars['--text-xsm'], // 12px
+ fontWeight: fontWeightVars['--font-weight-semibold'],
+ lineHeight: 1.3333333333333333, // 16px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+});
+
+/**
+ * Semantic text styles for body content
+ */
+const textStyles = stylex.create({
+ /** Body text (14px, regular) - The bulk of content */
+ body: {
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ /** Large body text (16px, regular) - Emphasized content, quotes */
+ large: {
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-lg'], // 16px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.5, // 24px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ /** Emphasized text (14px, medium) - Labels for form/chart/table columns */
+ label: {
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-medium'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+ /** Supporting/helper text (12px, regular) - Supplemental info */
+ supporting: {
+ fontFamily: typographyVars['--font-body'],
+ fontSize: textSizeVars['--text-xsm'], // 12px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.3333333333333333, // 16px
+ color: colorVars['--color-text-secondary'],
+ margin: 0,
+ },
+ /** Code/monospace text (14px, regular) */
+ code: {
+ fontFamily: typographyVars['--font-code'],
+ fontSize: textSizeVars['--text-base'], // 14px
+ fontWeight: fontWeightVars['--font-weight-normal'],
+ lineHeight: 1.4285714285714286, // 20px
+ color: colorVars['--color-text-primary'],
+ margin: 0,
+ },
+});
+
// =============================================================================
// Theme Export
// =============================================================================
@@ -331,6 +543,9 @@ export const neutralTheme: Theme = {
elevation: elevationTheme,
transition: transitionTheme,
typography: typographyTheme,
+ textSize: textSizeTheme,
+ lineHeight: lineHeightTheme,
+ fontWeight: fontWeightTheme,
},
raw: {
colors: colorRaw,
@@ -339,6 +554,9 @@ export const neutralTheme: Theme = {
elevation: elevationRaw,
transition: transitionRaw,
typography: typographyRaw,
+ textSize: textSizeRaw,
+ lineHeight: lineHeightRaw,
+ fontWeight: fontWeightRaw,
},
components: {
button: {
@@ -350,5 +568,12 @@ export const neutralTheme: Theme = {
section: {
content: sectionStyles.content,
},
+ heading: {
+ styles: headingStyles,
+ editorialStyles: headingEditorialStyles,
+ },
+ text: {
+ styles: textStyles,
+ },
},
};
diff --git a/packages/core/src/theme/tokens.stylex.ts b/packages/core/src/theme/tokens.stylex.ts
index 4e271f9535..1f0a9dda06 100644
--- a/packages/core/src/theme/tokens.stylex.ts
+++ b/packages/core/src/theme/tokens.stylex.ts
@@ -188,7 +188,7 @@ export const transitionRaw = {
export const transitionVars = stylex.defineVars(transitionRaw);
// =============================================================================
-// Typography Tokens
+// Typography Tokens - Font Families
// =============================================================================
export const typographyRaw = {
@@ -201,6 +201,52 @@ export const typographyRaw = {
export const typographyVars = stylex.defineVars(typographyRaw);
+// =============================================================================
+// Typography Tokens - Text Sizes
+// =============================================================================
+
+export const textSizeRaw = {
+ '--text-4xs': '0.5rem', // 8px - citation
+ '--text-3xs': '0.625rem', // 10px - micro
+ '--text-2xs': '0.6875rem', // 11px - small micro
+ '--text-xsm': '0.75rem', // 12px - supporting, badge
+ '--text-sm': '0.8125rem', // 13px - secondary text
+ '--text-base': '0.875rem', // 14px - body text (XDS default)
+ '--text-lg': '1rem', // 16px - large body
+ '--text-xl': '1.125rem', // 18px - h2
+ '--text-2xl': '1.25rem', // 20px - h1
+ '--text-3xl': '1.5rem', // 24px - editorial h2
+ '--text-4xl': '2rem', // 32px - editorial h1, data viz
+} as const;
+
+export const textSizeVars = stylex.defineVars(textSizeRaw);
+
+// =============================================================================
+// Typography Tokens - Line Heights
+// =============================================================================
+
+export const lineHeightRaw = {
+ '--leading-tight': '1.25', // Display text, headings
+ '--leading-snug': '1.375', // Compact body text, headings
+ '--leading-normal': '1.5', // Body text, large body
+ '--leading-relaxed': '1.625', // Editorial body, reading text
+} as const;
+
+export const lineHeightVars = stylex.defineVars(lineHeightRaw);
+
+// =============================================================================
+// Typography Tokens - Font Weights
+// =============================================================================
+
+export const fontWeightRaw = {
+ '--font-weight-normal': '400', // body, captions, code
+ '--font-weight-medium': '500', // subheadlines, data viz
+ '--font-weight-semibold': '600', // emphasized body, titles
+ '--font-weight-bold': '700', // strong emphasis, headings
+} as const;
+
+export const fontWeightVars = stylex.defineVars(fontWeightRaw);
+
// =============================================================================
// Token Types
// =============================================================================
@@ -211,6 +257,9 @@ export type RadiusVarName = keyof typeof radiusRaw;
export type ElevationVarName = keyof typeof elevationRaw;
export type TransitionVarName = keyof typeof transitionRaw;
export type TypographyVarName = keyof typeof typographyRaw;
+export type TextSizeVarName = keyof typeof textSizeRaw;
+export type LineHeightVarName = keyof typeof lineHeightRaw;
+export type FontWeightVarName = keyof typeof fontWeightRaw;
// Base raw types for createTheme casting
// StyleX's createTheme requires exact literal types from defineVars.
@@ -222,3 +271,6 @@ export type BaseRadiusRaw = typeof radiusRaw;
export type BaseElevationRaw = typeof elevationRaw;
export type BaseTransitionRaw = typeof transitionRaw;
export type BaseTypographyRaw = typeof typographyRaw;
+export type BaseTextSizeRaw = typeof textSizeRaw;
+export type BaseLineHeightRaw = typeof lineHeightRaw;
+export type BaseFontWeightRaw = typeof fontWeightRaw;
diff --git a/packages/core/src/theme/types.ts b/packages/core/src/theme/types.ts
index cc17eaf235..89393ca21b 100644
--- a/packages/core/src/theme/types.ts
+++ b/packages/core/src/theme/types.ts
@@ -10,13 +10,150 @@ export type StyleXStyles = any;
*/
export type ThemeMode = 'system' | 'light' | 'dark';
+/**
+ * Heading levels (1-6)
+ */
+export type HeadingLevel = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
+
+/**
+ * Semantic text types for XDSText
+ */
+export type XDSTextType = 'body' | 'large' | 'label' | 'supporting' | 'code';
+
+/**
+ * Text size scale for XDSText size prop override
+ * Maps to --text-* tokens
+ */
+export type XDSTextSize =
+ | '4xs'
+ | '3xs'
+ | '2xs'
+ | 'xsm'
+ | 'sm'
+ | 'base'
+ | 'lg'
+ | 'xl'
+ | '2xl'
+ | '3xl'
+ | '4xl';
+
+/**
+ * Font weight variants for XDSText/XDSHeading
+ */
+export type XDSTextWeight = 'normal' | 'medium' | 'semibold' | 'bold';
+
+/**
+ * Text color variants for XDSText/XDSHeading
+ */
+export type XDSTextColor =
+ | 'primary'
+ | 'secondary'
+ | 'disabled'
+ | 'placeholder'
+ | 'active'
+ | 'inherit';
+
+/**
+ * Display mode for XDSText/XDSHeading
+ */
+export type XDSTextDisplay = 'inline' | 'block';
+
+/**
+ * Word break behavior for truncated text
+ */
+export type XDSWordBreak = 'break-word' | 'break-all';
+
+/**
+ * Text wrap behavior
+ */
+export type XDSTextWrap = 'wrap' | 'nowrap' | 'balance' | 'pretty';
+
+/**
+ * Allowed CSS properties for XDSText/XDSHeading xstyle prop.
+ * Constrained to layout-only properties to prevent typography escapes.
+ */
+export type XDSTextXStyleAllowed = {
+ // Index signature required for StyleXStyles compatibility
+ [key: string]: unknown;
+
+ // Margins
+ margin?: unknown;
+ marginTop?: unknown;
+ marginBottom?: unknown;
+ marginStart?: unknown;
+ marginEnd?: unknown;
+ marginBlock?: unknown;
+ marginBlockStart?: unknown;
+ marginBlockEnd?: unknown;
+ marginInline?: unknown;
+ marginInlineStart?: unknown;
+ marginInlineEnd?: unknown;
+
+ // Width constraints
+ width?: unknown;
+ minWidth?: unknown;
+ maxWidth?: unknown;
+
+ // Flex child properties
+ alignSelf?: unknown;
+ flexBasis?: unknown;
+ flexGrow?: unknown;
+ flexShrink?: unknown;
+
+ // Text layout (non-typography)
+ textAlign?: unknown;
+ textAlignLast?: unknown;
+ verticalAlign?: unknown;
+};
+
+/**
+ * Prose element types for XDSFontWrapper
+ */
+export type ProseElement =
+ | 'p'
+ | 'ul'
+ | 'ol'
+ | 'li'
+ | 'liLast'
+ | 'blockquote'
+ | 'code'
+ | 'pre'
+ | 'preCode'
+ | 'hr'
+ | 'strong'
+ | 'em'
+ | 'a'
+ | 'aHover'
+ | 'firstChild'
+ | 'lastChild';
+
/**
* Component-specific style overrides
* Each component augments this interface to add its own entry
* See Button.tsx for an example of module augmentation
*/
-// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface ComponentStyles {
+ // Core typography styles
+ /** Heading styles (h1-h6) */
+ heading?: {
+ /** Default heading styles */
+ styles?: Partial<Record<HeadingLevel, StyleXStyles>>;
+ /** Editorial heading styles (larger scale) */
+ editorialStyles?: Partial<Record<HeadingLevel, StyleXStyles>>;
+ };
+ /** Text styles */
+ text?: {
+ /** Semantic text styles (body, large, label, supporting, code) */
+ styles?: Partial<Record<XDSTextType, StyleXStyles>>;
+ };
+ /** Prose styles for XDSFontWrapper */
+ prose?: {
+ /** Base wrapper styles */
+ base?: StyleXStyles;
+ /** Prose element styles */
+ styles?: Partial<Record<ProseElement, StyleXStyles>>;
+ };
+
// Components add their entries via module augmentation
// Example in Button.tsx:
// declare module '../theme/types' {
@@ -43,6 +180,12 @@ export interface ThemeRaw {
transition: Record<string, string>;
/** Raw typography values (e.g., font family strings) */
typography: Record<string, string>;
+ /** Raw text size values (e.g., '1rem') */
+ textSize: Record<string, string>;
+ /** Raw line height values (e.g., '1.5') */
+ lineHeight: Record<string, string>;
+ /** Raw font weight values (e.g., '400') */
+ fontWeight: Record<string, string>;
}
/**
@@ -59,8 +202,14 @@ export interface ThemeStyles {
elevation: StyleXStyles;
/** Transition CSS variables */
transition: StyleXStyles;
- /** Typography CSS variables */
+ /** Typography (font family) CSS variables */
typography: StyleXStyles;
+ /** Text size CSS variables */
+ textSize: StyleXStyles;
+ /** Line height CSS variables */
+ lineHeight: StyleXStyles;
+ /** Font weight CSS variables */
+ fontWeight: StyleXStyles;
}
/**
diff --git a/packages/core/src/typography.css b/packages/core/src/typography.css
new file mode 100644
index 0000000000..841ed6f663
--- /dev/null
+++ b/packages/core/src/typography.css
@@ -0,0 +1,270 @@
+/**
+ * XDS Typography Styles
+ *
+ * Base typography styles for native HTML elements using CSS custom properties
+ * from the XDS theme. Styles automatically adapt to the current theme.
+ *
+ * Usage:
+ *
+ * 1. Scoped (via XDSFontWrapper component):
+ * <XDSFontWrapper>
+ * <article dangerouslySetInnerHTML={{ __html: content }} />
+ * </XDSFontWrapper>
+ *
+ * 2. Global (apply to body):
+ * import '@xds/core/typography.css';
+ * <body className="xds-typography">
+ *
+ * Requires a parent <Theme> component to set the CSS custom properties.
+ *
+ * Similar to:
+ * - Tailwind's @tailwindcss/typography plugin
+ * - GitHub Primer's primer-typography
+ * - Radix Themes' prose styles
+ */
+
+@layer typography {
+ /* ===========================================================================
+ Base Styles
+ =========================================================================== */
+
+ .xds-typography {
+ font-size: var(--text-base);
+ font-family: var(--font-body);
+ line-height: 1.4285714285714286;
+ color: var(--color-text-primary);
+ }
+
+ /* ===========================================================================
+ Heading Styles - Default Scale
+ =========================================================================== */
+
+ .xds-typography h1,
+ .xds-typography--default h1 {
+ font-family: var(--font-heading);
+ font-size: var(--text-2xl);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.2;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-6);
+ margin-bottom: var(--spacing-3);
+ }
+
+ .xds-typography h2,
+ .xds-typography--default h2 {
+ font-family: var(--font-heading);
+ font-size: var(--text-xl);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.333;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-5);
+ margin-bottom: var(--spacing-3);
+ }
+
+ .xds-typography h3,
+ .xds-typography--default h3 {
+ font-family: var(--font-heading);
+ font-size: var(--text-lg);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.25;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-4);
+ margin-bottom: var(--spacing-2);
+ }
+
+ .xds-typography h4,
+ .xds-typography--default h4 {
+ font-family: var(--font-heading);
+ font-size: var(--text-base);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.428;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-4);
+ margin-bottom: var(--spacing-2);
+ }
+
+ .xds-typography h5,
+ .xds-typography--default h5 {
+ font-family: var(--font-heading);
+ font-size: var(--text-base);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.428;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-3);
+ margin-bottom: var(--spacing-2);
+ }
+
+ .xds-typography h6,
+ .xds-typography--default h6 {
+ font-family: var(--font-heading);
+ font-size: var(--text-xsm);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.333;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-3);
+ margin-bottom: var(--spacing-2);
+ }
+
+ /* ===========================================================================
+ Heading Styles - Editorial Scale
+ =========================================================================== */
+
+ .xds-typography--editorial h1 {
+ font-family: var(--font-heading);
+ font-size: var(--text-4xl);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.5;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-7);
+ margin-bottom: var(--spacing-4);
+ }
+
+ .xds-typography--editorial h2 {
+ font-family: var(--font-heading);
+ font-size: var(--text-3xl);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.333;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-6);
+ margin-bottom: var(--spacing-3);
+ }
+
+ .xds-typography--editorial h3 {
+ font-family: var(--font-heading);
+ font-size: var(--text-2xl);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.4;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-5);
+ margin-bottom: var(--spacing-3);
+ }
+
+ .xds-typography--editorial h4 {
+ font-family: var(--font-heading);
+ font-size: var(--text-lg);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.5;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-4);
+ margin-bottom: var(--spacing-2);
+ }
+
+ .xds-typography--editorial h5 {
+ font-family: var(--font-heading);
+ font-size: var(--text-base);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.428;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-4);
+ margin-bottom: var(--spacing-2);
+ }
+
+ .xds-typography--editorial h6 {
+ font-family: var(--font-heading);
+ font-size: var(--text-xsm);
+ font-weight: var(--font-weight-semibold);
+ line-height: 1.333;
+ color: var(--color-text-primary);
+ margin-top: var(--spacing-3);
+ margin-bottom: var(--spacing-2);
+ }
+
+ /* ===========================================================================
+ Prose Styles
+ =========================================================================== */
+
+ .xds-typography p {
+ margin-top: 0;
+ margin-bottom: var(--spacing-3);
+ }
+
+ .xds-typography ul,
+ .xds-typography ol {
+ margin-top: 0;
+ margin-bottom: var(--spacing-3);
+ padding-inline-start: var(--spacing-5);
+ }
+
+ .xds-typography li {
+ margin-bottom: var(--spacing-1);
+ }
+
+ .xds-typography li:last-child {
+ margin-bottom: 0;
+ }
+
+ .xds-typography blockquote {
+ margin-top: 0;
+ margin-bottom: var(--spacing-3);
+ margin-inline-start: 0;
+ margin-inline-end: 0;
+ padding-inline-start: var(--spacing-4);
+ border-inline-start: 3px solid var(--color-divider-emphasized);
+ color: var(--color-text-secondary);
+ font-style: italic;
+ }
+
+ .xds-typography code {
+ font-family: var(--font-code);
+ font-size: 0.9em;
+ background-color: var(--color-wash);
+ padding-block: var(--spacing-0-5);
+ padding-inline: var(--spacing-1);
+ border-radius: var(--radius-content);
+ }
+
+ .xds-typography pre {
+ font-family: var(--font-code);
+ font-size: var(--text-sm);
+ line-height: 1.5;
+ margin-top: 0;
+ margin-bottom: var(--spacing-3);
+ padding: var(--spacing-3);
+ background-color: var(--color-wash);
+ border-radius: var(--radius-element);
+ overflow: auto;
+ white-space: pre;
+ }
+
+ .xds-typography pre code {
+ background-color: transparent;
+ padding: 0;
+ border-radius: 0;
+ font-size: inherit;
+ }
+
+ .xds-typography hr {
+ margin-block: var(--spacing-4);
+ border: none;
+ border-top: 1px solid var(--color-divider);
+ }
+
+ .xds-typography strong,
+ .xds-typography b {
+ font-weight: var(--font-weight-semibold);
+ }
+
+ .xds-typography a {
+ color: var(--color-text-link);
+ text-decoration: underline;
+ text-underline-offset: 2px;
+ }
+
+ .xds-typography a:hover {
+ text-decoration-thickness: 2px;
+ }
+
+ /* ===========================================================================
+ Spacing Utilities
+ =========================================================================== */
+
+ /* Remove top margin from first child */
+ .xds-typography > :first-child {
+ margin-top: 0;
+ }
+
+ /* Remove bottom margin from last child */
+ .xds-typography > :last-child {
+ margin-bottom: 0;
+ }
+}