Repository navigation
feat: numeric spacing API for gap and padding props - #536
Conversation
cixzhang
left a comment
There was a problem hiding this comment.
Self-review
Architecture
- SpacingStep type lives in
utils/types.tsand is re-exported throughLayout/index.tsandStack/stack.stylex.ts - padding.stylex.ts is a new shared utility providing StyleX styles for the numeric padding prop, including
--container-padding-inlineand--layout-padding-outer-x/yCSS variable styles - Backward compat: Old string
SpacingScaletype is kept with@deprecatedJSDoc. Both numeric and string values are accepted viaresolveGapKey()
Key decisions
isFullBleedmaps topadding={0}internally — when both are set,paddingwins (explicit padding takes precedence)- Divider's
isFullBleedis untouched — it uses negative margins for a fundamentally different purpose - Added
--spacing-1-5(6px) to theme — required by the SpacingStep scale but was missing from the token set - Container system integration: When
paddingis 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
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsCard · View in Storybook
Collapsible · View in Storybook
Grid · View in Storybook
Layout · View in Storybook
Section · View in Storybook
Spinner · View in Storybook
Stack · View in Storybook
Table · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. XDSLayout - 1 issue(s)
Component PreviewsIncludes interactive hover previews as animated GIFs. XDSCardXDSCollapsibleSingle Mode (default)Screenshot: Interaction Preview: (view video) View in Storybook · Standalone CollapsibleScreenshot: View in Storybook · XDSGridXDSLayoutPlaygroundScreenshot: Interaction Preview: (view video) View in Storybook · XDSSectionDefaultScreenshot: Interaction Preview: (view video) View in Storybook · XDSSpinnerXDSStackStack Item Cross Align SelfScreenshot: View in Storybook · XDSTableSelectionDefaultScreenshot: Interaction Preview: (view video) View in Storybook · Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cc49e67 to
8781c68
Compare
Summary
Introduces a numeric spacing scale for the
gapandpaddingprops across layout components. This replaces string tokens ('space0'through'space10') with numeric values (0through10) for a more intuitive API.SpacingStep type
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
gapon Stack and GridBefore:
<XDSStack gap="space4">/<XDSGrid gap="space4">After:
<XDSStack gap={4}>/<XDSGrid gap={4}>rowGapandcolumnGapon GridSpacingSteptype exported from@xds/core/Layout--spacing-1-5(6px) token to theme2. Numeric
paddingon layout componentsAdded
padding?: SpacingStepto:--layout-padding-outer-x/y)isFullBleedis deprecated with@deprecated Use padding={0} insteadJSDoc on all layout components. XDSDivider'sisFullBleedis 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)
utils/types.ts,theme/tokens.stylex.tsstack.stylex.ts,XDSStack.tsx,XDSHStack.tsx,XDSVStack.tsx,XDSStackItem.tsxXDSGrid.tsx,XDSGridSpan.tsxpadding.stylex.ts(new),container.stylex.ts,index.ts,XDSLayout.tsx,XDSLayoutContent.tsx,XDSLayoutHeader.tsx,XDSLayoutFooter.tsx,XDSLayoutPanel.tsxXDSCard.tsx,XDSSection.tsx