-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Add Action Group component, e.g. to wrap Dialog buttons in (#1592
- Loading branch information
1 parent
3734e6e
commit d0ea054
Showing
21 changed files
with
308 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# Action Group | ||
|
||
Groups one or more related actions and manages their layout. | ||
|
||
## How to use | ||
|
||
- Both a [Button](?path=/docs/components-buttons-button--docs) and a [Link](?path=/docs/components-navigation-link--docs) can provide an ‘action’ in this context. | ||
- If two or more buttons or links are in a row, put the one for the primary action first and the other buttons behind it. | ||
- Sighted users will read the primary action first, in line with the natural reading order. | ||
The same goes for users of screen readers, who will hear the primary action first, and users of a keyboard, who will focus the primary action first. | ||
- Also, this approach keeps the order of buttons consistent on both narrow and wide screens: if the buttons do not fit next to each other, they get stacked vertically with the primary action on top. | ||
- Replace the default ’group’ role with `role="toolbar"` for button toolbars. |
15 changes: 15 additions & 0 deletions
15
packages/css/src/components/action-group/action-group.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
.ams-action-group { | ||
align-items: baseline; | ||
display: inline-flex; | ||
flex-wrap: wrap; | ||
gap: var(--ams-action-group-gap); | ||
|
||
> * { | ||
flex: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { createRef } from 'react' | ||
import { ActionGroup } from './ActionGroup' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('Action Group', () => { | ||
it('renders', () => { | ||
render(<ActionGroup />) | ||
|
||
const component = screen.getByRole('group') | ||
|
||
expect(component).toBeInTheDocument() | ||
expect(component).toBeVisible() | ||
}) | ||
|
||
it('renders a design system BEM class name', () => { | ||
render(<ActionGroup />) | ||
|
||
const component = screen.getByRole('group') | ||
|
||
expect(component).toHaveClass('ams-action-group') | ||
}) | ||
|
||
it('renders an additional class name', () => { | ||
render(<ActionGroup className="extra" />) | ||
|
||
const component = screen.getByRole('group') | ||
|
||
expect(component).toHaveClass('ams-action-group extra') | ||
}) | ||
|
||
it('supports ForwardRef in React', () => { | ||
const ref = createRef<HTMLDivElement>() | ||
|
||
render(<ActionGroup ref={ref} />) | ||
|
||
const component = screen.getByRole('group') | ||
|
||
expect(ref.current).toBe(component) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes, PropsWithChildren } from 'react' | ||
|
||
export type ActionGroupProps = PropsWithChildren<HTMLAttributes<HTMLDivElement>> | ||
|
||
export const ActionGroup = forwardRef( | ||
({ children, className, ...restProps }: ActionGroupProps, ref: ForwardedRef<HTMLDivElement>) => ( | ||
<div {...restProps} ref={ref} className={clsx('ams-action-group', className)} role="group"> | ||
{children} | ||
</div> | ||
), | ||
) | ||
|
||
ActionGroup.displayName = 'ActionGroup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# React Action Group component | ||
|
||
[Action Group documentation](../../../css/src/components/action-group/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { ActionGroup } from './ActionGroup' | ||
export type { ActionGroupProps } from './ActionGroup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
proprietary/tokens/src/components/ams/action-group.tokens.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"ams": { | ||
"action-group": { | ||
"gap": { "value": "{ams.space.md}" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{/* @license CC0-1.0 */} | ||
|
||
import { Canvas, Markdown, Meta, Primary } from "@storybook/blocks"; | ||
import * as ActionGroupStories from "./ActionGroup.stories.tsx"; | ||
import README from "../../../../packages/css/src/components/action-group/README.md?raw"; | ||
|
||
<Meta of={ActionGroupStories} /> | ||
|
||
<Markdown>{README}</Markdown> | ||
|
||
<Primary /> | ||
|
||
## Examples | ||
|
||
### Stacked | ||
|
||
If the Buttons don’t fit next to each other, they will automatically stack vertically and stretch to the full width. | ||
This can occur in a narrow Dialog, with long labels, a large text size, or when zooming in. | ||
Resize the pink rectangle to see this in action. | ||
|
||
<Canvas of={ActionGroupStories.Stacked} /> | ||
|
||
### With Link | ||
|
||
An action that involves navigation should be a link. | ||
|
||
<Canvas of={ActionGroupStories.WithLink} /> |
43 changes: 43 additions & 0 deletions
43
storybook/src/components/ActionGroup/ActionGroup.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import { Button, Link } from '@amsterdam/design-system-react' | ||
import { ActionGroup } from '@amsterdam/design-system-react/src' | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
const meta = { | ||
title: 'Components/Buttons/Action Group', | ||
component: ActionGroup, | ||
args: { | ||
children: [<Button>Doorgaan</Button>, <Button variant="tertiary">Stoppen</Button>], | ||
}, | ||
} satisfies Meta<typeof ActionGroup> | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = {} | ||
|
||
export const Stacked: Story = { | ||
args: { | ||
children: [<Button>Adres wijzigen</Button>, <Button variant="secondary">Adres verwijderen</Button>], | ||
className: 'ams-resize-horizontal', | ||
style: { | ||
inlineSize: '16rem', | ||
}, | ||
}, | ||
} | ||
|
||
export const WithLink: Story = { | ||
args: { | ||
children: [ | ||
<Button key={1}>Bewerken</Button>, | ||
<Link download href="#" key={2} variant="standalone"> | ||
Downloaden | ||
</Link>, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.