Repository navigation
Description
Problem
Themes can currently override internal CSS variable names to adjust component spacing. The neutral theme does this for Card and Section:
// neutralTheme.ts — reaches into internal implementation details
card: {
base: {
"--layout-padding-inner-x": "var(--spacing-3)",
"--layout-padding-inner-y": "var(--spacing-3)",
"--layout-padding-outer-x": "var(--spacing-3)",
"--layout-padding-outer-y": "var(--spacing-3)",
},
},These --layout-padding-* variables are internal implementation details of the Layout system, not public tokens. If core renames them, themes break silently.
Two things need to happen
1. Close the hole — make internal vars inaccessible to themes
Internal CSS variables like --layout-padding-inner-x, --container-padding, --component-padding-inline, --edge-start/--edge-end should be scoped using stylex.defineVars so themes cannot override them by name. They are implementation details of the edge compensation and layout systems.
2. Open a proper door — expose public container padding tokens
Add formal tokens that themes can legitimately override:
// In tokens.stylex.ts
export const layoutDefaults = {
"--layout-padding": "16px", // default container content padding
// potentially more granular:
// "--layout-padding-x": "16px",
// "--layout-padding-y": "16px",
};
export const layoutVars = stylex.defineVars(layoutDefaults);Layout components (Card, Section, LayoutContent, LayoutPanel, etc.) would read from these public tokens as their defaults, then use internal vars for the inner/outer split and edge compensation mechanics.
The neutral theme would then override the public token:
// Clean: overrides a public token
defineTheme(layoutVars, {
"--layout-padding": "var(--spacing-3)", // 12px
})Context
Found during spacing audit for issue #839. The neutral theme's current approach works but creates fragile coupling. This is a prerequisite for a clean density system — density="compact" on XDSTheme would adjust these public tokens, which then propagate through the layout system via the internal vars.
Related
- RFC: Density System — Theme-level + Nestable Density Provider #839 — Density System RFC
- Edge compensation system (
Layout/edgeCompensation.stylex.ts) — internal vars should stay internal
Activity
cixzhang commentedon Mar 24, 2026
Update: after reading the theme infrastructure docs, the right approach here is component-specific tokens via the existing component override system — not new global tokens.
The theme system already supports component overrides via module augmentation:
So Card, Section, and Layout should expose their padding through this system. The neutral theme would then use the proper component override API:
Two things still need to happen:
--layout-padding-inner-x, etc.) should be scoped viastylex.defineVarsso themes can't override them by nameThis also sets up cleanly for the density prop on XDSTheme —
density="compact"could adjust the component-level padding tokens that components read as their defaults.— drafted with Navi
fix(theme): formalize container padding tokens, prevent internal var …
docs: document --xds-container-padding public API for theme overrides
fix(theme): formalize container padding tokens, prevent internal var …
fix(theme): formalize container padding tokens, prevent internal var …
fix(theme): formalize container padding tokens, prevent internal var …