Skip to content

feat(Stack): add tight/cozy spacing values and directional padding props#7697

Open
hectahertz wants to merge 3 commits intomainfrom
hectahertz/stack-spacing
Open

feat(Stack): add tight/cozy spacing values and directional padding props#7697
hectahertz wants to merge 3 commits intomainfrom
hectahertz/stack-spacing

Conversation

@hectahertz
Copy link
Contributor

Closes github/primer#6466

Adds two new spacing values (tight at 4px, cozy at 12px) to the gap and padding scales, filling holes in the spacing ramp that were pushing devs toward utility classes or CSS modules. Also adds paddingBlock and paddingInline props for per-axis padding control, and switches the CSS internals from padding shorthand to padding-block + padding-inline longhands so external overrides don't get clobbered.

New spacing scale:

Name Pixels
none 0
tight 4
condensed 8
cozy 12
normal 16
spacious 24

Directional padding: paddingBlock and paddingInline accept the same scale as padding and override their respective axis. padding="normal" paddingInline="spacious" sets block padding to 16px and inline padding to 24px.

Changelog

New

  • gap and padding props now accept 'tight' (4px) and 'cozy' (12px) values
  • paddingBlock prop for block-axis (vertical) padding control
  • paddingInline prop for inline-axis (horizontal) padding control

Changed

  • padding prop CSS internals switched from padding shorthand to padding-block + padding-inline longhands for predictable override behavior

Removed

N/A

Rollout strategy

  • Minor release

Testing & Reviewing

  1. Check the new Storybook stories: Components/Stack/Features/GapScale, PaddingScale, and DirectionalPadding
  2. Verify existing padding prop behavior is unchanged (backward compatible, same visual output)
  3. Verify paddingBlock/paddingInline override the corresponding axis of padding when both are set

Merge checklist

Copilot AI review requested due to automatic review settings March 24, 2026 13:24
@hectahertz hectahertz requested a review from a team as a code owner March 24, 2026 13:24
@hectahertz hectahertz requested a review from liuliu-dev March 24, 2026 13:24
@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: 5d77814

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Mar 24, 2026
@github-actions
Copy link
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds additional spacing options and directional padding controls to Stack, expanding the ergonomics of layout spacing without requiring utility classes/custom CSS.

Changes:

  • Extend Stack gap/padding scales with new values: tight (4px) and cozy (12px).
  • Add paddingBlock and paddingInline props (including responsive support) and emit corresponding data attributes.
  • Switch internal padding styling from padding shorthand to padding-block/padding-inline longhands, plus add new CSS selectors and Storybook feature stories.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react/src/Stack/Stack.tsx Extends spacing union types; adds paddingBlock/paddingInline props and data attributes.
packages/react/src/Stack/Stack.module.css Adds tight/cozy spacing rules; introduces block/inline padding rules and responsive variants; moves to logical longhands.
packages/react/src/Stack/tests/Stack.test.tsx Expands coverage for new scale values and new directional padding props (attribute assertions).
packages/react/src/Stack/Stack.features.stories.tsx Adds feature stories for visual verification of new spacing scales and directional padding behavior.
packages/react/src/Stack/Stack.docs.json Updates prop type strings and documents new props.
.changeset/stack-spacing-options.md Adds changeset for a minor release of @primer/react.

Comment on lines +44 to +51
<Placeholder label='padding="normal" (all sides)' />
</Stack>
<Stack padding="normal" paddingInline="spacious" style={{backgroundColor: 'var(--bgColor-muted)'}}>
<Placeholder label='padding="normal" paddingInline="spacious"' />
</Stack>
<Stack paddingBlock="condensed" paddingInline="spacious" style={{backgroundColor: 'var(--bgColor-muted)'}}>
<Placeholder label='paddingBlock="condensed" paddingInline="spacious"' />
</Stack>
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

JSX uses single-quoted attribute values for label here (e.g. label='padding="normal" …'), which is inconsistent with the repo’s Prettier/JSX formatting and will likely be rewritten by npx prettier --write. Please reformat these to the standard JSX attribute style (e.g. use double quotes with escaping or a {...} string literal) and run Prettier on the file.

Copilot generated this review using guidance from repository custom instructions.
@hectahertz
Copy link
Contributor Author

cc @HiroAgustin @dfosco, this addresses your requests for more Stack spacing options and consistent padding overrides from the thread. Would love your feedback!

Copy link
Contributor

@liuliu-dev liuliu-dev left a comment

Choose a reason for hiding this comment

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

code looks good! ✨

@dfosco
Copy link

dfosco commented Mar 25, 2026

@hectahertz From what you described here this looks great and addresses all of my points from the thread! 🙌

@HiroAgustin
Copy link
Contributor

This is great! Funnily enough: https://github.com/github/github-ui/pull/16820/changes#r2988457348

On top of this it would be nice to expand the hx_utilities gap classes to fill in the missing gaps:

.gap-1pt5 {
  gap: var(--base-size-6) !important;
}

.gap-2pt5 {
  gap: var(--base-size-12) !important;
}

.gap-3pt5 {
  gap: var(--base-size-20) !important;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants