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

feat: Allow a row to wrap its items onto multiple lines #1319

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/css/src/components/row/row.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
gap: var(--ams-row-gap-#{$size});
}
}

.ams-row--wrap {
flex-wrap: wrap;
}
6 changes: 4 additions & 2 deletions packages/react/src/Row/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export type RowProps = {
as?: RowTag
/** The amount of vertical space between items. */
gap?: RowGap
/** Whether items of the row can wrap onto multiple lines. */
wrap?: Boolean
} & PropsWithChildren<HTMLAttributes<HTMLElement>>

export const Row = forwardRef(
({ as: Tag = 'div', children, className, gap = 'medium', ...restProps }: RowProps, ref: any) => (
<Tag {...restProps} ref={ref} className={clsx('ams-row', `ams-row--${gap}`, className)}>
({ as: Tag = 'div', children, className, gap = 'medium', wrap = false, ...restProps }: RowProps, ref: any) => (
<Tag {...restProps} ref={ref} className={clsx('ams-row', `ams-row--${gap}`, wrap && 'ams-row--wrap', className)}>
{children}
</Tag>
),
Expand Down
8 changes: 7 additions & 1 deletion storybook/src/components/Row/Row.docs.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{/* @license CC0-1.0 */}

import { Controls, Markdown, Meta, Primary } from "@storybook/blocks";
import { Canvas, Controls, Markdown, Meta, Primary } from "@storybook/blocks";
import * as RowStories from "./Row.stories.tsx";
import README from "../../../../packages/css/src/components/row/README.md?raw";

Expand All @@ -23,3 +23,9 @@ Wrap a Row around a set of components that need the same amount of white space b
<Primary />

<Controls />

### Wrapping

Items that may not fit together on a single line should be allowed to wrap onto multiple lines.

<Canvas of={RowStories.Wrapping} />
15 changes: 14 additions & 1 deletion storybook/src/components/Row/Row.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
* Copyright Gemeente Amsterdam
*/

import { Button, Row } from '@amsterdam/design-system-react/src'
import { Button, Paragraph, Row } from '@amsterdam/design-system-react/src'
import { Meta, StoryObj } from '@storybook/react'

const ThreeButtons = Array.from(Array(3).keys()).map((i) => <Button key={i}>Button {i + 1}</Button>)

const FourBoxes = Array.from(Array(4).keys()).map((i) => (
<Paragraph className="ams-docs-pink-box" key={i}>
Wrapping row item {i + 1}
</Paragraph>
))

const meta = {
title: 'Components/Layout/Row',
component: Row,
Expand All @@ -27,3 +33,10 @@ export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {}

export const Wrapping: Story = {
args: {
children: FourBoxes,
wrap: true,
},
}