Skip to content
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
merged 26 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b7e2715
Add Stack component
vdepizzol Jul 12, 2022
5da8ba6
Stylelint auto-fixes
actions-user Jul 12, 2022
93c00bc
Ongoing Stack component implementation
vdepizzol Jul 12, 2022
98a52a5
Add Stack dividers, responsive props, examples
vdepizzol Jul 12, 2022
8b08722
Implement align, alignWrap, and spread props
vdepizzol Jul 13, 2022
51df24d
Code cleanup
vdepizzol Jul 13, 2022
ae6231e
Wrap responsive props under narrow+regular queries
vdepizzol Jul 13, 2022
84b0b11
Fix structure comment
vdepizzol Jul 14, 2022
116b3f9
Address rendering bugs, add docs
vdepizzol Jul 15, 2022
a0a7c9a
typo
vdepizzol Jul 15, 2022
49d1029
Cleanup
vdepizzol Jul 15, 2022
9e7ff3a
typo
vdepizzol Jul 15, 2022
7b1b238
Please stylelint
vdepizzol Jul 15, 2022
b9ca078
Update docs/src/stories/components/Layout/Stack.stories.jsx
vdepizzol Jul 20, 2022
af0e187
Simplify jsx
vdepizzol Jul 22, 2022
e413d30
Simplify Stack CSS, add Stack-item
vdepizzol Jul 22, 2022
9412feb
Add Stack feature stories
vdepizzol Jul 22, 2022
cd52ff6
Stylelint auto-fixes
actions-user Jul 22, 2022
3c2954d
Remove `none` from dividerAriaRole property
vdepizzol Jul 22, 2022
d96dca9
Merge branch 'main' into Stack
vdepizzol Jul 22, 2022
9a49e3a
add wide viewport support
vdepizzol Jul 25, 2022
d605c43
Stylelint auto-fixes
actions-user Jul 25, 2022
c3a9a1a
Add changeset
vdepizzol Jul 25, 2022
7204480
Hide custom gap support
vdepizzol Jul 25, 2022
ecd2e24
Use Sass comments instead
vdepizzol Jul 25, 2022
2795894
Merge branch 'main' into Stack
vdepizzol Jul 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 209 additions & 0 deletions docs/src/stories/components/Layout/Stack.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import React from 'react'
import clsx from 'clsx'

export default {
title: 'Components/Layout/Stack',
excludeStories: ['StackTemplate'],
argTypes: {

// Debug

_debug: {
control: {
type: 'boolean',
},
table: {
category: 'Debug'
},
},

// Direction

direction: {
options: ['inline', 'block'],
control: {
type: 'inline-radio',
},
},
narrow_direction: {
options: ['inline', 'block'],
control: {
type: 'inline-radio',
},
table: {
category: 'Narrow viewport'
},
},

// Gap

gap: {
options: ['none', 'condensed', 'normal', 'spacious', 'custom'],
control: {
type: 'inline-radio',
},
},
narrow_gap: {
options: ['none', 'condensed', 'normal', 'custom'],
control: {
type: 'inline-radio',
},
table: {
category: 'Narrow viewport'
},
},
gap_custom: {
control: {
type: 'string'
},
},
narrow_gap_custom: {
control: {
type: 'string'
},
table: {
category: 'Narrow viewport'
},
},

// Align

align: {
options: ['start', 'center', 'end'],
control: {
type: 'inline-radio'
},
},
narrow_align: {
options: ['start', 'center', 'end'],
control: {
type: 'inline-radio'
},
table: {
category: 'Narrow viewport'
},
},

// Wrap

wrap: {
options: ['wrap', 'nowrap'],
control: {
type: 'inline-radio'
},
},
narrow_wrap: {
options: ['wrap', 'nowrap'],
control: {
type: 'inline-radio'
},
table: {
category: 'Narrow viewport'
},
},

// Divider

divider: {
control: {
type: 'boolean'
},
},
narrow_divider: {
control: {
type: 'boolean'
},
table: {
category: 'Narrow viewport'
},
},
},
};

export const StackTemplate = ({
_debug,
direction,
gap,
gap_custom,
align,
wrap,
divider,

narrow_direction,
narrow_gap,
narrow_gap_custom,
narrow_align,
narrow_wrap,
narrow_divider
}) => {



return (
<>
<div className={clsx(
'Stack',
direction && 'Stack--' + `${direction}`,
gap && 'Stack--' + `${gap}`,
align && 'Stack--' + `${align}`,
wrap && 'Stack--' + `${wrap}`,
)}
>

<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>

{_debug && (
<>
<style type="text/css">{`
.Stack {
background: beige;
}
.Stack > * {
padding: 8px;
border-radius: 6px;
}
.Stack :nth-child(1) {
background: lightblue;
width: 6ch;
}
.Stack :nth-child(2) {
background: coral;
width: 9ch;
}
.Stack :nth-child(3) {
background: darkseagreen;
width: 8ch;
}
.Stack :nth-child(4) {
background: khaki;
width: 7ch;
}
.Stack :nth-child(5) {
background: lightpink;
width: 10ch;
}
.Stack :nth-child(6) {
background: lightsalmon;
width: 6ch;
}
`}</style>
</>
)}
</>
);
};

export const Playground = StackTemplate.bind({})

Playground.args = {
_debug: true,
direction: "block",
gap: "normal",
align: "start",
};
1 change: 1 addition & 0 deletions src/layout/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@import './grid-offset.scss';
@import './layout.scss';
@import './page-layout.scss';
@import './stack.scss';
119 changes: 119 additions & 0 deletions src/layout/stack.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Stack layout helper

.Stack {
--Stack-gap: var(--primer-stack-gap-normal, 16px);
--Stack-gap-whenNarrow: var(--Stack-gap);

display: flex;
flex-flow: column;
vdepizzol marked this conversation as resolved.
Show resolved Hide resolved
gap: var(--Stack-gap);

@media ($viewport-narrow) {
gap: var(--Stack-gap-whenNarrow);
}
}

/* Direction */

.Stack--inline {
vdepizzol marked this conversation as resolved.
Show resolved Hide resolved
flex-flow: row;
}

.Stack--block {
flex-flow: column;
}

@media ($viewport-narrow) {
.Stack--inline-whenNarrow {
flex-flow: row;
}

.Stack--block-whenNarrow {
flex-flow: column;
}
}

/* Gap */

.Stack--none {
--Stack-gap: 0;
}

.Stack--condensed {
--Stack-gap: var(--primer-stack-gap-condensed, 8px);
}

.Stack--normal {
--Stack-gap: var(--primer-stack-gap-normal, 16px);
}

@media ($viewport-regular) {
.Stack--spacious {
--Stack-gap: var(--primer-stack-gap-spacious, 24px);
}
}

@media ($viewport-narrow) {
.Stack--none-whenNarrow {
--Stack-gap-whenNarrow: 0;
}

.Stack--condensed-whenNarrow {
--Stack-gap-whenNarrow: var(--primer-stack-gap-condensed, 8px);
}

.Stack--normal-whenNarrow {
--Stack-gap-whenNarrow: var(--primer-stack-gap-normal, 16px);
}
}

/* Align */

.Stack--start {
align-items: flex-start;
justify-content: flex-start;
}

.Stack--center {
align-items: center;
justify-content: center;
}

.Stack--end {
align-items: flex-end;
justify-content: flex-end;
}

@media ($viewport-narrow) {
.Stack--start-whenNarrow {
align-items: flex-start;
}

.Stack--center-whenNarrow {
align-items: center;
}

.Stack--end-whenNarrow {
align-items: flex-end;
}
}

/* Wrap */

.Stack--wrap {
flex-wrap: wrap;
}

.Stack--nowrap {
flex-wrap: nowrap;
}

@media ($viewport-narrow) {
.Stack--wrap-whenNarrow {
flex-wrap: wrap;
}

.Stack--nowrap-whenNarrow {
flex-wrap: nowrap;
}
}
6 changes: 6 additions & 0 deletions src/support/variables/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ $breakpoints: (
xl: $width-xl
) !default;

// Viewport ranges
// Soon to be provided by Primer Primitives directly
// https://github.com/primer/primitives/blob/main/tokens/functional/size/viewport.json
$viewport-narrow: 'max-width: #{$width-md - 0.02px}' !default;
$viewport-regular: 'min-width: #{$width-md}' !default;

// This map in the form (breakpoint: variant) is used to iterate over
// breakpoints and create both responsive and non-responsive classes in one
// loop:
Expand Down