Skip to content

feat: numeric spacing API for gap and padding props - #536

Merged
cixzhang merged 1 commit into
mainfrom
navi/feat/numeric-spacing-api
Mar 8, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/feat/numeric-spacing-api

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Introduces a numeric spacing scale for the gap and padding props across layout components. This replaces string tokens ('space0' through 'space10') with numeric values (0 through 10) for a more intuitive API.

SpacingStep type

type SpacingStep = 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10;

Maps to CSS spacing tokens: 0 = 0px, 0.5 = 2px, 1 = 4px, 1.5 = 6px, 2 = 8px, 3 = 12px, 4 = 16px, 5 = 20px, 6 = 24px, 8 = 32px, 10 = 40px.

Changes

1. Numeric gap on Stack and Grid

Before: <XDSStack gap="space4"> / <XDSGrid gap="space4">
After: <XDSStack gap={4}> / <XDSGrid gap={4}>

  • String tokens still work (deprecated, backward compat)
  • Same for rowGap and columnGap on Grid
  • Added SpacingStep type exported from @xds/core/Layout
  • Added --spacing-1-5 (6px) token to theme

2. Numeric padding on layout components

Added padding?: SpacingStep to:

  • XDSCard (default: 4 = 16px)
  • XDSSection (default: 4 = 16px)
  • XDSLayout (controls --layout-padding-outer-x/y)
  • XDSLayoutContent
  • XDSLayoutHeader
  • XDSLayoutFooter
  • XDSLayoutPanel

isFullBleed is deprecated with @deprecated Use padding={0} instead JSDoc on all layout components. XDSDivider's isFullBleed is NOT touched — it uses negative margins for a different purpose.

3. Codemods

Two new codemods in packages/cli/src/codemods/transforms/v0.0.2/:

  • migrate-gap-to-numeric: gap="space4" → gap={4}
  • migrate-isFullBleed-to-padding: isFullBleed → padding={0}

27 tests covering both codemods.

4. Stories and docs

All stories and doc files updated to use numeric gap values. Doc files updated with new prop types and descriptions.

Files changed (64)

Category Files
Core types utils/types.ts, theme/tokens.stylex.ts
Stack stack.stylex.ts, XDSStack.tsx, XDSHStack.tsx, XDSVStack.tsx, XDSStackItem.tsx
Grid XDSGrid.tsx, XDSGridSpan.tsx
Layout padding.stylex.ts (new), container.stylex.ts, index.ts, XDSLayout.tsx, XDSLayoutContent.tsx, XDSLayoutHeader.tsx, XDSLayoutFooter.tsx, XDSLayoutPanel.tsx
Card/Section XDSCard.tsx, XDSSection.tsx
Codemods 2 transforms + 2 test files + index update
Stories 14 story files
Docs 7 doc files
Examples 3 example app files

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 8, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review

Architecture

  • SpacingStep type lives in utils/types.ts and is re-exported through Layout/index.ts and Stack/stack.stylex.ts
  • padding.stylex.ts is a new shared utility providing StyleX styles for the numeric padding prop, including --container-padding-inline and --layout-padding-outer-x/y CSS variable styles
  • Backward compat: Old string SpacingScale type is kept with @deprecated JSDoc. Both numeric and string values are accepted via resolveGapKey()

Key decisions

  1. isFullBleed maps to padding={0} internally — when both are set, padding wins (explicit padding takes precedence)
  2. Divider's isFullBleed is untouched — it uses negative margins for a fundamentally different purpose
  3. Added --spacing-1-5 (6px) to theme — required by the SpacingStep scale but was missing from the token set
  4. Container system integration: When padding is set, the container CSS variables are updated to match, so edge compensation and layout padding variables stay in sync

Test results

  • ✅ 89 test files, 1428 tests passing
  • ✅ Build passes (core + themes)
  • ✅ Lint passes (0 errors, only pre-existing warnings)
  • ✅ 27 codemod tests covering both transforms

@github-actions

github-actions Bot commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Card · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 233B N/A
Lines of Code N/A 115 -
Complexity N/A Medium (11) -
Collapsible · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 4.7KB N/A
Lines of Code N/A 239 -
Complexity N/A High (18) -
Grid · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 199B N/A
Lines of Code N/A 376 -
Complexity N/A High (23) -
Layout · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1023B N/A
Lines of Code N/A 899 -
Complexity N/A Very High (71) -
Section · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 239B N/A
Lines of Code N/A 152 -
Complexity N/A High (17) -
Spinner · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 175B N/A
Lines of Code N/A 109 -
Complexity N/A Medium (8) -
Stack · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 287B N/A
Lines of Code N/A 391 -
Complexity N/A Low (3) -
Table · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 863B N/A
Lines of Code N/A 845 -
Complexity N/A Very High (54) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 9.1KB 14.7KB 2.3KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

XDSLayout - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/10 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Component Previews

Includes interactive hover previews as animated GIFs.

XDSCard

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · layout-xdscard--default

With Simple Content

Screenshot:

With Simple Content

View in Storybook · layout-xdscard--with-simple-content

With Inner Layout

Screenshot:

With Inner Layout

View in Storybook · layout-xdscard--with-inner-layout

Sizes

Screenshot:

Sizes

View in Storybook · layout-xdscard--sizes

Fixed Height

Screenshot:

Fixed Height

View in Storybook · layout-xdscard--fixed-height

Nested Cards

Screenshot:

Nested Cards

View in Storybook · layout-xdscard--nested-cards

Nested Sections

Screenshot:

Nested Sections

View in Storybook · layout-xdscard--nested-sections

Single Section

Screenshot:

Single Section

View in Storybook · layout-xdscard--single-section

Mixed Content

Screenshot:

Mixed Content

View in Storybook · layout-xdscard--mixed-content

Full Bleed

Screenshot:

Full Bleed

View in Storybook · layout-xdscard--full-bleed

On Backgrounds

Screenshot:

On Backgrounds

View in Storybook · layout-xdscard--on-backgrounds

XDSCollapsible

Single Mode (default)

Screenshot:

Single Mode (default)

Interaction Preview: (view video)

Single Mode (default) interaction

View in Storybook · components-xdscollapsible--single-mode

Multiple Mode

Screenshot:

Multiple Mode

View in Storybook · components-xdscollapsible--multiple-mode

Controlled

Screenshot:

Controlled

View in Storybook · components-xdscollapsible--controlled

Standalone Collapsible

Screenshot:

Standalone Collapsible

View in Storybook · components-xdscollapsible--standalone-collapsible

Without Card (standalone)

Screenshot:

Without Card (standalone)

View in Storybook · components-xdscollapsible--without-card

FAQ Page

Screenshot:

FAQ Page

View in Storybook · components-xdscollapsible--faq

XDSGrid

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · layout-xdsgrid--default

Fixed Columns

Screenshot:

Fixed Columns

View in Storybook · layout-xdsgrid--fixed-columns

Responsive Auto Fit

Screenshot:

Responsive Auto Fit

View in Storybook · layout-xdsgrid--responsive-auto-fit

Capped Responsive

Screenshot:

Capped Responsive

View in Storybook · layout-xdsgrid--capped-responsive

With Grid Span

Screenshot:

With Grid Span

View in Storybook · layout-xdsgrid--with-grid-span

Grid Span With Rows

Screenshot:

Grid Span With Rows

View in Storybook · layout-xdsgrid--grid-span-with-rows

Gallery Example

Screenshot:

Gallery Example

View in Storybook · layout-xdsgrid--gallery-example

Different Gaps

Screenshot:

Different Gaps

View in Storybook · layout-xdsgrid--different-gaps

Dashboard Layout

Screenshot:

Dashboard Layout

View in Storybook · layout-xdsgrid--dashboard-layout

XDSLayout

Playground

Screenshot:

Playground

Interaction Preview: (view video)

Playground interaction

View in Storybook · layout-xdslayout--playground

Basic Card Layout

Screenshot:

Basic Card Layout

View in Storybook · layout-xdslayout--basic-card

Layout with Sidebar

Screenshot:

Layout with Sidebar

View in Storybook · layout-xdslayout--with-sidebar

Dual Panel Layout

Screenshot:

Dual Panel Layout

View in Storybook · layout-xdslayout--dual-panels

Without Dividers

Screenshot:

Without Dividers

View in Storybook · layout-xdslayout--no-dividers

Full Bleed Content

Screenshot:

Full Bleed Content

View in Storybook · layout-xdslayout--full-bleed-content

Section Variants

Screenshot:

Section Variants

View in Storybook · layout-xdslayout--section-variants

Content Only

Screenshot:

Content Only

View in Storybook · layout-xdslayout--content-only

Themed Layout (Neutral vs Default)

Screenshot:

Themed Layout (Neutral vs Default)

View in Storybook · layout-xdslayout--themed-layout

Outer Padding Demonstration

Screenshot:

Outer Padding Demonstration

View in Storybook · layout-xdslayout--outer-padding-demo

XDSSection

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · layout-xdssection--default

Variants

Screenshot:

Variants

View in Storybook · layout-xdssection--variants

With Simple Content

Screenshot:

With Simple Content

View in Storybook · layout-xdssection--with-simple-content

With Inner Layout

Screenshot:

With Inner Layout

View in Storybook · layout-xdssection--with-inner-layout

Page Layout

Screenshot:

Page Layout

View in Storybook · layout-xdssection--page-layout

Full Bleed

Screenshot:

Full Bleed

View in Storybook · layout-xdssection--full-bleed

XDSSpinner

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdsspinner--default

Sizes

Screenshot:

Sizes

View in Storybook · core-xdsspinner--sizes

Shades

Screenshot:

Shades

View in Storybook · core-xdsspinner--shades

In Context

Screenshot:

In Context

View in Storybook · core-xdsspinner--in-context

XDSStack

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · layout-xdsstack--default

Horizontal

Screenshot:

Horizontal

View in Storybook · layout-xdsstack--horizontal

Vertical

Screenshot:

Vertical

View in Storybook · layout-xdsstack--vertical

Horizontal Alignments

Screenshot:

Horizontal Alignments

View in Storybook · layout-xdsstack--horizontal-alignments

Vertical Alignments

Screenshot:

Vertical Alignments

View in Storybook · layout-xdsstack--vertical-alignments

Wrapping

Screenshot:

Wrapping

View in Storybook · layout-xdsstack--wrapping

Stack Item Fill Size

Screenshot:

Stack Item Fill Size

View in Storybook · layout-xdsstack--stack-item-fill-size

Stack Item Equal Fill

Screenshot:

Stack Item Equal Fill

View in Storybook · layout-xdsstack--stack-item-equal-fill

Stack Item Cross Align Self

Screenshot:

Stack Item Cross Align Self

View in Storybook · layout-xdsstack--stack-item-cross-align-self

Header Layout

Screenshot:

Header Layout

View in Storybook · layout-xdsstack--header-layout

Sidebar Layout

Screenshot:

Sidebar Layout

View in Storybook · layout-xdsstack--sidebar-layout

Page Layout

Screenshot:

Page Layout

View in Storybook · layout-xdsstack--page-layout

XDSTable

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdstable--default

Compact

Screenshot:

Compact

View in Storybook · core-xdstable--compact

Spacious

Screenshot:

Spacious

View in Storybook · core-xdstable--spacious

Striped With Hover

Screenshot:

Striped With Hover

View in Storybook · core-xdstable--striped-with-hover

Grid Dividers

Screenshot:

Grid Dividers

View in Storybook · core-xdstable--grid-dividers

Column Dividers

Screenshot:

Column Dividers

View in Storybook · core-xdstable--column-dividers

No Dividers

Screenshot:

No Dividers

View in Storybook · core-xdstable--no-dividers

Auto Columns

Screenshot:

Auto Columns

View in Storybook · core-xdstable--auto-columns

Custom Cell Renderer

Screenshot:

Custom Cell Renderer

View in Storybook · core-xdstable--custom-cell-renderer

Children Mode

Screenshot:

Children Mode

View in Storybook · core-xdstable--children-mode

All Densities

Screenshot:

All Densities

View in Storybook · core-xdstable--all-densities

Kitchen Sink

Screenshot:

Kitchen Sink

View in Storybook · core-xdstable--kitchen-sink

Selection

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdstable-selection--default

With Preselection

Screenshot:

With Preselection

View in Storybook · core-xdstable-selection--with-preselection

Non Selectable Rows

Screenshot:

Non Selectable Rows

View in Storybook · core-xdstable-selection--non-selectable-rows

Disabled Rows

Screenshot:

Disabled Rows

View in Storybook · core-xdstable-selection--disabled-rows

Compact

Screenshot:

Compact

View in Storybook · core-xdstable-selection--compact

Spacious

Screenshot:

Spacious

View in Storybook · core-xdstable-selection--spacious

With Striped Rows

Screenshot:

With Striped Rows

View in Storybook · core-xdstable-selection--with-striped-rows


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang
cixzhang force-pushed the navi/feat/numeric-spacing-api branch from cc49e67 to 8781c68 Compare March 8, 2026 16:26
@cixzhang
cixzhang merged commit 6ffc6fd into main Mar 8, 2026
13 checks passed
@cixzhang
cixzhang deleted the navi/feat/numeric-spacing-api branch March 13, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant