-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Stack component #2152
Merged
Add Stack component #2152
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 2795894 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
langermank
approved these changes
Jul 25, 2022
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
This PR adds the
Stack
component to Primer CSS.Overview
This is the first Layout helper component1 to be designed and implemented following the new Responsive API design guidelines2.
Layout helper components have been proposed as a way to reduce our dependency on utilities, make it easier to implement responsive design, and support the new Primer Primitives design tokens.
Layout helper components are designed in a platform-agnostic way. They will be available to both Primer ViewComponents and Primer React with the same behavior and API.
Features
Stack
makes it easy to group elements that follow a same direction (vertically or horizontally), with spacing gap, optional dividers, and optional wrapping.Responsive by design
All properties from this component are responsive, meaning different values can be passed depending on the viewport range.
For example, a
Stack
direction
can be set toinline
(horizontal) onnarrow
, andblock
(vertical) ondesktop
.In CSS, we use
-whenNarrow
,-whenRegular
, and-whenWide
suffixes to target modifier classes to a specific range. This is how the team is planning to support any responsive properties going forward.More information about viewport ranges can be found here (only available for Hubbers, documentation to be made public in a future PR).
Alignment and distribution of stacking elements
Stack
also allows aligning elements without relying on difficult Flexbox property names (align-items
,justify-content
, andalign-content
). For that, it uses simpler concepts such asalign
andspread
(described in the Properties section below).Note on using inline Stack for buttons
Properties
Stack
has the following properties:direction
Sets how elements inside
Stack
are placed, either horizontally (inline
) or vertically (block
). This property follows the writing mode.gap
Sets the spacing gap between items. All sizes use design tokens from the new Primer Primitives'
UI Stack
pattern.Values:
none
:0
condensed
:var(--primer-stack-gap-condensed, 8px)
,normal
:var(--primer-stack-gap-normal, 16px)
(default)spacious
:var(--primer-stack-gap-spacious, 24px)
(on regular viewports, otherwise it appears asnormal
on narrow viewports)Custom values are not supported for now.
align
Sets the alignment between items in the cross-axis of the specified direction. For example:
direction
is set toblock
(stacks vertically), it controls the horizontal alignment (left, center, right).direction
is set toinline
(stacks horizontally), it controls the vertical alignment (top, center, bottom).This property behavior is equivalent to the
align-items
Flexbox property.Values:
stretch
(default)start
center
end
baseline
alignWrap
Sets how stack lines are distributed, if they
wrap
into multiple lines. This has equivalent behavior to thealign-content
Flexbox property.(Most instances of
Stack
shouldn't require this property)Values:
start
(default)center
end
distribute
(equivalent behavior to Flexbox'sspace-between
)distributeEvenly
(equivalent behavior to Flexbox'sspace-evenly
)spread
Sets how items will be distributed in the stacking direction.
Values:
start
(default)center
end
distribute
(equivalent behavior to Flexbox'sspace-between
)distributeEvenly
(equivalent behavior to Flexbox'sspace-evenly
)wrap
Sets whether items are forced onto one line or can wrap onto multiple lines.
Values:
wrap
nowrap
(default)showDividers
Boolean. Whether dividers are present between items or not.
Note: dividers are not compatible in wrapping stacks.
Note 2: the presence of a divider duplicates the
gap
between items.dividerAriaRole
Sets which ARIA role will be used for the divider.
Values:
presentation
(default)separator
Structure
Storybook
You can play with
Stack
in Storybook. By default it comes with_debug
set to true, so you can see how the elements are positioned.✨ Link to Storybook ✨
Can these changes ship as is?
Footnotes
Discussion on Layout helper components (only available for Hubbers) ↩
Responsive API design guidelines ADR (only available for hubbers, but content will be made public in a future PR) ↩