Skip to content

Commit

Permalink
feat: Allow small and large vertical whitespace on grids (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga authored Nov 29, 2023
1 parent 4c25f43 commit aa54eb9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/css/src/grid/grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
--amsterdam-grid-padding-inline: var(--amsterdam-grid-compact-padding-inline);
}

.amsterdam-grid--gap-vertical--small {
row-gap: calc(var(--amsterdam-grid-gap) / 2);
}

.amsterdam-grid--gap-vertical--large {
row-gap: calc(var(--amsterdam-grid-gap) * 2);
}

.amsterdam-grid--padding-bottom--small {
padding-block-end: calc(var(--amsterdam-grid-gap) / 2);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/Grid/Grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ describe('Grid', () => {
expect(component).toHaveClass('amsterdam-grid--padding-bottom--large')
})

it('renders a class name for a vertical gap', () => {
const { container } = render(<Grid gapVertical="large" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--gap-vertical--large')
})

it('renders a class name for a vertical gap and a vertical padding', () => {
const { container } = render(<Grid gapVertical="small" paddingVertical="large" />)
const component = container.querySelector(':only-child')
expect(component).toHaveClass('amsterdam-grid--gap-vertical--small amsterdam-grid--padding-vertical--large')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLDivElement>()
const { container } = render(<Grid ref={ref} />)
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export type GridProps = {
* @todo Implement more generally – it will be moved into a theme soon.
*/
compact?: boolean
/** The amount of vertical whitespace between rows of the grid. */
gapVertical?: 'small' | 'large'
} & (GridPaddingVerticalProp | GridPaddingTopAndBottomProps) &
PropsWithChildren<HTMLAttributes<HTMLDivElement>>

Expand Down Expand Up @@ -78,7 +80,7 @@ interface GridComponent extends ForwardRefExoticComponent<GridProps & RefAttribu

export const Grid = forwardRef(
(
{ children, className, compact, paddingBottom, paddingTop, paddingVertical, ...restProps }: GridProps,
{ children, className, compact, gapVertical, paddingBottom, paddingTop, paddingVertical, ...restProps }: GridProps,
ref: ForwardedRef<HTMLDivElement>,
) => (
<div
Expand All @@ -87,6 +89,7 @@ export const Grid = forwardRef(
className={clsx(
'amsterdam-grid',
compact && `amsterdam-grid--compact`,
gapVertical && `amsterdam-grid--gap-vertical--${gapVertical}`,
paddingClasses(paddingBottom, paddingTop, paddingVertical),
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion storybook/storybook-react/src/Footer/Footer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Default: Story = {
<VisuallyHidden>
<Heading>Colofon</Heading>
</VisuallyHidden>
<Grid paddingVertical="medium">
<Grid gapVertical="large" paddingVertical="medium">
<Grid.Cell span={3}>
<div style={{ display: 'grid', gap: '2.5rem' }}>
<Heading level={2} size="level-4" inverseColor>
Expand Down
9 changes: 9 additions & 0 deletions storybook/storybook-react/src/Grid/Grid.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ Elke cel biedt ruimte voor een afbeelding.

<Canvas of={GridStories.Cells} />

### Verticale witruimte

Een grid maakt automatisch meerdere rijen als de eerstvolgende cel niet meer op de huidige rij past.

Standaard zit tussen twee rijen evenveel witruimte als tussen twee kolommen.
In sommige gevallen kan daar beter meer of minder witruimte staan.

<Canvas of={GridStories.VerticalGap} />

Voor meer voorbeelden raadpleeg je [Grid Cell](?path=/docs/react_layout-grid-cell--docs) zelf.
20 changes: 20 additions & 0 deletions storybook/storybook-react/src/Grid/Grid.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ export const VerticalSpace: Story = {
compact: false,
paddingVertical: 'medium',
},
name: 'Verticale marge',
}

export const VerticalGap: Story = {
...StoryTemplate,
args: {
children: Array.from(Array(6).keys()).map((i) => (
<Grid.Cell className="amsterdam-docs-pink-box" span={4} key={i} />
)),
gapVertical: 'small',
},
argTypes: {
gapVertical: {
control: {
type: 'radio',
labels: { small: 'small', undefined: 'medium', large: 'large' },
},
options: ['small', undefined, 'large'],
},
},
name: 'Verticale witruimte',
}

Expand Down

0 comments on commit aa54eb9

Please sign in to comment.