From aa54eb911bfed633856a74e0be4e11d4ad8f3ebc Mon Sep 17 00:00:00 2001 From: Vincent Smedinga Date: Wed, 29 Nov 2023 14:21:01 +0100 Subject: [PATCH] feat: Allow small and large vertical whitespace on grids (#821) --- packages/css/src/grid/grid.scss | 8 ++++++++ packages/react/src/Grid/Grid.test.tsx | 12 +++++++++++ packages/react/src/Grid/Grid.tsx | 5 ++++- .../src/Footer/Footer.stories.tsx | 2 +- .../storybook-react/src/Grid/Grid.docs.mdx | 9 +++++++++ .../storybook-react/src/Grid/Grid.stories.tsx | 20 +++++++++++++++++++ 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/packages/css/src/grid/grid.scss b/packages/css/src/grid/grid.scss index a739516ce9..c9c2728caa 100644 --- a/packages/css/src/grid/grid.scss +++ b/packages/css/src/grid/grid.scss @@ -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); } diff --git a/packages/react/src/Grid/Grid.test.tsx b/packages/react/src/Grid/Grid.test.tsx index 4644bf73d2..01198dec8b 100644 --- a/packages/react/src/Grid/Grid.test.tsx +++ b/packages/react/src/Grid/Grid.test.tsx @@ -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() + 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() + 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() const { container } = render() diff --git a/packages/react/src/Grid/Grid.tsx b/packages/react/src/Grid/Grid.tsx index 78cc7eea44..3461c65f4b 100644 --- a/packages/react/src/Grid/Grid.tsx +++ b/packages/react/src/Grid/Grid.tsx @@ -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> @@ -78,7 +80,7 @@ interface GridComponent extends ForwardRefExoticComponent, ) => (
Colofon - +
diff --git a/storybook/storybook-react/src/Grid/Grid.docs.mdx b/storybook/storybook-react/src/Grid/Grid.docs.mdx index 566409d41d..d456363419 100644 --- a/storybook/storybook-react/src/Grid/Grid.docs.mdx +++ b/storybook/storybook-react/src/Grid/Grid.docs.mdx @@ -52,4 +52,13 @@ Elke cel biedt ruimte voor een afbeelding. +### 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. + + + Voor meer voorbeelden raadpleeg je [Grid Cell](?path=/docs/react_layout-grid-cell--docs) zelf. diff --git a/storybook/storybook-react/src/Grid/Grid.stories.tsx b/storybook/storybook-react/src/Grid/Grid.stories.tsx index 6d4e4763ba..72e65e1541 100644 --- a/storybook/storybook-react/src/Grid/Grid.stories.tsx +++ b/storybook/storybook-react/src/Grid/Grid.stories.tsx @@ -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) => ( + + )), + gapVertical: 'small', + }, + argTypes: { + gapVertical: { + control: { + type: 'radio', + labels: { small: 'small', undefined: 'medium', large: 'large' }, + }, + options: ['small', undefined, 'large'], + }, + }, name: 'Verticale witruimte', }