[Suggestion][QoL] Add a rhythm property to FlexProps
See original GitHub issuerhythm
is an idea I’ve used in the past to describe containers that kept identical spacing between their children. As an example, the phrase “with an 8-pixel vertical rhythm” means that items in the vertical list were separated vertically by 8 pixels.
I’ve usually implemented this idea with a set of rhythm-$direction-$spacing
CSS classes that would be applied to Flex containers like this:
<div className="flex-column rhythm-vertical-8>{...children}</div>
These classes do the following (SCSS):
& > :not(:firstChild) {
margin-top: $spacing; // margin-left for horizontal
}
Given that Primer’s Flex
component has flexDirection
as a prop, exposing a rhythm
prop would allow Flex
to automatically generate the appropriate classes.
This paradigm allows for a few things:
- Use of components that don’t actually have any
margin
props exposed without having to manage the margins of elements around them (eg. putting an SVG between twoText
elements is currently a tiny bit painful if you want any spacing) - Less duplication of
mr={2}
on child components for these kinds of scenarios
I’m not sure if this is a thing that’s in keeping with the Primer design system, or necessarily something that Primer wants to support as a first-class idea, but I’ve found a notion of this handy in the past and wanted to float it as an idea.
If this is something Primer wants to support, I’m happy to spend an hour or two this weekend opening a pull-request for it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (19 by maintainers)
Top GitHub Comments
👆 This funky-looking selector tells CSS to select any element that immediately follows a direct child of the flex container:
It’s a combination of a child combinator (
>
), adjacent sibling combinator (+
), and universal selectors (*
) if you’re interested in reading more.I think I found a simple way to implement this with just CSS:
CodeSandbox demo
This implementation allows children to override the margin without needing any special logic 😄
Update: Playing with this component in CodeSandbox makes me really want it in Primer Components now haha