Skip to content

fix(theme): formalize container padding tokens, prevent internal var access - #847

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/formalize-container-padding-tokens
Mar 24, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/fix/formalize-container-padding-tokens

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Introduces --xds-container-padding as the public API for themes to adjust container (Card/Section) padding. Themes no longer need to reference internal --layout-padding-* CSS variables.

Problem

The neutral theme was overriding internal CSS variable names (--layout-padding-inner-x, --layout-padding-inner-y, --layout-padding-outer-x, --layout-padding-outer-y) to adjust Card and Section padding. These are implementation details — if core renames them, themes break silently.

Solution

New public API: --xds-container-padding

Themes set a single CSS custom property in component overrides:

components: {
  card: { base: { '--xds-container-padding': 'var(--spacing-3)' } },
  section: { base: { '--xds-container-padding': 'var(--spacing-3)' } },
}

How it works

  • container.stylex.ts: New useThemeDefault mode cascades all six internal layout vars from --xds-container-padding with --spacing-4 fallback
  • Card and Section: When no explicit padding prop is provided, use theme default mode. When padding is explicitly set, override the theme.
  • Neutral theme: Replaced 4 internal var overrides per component with a single --xds-container-padding override

What stays the same

  • The internal --layout-padding-* vars still power the Layout system's inner/outer padding split
  • Edge compensation system untouched
  • Explicit padding prop on Card/Section still works and overrides the theme
  • All existing behavior preserved

Test plan

  • 1889 tests passing
  • 0 lint errors
  • Neutral theme visual output unchanged (same 12px padding on cards/sections)

Closes #846

…access

Introduces --xds-container-padding as the public API for themes to
adjust container (Card/Section) padding. Themes no longer need to
reference internal --layout-padding-* CSS variables.

Changes:
- container.stylex.ts: Add useThemeDefault mode that cascades internal
  layout vars from --xds-container-padding with --spacing-4 fallback
- XDSCard.tsx: Use theme default when no explicit padding prop
- XDSSection.tsx: Same treatment
- neutralTheme.ts: Replace 4 internal var overrides per component with
  single --xds-container-padding override

The internal --layout-padding-* vars still exist for the Layout system's
inner/outer padding split, but themes interact only with the public
--xds-container-padding property.

Closes #846

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang requested a review from josephfarina as a code owner March 24, 2026 15:40
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 24, 2026
@github-actions

github-actions Bot commented Mar 24, 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 326B N/A
Lines of Code N/A 123 -
Complexity N/A Medium (13) -
Layout · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.1KB N/A
Lines of Code N/A 935 -
Complexity N/A Very High (66) -
Section · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 332B N/A
Lines of Code N/A 179 -
Complexity N/A High (24) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 11.0KB 17.6KB 2.7KB

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 4/10 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

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

@cixzhang

Copy link
Copy Markdown
Contributor Author

This is good but we should think about how documentation reflects this capability for our containers and ensure we have night watch cover this.

@cixzhang
cixzhang merged commit ddf3d5c into main Mar 24, 2026
13 checks passed
cixzhang added a commit that referenced this pull request Mar 24, 2026
Add documentation for the --xds-container-padding CSS custom property
introduced in PR #847. This is the public API for themes to adjust
Card/Section padding, replacing direct access to internal
--layout-padding-* variables.

Updated:
- packages/cli/docs/theme.md — new 'Container Padding Override' section
- packages/cli/docs/tokens.md — new 'Component CSS Custom Properties' section
- packages/core/src/theme/README.md — new component-level CSS properties table

Closes #846
@cixzhang
cixzhang deleted the navi/fix/formalize-container-padding-tokens branch April 9, 2026 14:32
cixzhang added a commit that referenced this pull request Apr 26, 2026
…access (#847)

Introduces --xds-container-padding as the public API for themes to
adjust container (Card/Section) padding. Themes no longer need to
reference internal --layout-padding-* CSS variables.

Changes:
- container.stylex.ts: Add useThemeDefault mode that cascades internal
  layout vars from --xds-container-padding with --spacing-4 fallback
- XDSCard.tsx: Use theme default when no explicit padding prop
- XDSSection.tsx: Same treatment
- neutralTheme.ts: Replace 4 internal var overrides per component with
  single --xds-container-padding override

The internal --layout-padding-* vars still exist for the Layout system's
inner/outer padding split, but themes interact only with the public
--xds-container-padding property.

Closes #846

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
…access (#847)

Introduces --xds-container-padding as the public API for themes to
adjust container (Card/Section) padding. Themes no longer need to
reference internal --layout-padding-* CSS variables.

Changes:
- container.stylex.ts: Add useThemeDefault mode that cascades internal
  layout vars from --xds-container-padding with --spacing-4 fallback
- XDSCard.tsx: Use theme default when no explicit padding prop
- XDSSection.tsx: Same treatment
- neutralTheme.ts: Replace 4 internal var overrides per component with
  single --xds-container-padding override

The internal --layout-padding-* vars still exist for the Layout system's
inner/outer padding split, but themes interact only with the public
--xds-container-padding property.

Closes #846

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
…access (#847)

Introduces --xds-container-padding as the public API for themes to
adjust container (Card/Section) padding. Themes no longer need to
reference internal --layout-padding-* CSS variables.

Changes:
- container.stylex.ts: Add useThemeDefault mode that cascades internal
  layout vars from --xds-container-padding with --spacing-4 fallback
- XDSCard.tsx: Use theme default when no explicit padding prop
- XDSSection.tsx: Same treatment
- neutralTheme.ts: Replace 4 internal var overrides per component with
  single --xds-container-padding override

The internal --layout-padding-* vars still exist for the Layout system's
inner/outer padding split, but themes interact only with the public
--xds-container-padding property.

Closes #846
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.

fix: formalize container padding tokens, prevent theme access to internal CSS vars

1 participant