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: Start-align Dialog buttons and place the primary button first #1143

Merged
merged 19 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
46f5234
Align dialog buttons to the start of the line
VincentSmedinga Mar 24, 2024
6246f16
Improve copy of Dialog stories
VincentSmedinga Mar 24, 2024
2d1a7ee
Remove obsolete import
VincentSmedinga Mar 24, 2024
19e9955
Merge branch 'develop' into feature/DES-553-dialog-buttons-alignment
VincentSmedinga Apr 27, 2024
be4b2dd
Implement button alignment on narrow and wide screens
VincentSmedinga Apr 28, 2024
cc1d1fa
Center button content in case it stretches
VincentSmedinga Apr 28, 2024
9c56b93
Document button order guidelines
VincentSmedinga Apr 28, 2024
8ed90ad
Apply suggestions from code review
VincentSmedinga May 6, 2024
cb31399
Make this function more readable
VincentSmedinga May 6, 2024
6078253
Merge branch 'develop' into feature/DES-553-dialog-buttons-alignment
VincentSmedinga May 6, 2024
5b6de60
Merge branch 'develop' into feature/DES-553-dialog-buttons-alignment
VincentSmedinga May 13, 2024
111cfc4
Merge branch 'develop' into feature/DES-553-dialog-buttons-alignment
VincentSmedinga May 13, 2024
7c75056
Merge branch 'feature/DES-553-dialog-buttons-alignment' of github.com…
VincentSmedinga May 13, 2024
0b9e77e
Align dialog buttons to the start of the line
VincentSmedinga May 14, 2024
ccec169
Remove unnecessary Fragment
VincentSmedinga May 14, 2024
302cb75
Add example code to open and close a dialog
VincentSmedinga May 16, 2024
7ee7dfc
Fix semantic level of headings in privacy statement example
VincentSmedinga May 16, 2024
b17dc67
Merge branch 'develop' into feature/DES-553-dialog-buttons-alignment
VincentSmedinga May 17, 2024
722b8a9
Use crazy long button labels to demonstrate vertical stacking
VincentSmedinga May 17, 2024
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
1 change: 1 addition & 0 deletions packages/css/src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
font-family: var(--ams-button-font-family);
font-size: var(--ams-button-font-size);
gap: var(--ams-button-gap);
justify-content: center;
line-height: var(--ams-button-line-height);
outline-offset: var(--ams-button-outline-offset);
padding-block: var(--ams-button-padding-block);
Expand Down
7 changes: 7 additions & 0 deletions packages/css/src/components/dialog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ A Dialog allows the user to focus on one task or a piece of information by poppi
- Use a dialog for short and non-frequent tasks.
Consider using the main flow for regular tasks.

## The order of buttons

If your Dialog needs more than one button, 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.

## Keyboard Support

| key | function |
Expand Down
14 changes: 7 additions & 7 deletions packages/css/src/components/dialog/dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Copyright Gemeente Amsterdam
*/

@import "../../common/breakpoint";

.ams-dialog {
background-color: var(--ams-dialog-background-color);
border: var(--ams-dialog-border);
Expand Down Expand Up @@ -48,11 +46,13 @@

.ams-dialog__footer {
display: flex;
flex-direction: column;
grid-gap: var(--ams-dialog-footer-gap);
flex-wrap: wrap; // [1]
gap: var(--ams-dialog-footer-gap);
margin-inline-end: auto; // [1]

@media screen and (min-width: $ams-breakpoint-medium) {
flex-direction: row;
justify-content: end;
> * {
RubenSibon marked this conversation as resolved.
Show resolved Hide resolved
flex: auto; // [1]
}
}

// [1] This combination stacks the buttons vertically and stretches them, until they fit next to each other.
dlnr marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions storybook/src/components/Dialog/Dialog.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ Content taller than the dialog itself will scroll.
Click or tap the button to open a dialog.

<Canvas of={DialogStories.TriggerButton} />

Some basic example code to open and close a dialog:

```ts
const openDialog = () => (document.querySelector("#openDialog") as HTMLDialogElement)?.showModal();

const closeDialog = (e: MouseEvent<HTMLButtonElement>) => e.currentTarget.closest("dialog")?.close();
```

## Vertically Stacked Buttons

If the buttons don’t fit next to each other, they will stack vertically and stretch to the full width.
View this example in a narrow window, enlarge your browser’s text size, or [use the ‘Phone’ size of the preview](?path=/story/components-containers-dialog--vertical-buttons&globals=viewport:phone).
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved

<Canvas of={DialogStories.VerticalButtons} />
70 changes: 48 additions & 22 deletions storybook/src/components/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@

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

const closeDialog = (event: MouseEvent<HTMLButtonElement>) => {
return event.currentTarget.closest('dialog')?.close()
dlnr marked this conversation as resolved.
Show resolved Hide resolved
}

const meta = {
title: 'Components/Containers/Dialog',
component: Dialog,
args: {
title: 'Weet u het zeker?',
children: (
<Paragraph>
Weet u zeker dat u door wilt gaan met het uitvoeren van deze actie? Alle niet-opgeslagen data zal worden
verwijderd.
</Paragraph>
),
actions: (
<>
<Button variant="tertiary" onClick={(event) => event.currentTarget.closest('dialog')?.close()}>
Terug
<Button type="submit">Doorgaan</Button>
<Button onClick={closeDialog} variant="tertiary">
Stoppen
</Button>
<Button type="submit">Verder</Button>
</>
),
children: (
<Paragraph>
Weet u zeker dat u door wilt gaan met het uitvoeren van deze actie? Dat verwijdert gegevens die nog niet
opgeslagen zijn.
</Paragraph>
),
title: 'Niet alle gegevens zijn opgeslagen',
},
argTypes: {
actions: {
Expand Down Expand Up @@ -58,10 +63,9 @@ export const Default: Story = {

export const WithScrollbar: Story = {
args: {
open: true,
title: 'Privacyverklaring gemeente Amsterdam',
actions: <Button onClick={closeDialog}>Sluiten</Button>,
children: [
<Heading size="level-4" key={1}>
<Heading level={2} size="level-5" key={1}>
Algemeen
</Heading>,
<Paragraph key={2}>
Expand All @@ -82,7 +86,7 @@ export const WithScrollbar: Story = {
ook wijzigingen zijn in de wijze van het verwerken van persoonsgegevens. Wij raden u daarom aan om regelmatig
deze pagina te bekijken. Deze pagina wordt doorlopend geactualiseerd.
</Paragraph>,
<Heading size="level-4" key={6}>
<Heading level={2} size="level-5" key={6}>
Geldende wet- en regelgeving en reikwijdte
</Heading>,
<Paragraph key={7}>
Expand All @@ -92,6 +96,8 @@ export const WithScrollbar: Story = {
vinden op de website van Autoriteit Persoonsgegevens.
</Paragraph>,
],
open: true,
title: 'Privacyverklaring gemeente Amsterdam',
},
decorators: [
(Story) => (
Expand All @@ -109,14 +115,6 @@ export const WithScrollbar: Story = {
export const TriggerButton: Story = {
args: {
id: 'openDialog',
actions: (
<>
<Button variant="tertiary" autoFocus onClick={(event) => event.currentTarget.closest('dialog')?.close()}>
Terug
</Button>
<Button type="submit">Verder</Button>
</>
),
},
decorators: [
(Story) => (
Expand All @@ -129,3 +127,31 @@ export const TriggerButton: Story = {
),
],
}

export const VerticalButtons: Story = {
args: {
actions: (
<>
<Button type="submit">Ja, ik wil doorgaan</Button>
<Button onClick={closeDialog} variant="tertiary">
Nee, toch maar terug
</Button>
</>
),
open: true,
},
decorators: [
(Story) => (
<div style={{ backgroundColor: '#0006', position: 'absolute', width: '100%', height: '100%' }}>
<Story />
</div>
),
],
parameters: {
layout: 'fullscreen',
docs: {
story: { height: '32em' },
},
viewport: { defaultViewport: 'phone' },
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
},
}
Loading