Skip to content

docs(layout): document Box spacing prop and disambiguate from gap - #2762

Open
dgaponov wants to merge 1 commit into
gravity-ui:mainfrom
dgaponov:docs/layout-box-spacing-prop
Open

dgaponov wants to merge 1 commit into
gravity-ui:mainfrom
dgaponov:docs/layout-box-spacing-prop

Conversation

@dgaponov

@dgaponov dgaponov commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Motivation

The layout guide (docs/layout.md) implied Flex/Box only expose gap for spacing. Per the installed source that is incorrect:

  • Box (src/components/layout/Box/Box.tsx) has no gap — it has a spacing prop for the element's own margins/paddings.
  • Flex (src/components/layout/Flex/Flex.tsx) extends BoxProps, so it inherits spacing and adds gap/gapRow/space for spacing between children.

As a result, the spacing prop of Box was effectively undocumented.

Changes

  • "Ways to apply spacing" → item feat: setup build #1 — split into two distinct props:
    • gap/gapRow (Flex only) — spacing between children;
    • spacing (Box, inherited by Flex) — the element's own margins/paddings.
      Added an example (<Box spacing={{mr: 3, pb: 2}}>) and a link to the shortcut key table.
  • ## Box section — added a Props block documenting spacing (plus as, overflow, the size/position props), with a note that Box has no gap and that Flex also accepts spacing.
  • "Rule of thumb" — updated to reflect the actual gap vs spacing split.
  • Added an anchor heading so the new #the-spacing-utility link resolves.

Docs-only change; no code touched.

Summary by Sourcery

Clarify layout spacing documentation for Box and Flex by distinguishing element-level spacing from inter-child gaps.

Documentation:

  • Document the Box spacing prop as distinct from Flex gap/gapRow, including usage examples and supported shortcut keys.
  • Add a Box props overview section covering spacing, structural props like as, and size/overflow-related props, with notes on Flex inheritance and Box lacking gap.

The layout guide implied `Box` only exposes `gap`, but per the installed
source `Box` has no `gap` — it has a `spacing` prop for the element's own
margins/paddings. `Flex` extends `BoxProps`, so it inherits `spacing` and
adds `gap`/`gapRow` for spacing between children.

- Split the "Ways to apply spacing" item gravity-ui#1 into `gap` (Flex, between
  children) and `spacing` (Box, element itself), with an example and a link
  to the shortcut key table.
- Add a Props block to the `## Box` section documenting `spacing` (plus
  `as`, `overflow`, size props) with a note that `Box` has no `gap`.
- Update the "Rule of thumb" summary to match the actual gap/spacing split.
- Add an anchor heading so the new "#the-spacing-utility" link resolves.
@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Updates the layout documentation to clearly distinguish Box’s spacing prop from Flex’s gap-style props, documents Box’s core props, and adds an anchor for the spacing utility section so examples and guidance align with the actual API.

File-Level Changes

Change Details Files
Clarified the spacing story for layout primitives by splitting and explaining Flex-only gap/gapRow (between children) vs Box/Flex spacing (own margins/paddings), with examples.
  • Reworded the "Component props" section to describe two spacing props instead of a single gap prop.
  • Documented gap/gapRow as Flex-only props used for spacing between children, with a code sample.
  • Documented spacing as a Box (and inherited Flex) prop used for the element’s own margins/paddings, including a Box code example and reference to the spacing utility key table.
docs/layout.md
Improved guidance on when to use gap vs spacing vs the spacing utility by updating the rule-of-thumb blockquote.
  • Changed the rule-of-thumb text to say gap applies to spacing between siblings inside a Flex.
  • Clarified that the spacing prop (or spacing utilities) are for an element’s own margins/paddings.
  • Kept the recommendation to use spacing scale steps instead of hard-coded pixels.
docs/layout.md
Expanded Box component documentation to list its key props, including spacing, and explicitly note that Box has no gap prop while Flex extends Box and accepts spacing.
  • Added a Box Props list covering as, spacing, overflow, and core size/position props sourced from React.CSSProperties.
  • Explained the relationship between Box’s spacing and Flex’s gap, emphasizing that gap is for between-children spacing and spacing is for the element itself.
  • Added a Box usage example showing spacing combined with width/height props.
  • Added a note that Box does not have a gap prop and that Flex, as an extension of Box, also accepts spacing.
docs/layout.md
Introduced an anchor heading for the spacing utility to support in-page linking from the new spacing prop docs.
  • Inserted a "The spacing utility" heading before the spacing utility description so the #the-spacing-utility anchor exists.
  • Ensured the earlier reference to the key table under the spacing utility resolves to this heading.
docs/layout.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The link text [SpacingProps](#the-spacing-utility) may be confusing since the anchor points to a "The spacing utility" heading rather than an explicitly named SpacingProps section; consider either renaming the heading or adjusting the link text to better match the target.
  • The new "##### The spacing utility" subheading sits directly under the numbered "The spacing() utility" section and feels redundant; you could drop the extra heading and instead use an explicit HTML anchor to keep the link target without introducing another heading level.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The link text `[`SpacingProps`](#the-spacing-utility)` may be confusing since the anchor points to a "The `spacing` utility" heading rather than an explicitly named `SpacingProps` section; consider either renaming the heading or adjusting the link text to better match the target.
- The new "##### The `spacing` utility" subheading sits directly under the numbered "The `spacing()` utility" section and feels redundant; you could drop the extra heading and instead use an explicit HTML anchor to keep the link target without introducing another heading level.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gravity-ui

gravity-ui Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Preview is ready.

@gravity-ui

gravity-ui Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

🎭 Component Tests Report is ready.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant