@aleph-alpha/ui-library 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +1 -1
- package/dist/system/icons/story-sidebar-icons.json +74 -17
- package/dist/system/lib.js +1167 -1162
- package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +74 -17
- package/package.json +8 -3
- package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
- package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
- package/src/components/UiAlert/UiAlert.guidance.md +66 -0
- package/src/components/UiAlert/UiAlert.stories.ts +167 -143
- package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
- package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
- package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
- package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
- package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
- package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
- package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
- package/src/components/UiBadge/UiBadge.guidance.md +65 -0
- package/src/components/UiBadge/UiBadge.stories.ts +325 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
- package/src/components/UiButton/UiButton.stories.ts +5 -2
- package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
- package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
- package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
- package/src/components/UiCard/UiCard.guidance.md +65 -0
- package/src/components/UiCard/UiCard.stories.ts +393 -0
- package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
- package/src/components/UiChip/UiChip.guidance.md +64 -0
- package/src/components/UiChip/UiChip.stories.ts +162 -138
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
- package/src/components/UiDialog/UiDialog.guidance.md +66 -0
- package/src/components/UiDialog/UiDialog.stories.ts +90 -66
- package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
- package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
- package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +332 -85
- package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +134 -0
- package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +23 -2
- package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
- package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
- package/src/components/UiField/UiField.guidance.md +63 -0
- package/src/components/UiField/UiField.stories.ts +90 -113
- package/src/components/UiFileType/UiFileType.stories.ts +254 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
- package/src/components/UiIcon/UiIcon.stories.ts +256 -1
- package/src/components/UiInput/UiInput.guidance.md +64 -0
- package/src/components/UiInput/UiInput.stories.ts +132 -80
- package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
- package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
- package/src/components/UiItem/UiItem.guidance.md +66 -0
- package/src/components/UiItem/UiItem.stories.ts +81 -28
- package/src/components/UiKbd/UiKbd.guidance.md +65 -0
- package/src/components/UiKbd/UiKbd.stories.ts +373 -3
- package/src/components/UiLabel/UiLabel.guidance.md +65 -0
- package/src/components/UiLabel/UiLabel.stories.ts +163 -139
- package/src/components/UiListbox/UiListbox.stories.ts +197 -195
- package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
- package/src/components/UiPopover/UiPopover.guidance.md +65 -0
- package/src/components/UiPopover/UiPopover.stories.ts +115 -91
- package/src/components/UiProgress/UiProgress.guidance.md +65 -0
- package/src/components/UiProgress/UiProgress.stories.ts +300 -0
- package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
- package/src/components/UiResizable/UiResizable.guidance.md +65 -0
- package/src/components/UiResizable/UiResizable.stories.ts +176 -152
- package/src/components/UiSelect/UiSelect.guidance.md +66 -0
- package/src/components/UiSelect/UiSelect.stories.ts +150 -126
- package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
- package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
- package/src/components/UiSheet/UiSheet.guidance.md +66 -0
- package/src/components/UiSheet/UiSheet.stories.ts +194 -170
- package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
- package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
- package/src/components/UiSlider/UiSlider.guidance.md +66 -0
- package/src/components/UiSlider/UiSlider.stories.ts +150 -126
- package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
- package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
- package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
- package/src/components/UiStepper/UiStepper.guidance.md +66 -0
- package/src/components/UiStepper/UiStepper.stories.ts +142 -124
- package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
- package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
- package/src/components/UiTable/UiTable.guidance.md +66 -0
- package/src/components/UiTable/UiTable.stories.ts +530 -12
- package/src/components/UiTabs/UiTabs.guidance.md +66 -0
- package/src/components/UiTabs/UiTabs.stories.ts +174 -150
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
- package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
- package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
- package/src/components/UiToggle/UiToggle.guidance.md +66 -0
- package/src/components/UiToggle/UiToggle.stories.ts +183 -159
- package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
- package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
- package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
- package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
- package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
- package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
- package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
- package/src/patterns/UiPlaceholder/types.ts +1 -0
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +74 -72
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
|
@@ -65,8 +65,9 @@ export function useMobileSubmenuPlacement(
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Measures the trigger row and parent panel, and writes the placement.
|
|
68
|
+
* @param event The event that asked for a new placement, if any.
|
|
68
69
|
*/
|
|
69
|
-
function apply() {
|
|
70
|
+
function apply(event?: Event) {
|
|
70
71
|
const content = getContent();
|
|
71
72
|
if (!content?.isConnected) {
|
|
72
73
|
return;
|
|
@@ -80,12 +81,29 @@ export function useMobileSubmenuPlacement(
|
|
|
80
81
|
if (!trigger || !parent) {
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
84
|
+
// Only a scroll around the row moves it. The submenu's own list and the
|
|
85
|
+
// other menu panels, portalled beside it, leave it where it is; placing
|
|
86
|
+
// again for those would also let two capped panels keep re-placing each
|
|
87
|
+
// other.
|
|
88
|
+
if (
|
|
89
|
+
event?.type === 'scroll' &&
|
|
90
|
+
event.target instanceof Node &&
|
|
91
|
+
!event.target.contains(trigger)
|
|
92
|
+
) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
83
95
|
|
|
84
96
|
const triggerRect = trigger.getBoundingClientRect();
|
|
85
97
|
const parentRect = parent.getBoundingClientRect();
|
|
86
98
|
// Measure the panel at its natural height, so a cap written on an earlier
|
|
87
99
|
// pass does not stick once there is room again. Layout height, not the
|
|
88
|
-
// bounding box: the panel is scaled while it animates in.
|
|
100
|
+
// bounding box: the panel is scaled while it animates in. Uncapped, the
|
|
101
|
+
// list is taller and can scroll less far, so the browser pulls its
|
|
102
|
+
// position back; it is put back once the cap is written again.
|
|
103
|
+
const scroll = content.querySelector<HTMLElement>(
|
|
104
|
+
'[data-slot="dropdown-menu-scroll"]',
|
|
105
|
+
);
|
|
106
|
+
const scrollTop = scroll?.scrollTop ?? 0;
|
|
89
107
|
content.style.removeProperty(SCROLL_MAX_HEIGHT_VAR);
|
|
90
108
|
delete content.dataset.mobileClamped;
|
|
91
109
|
const submenuHeight =
|
|
@@ -109,6 +127,9 @@ export function useMobileSubmenuPlacement(
|
|
|
109
127
|
);
|
|
110
128
|
content.dataset.mobileClamped = '';
|
|
111
129
|
}
|
|
130
|
+
if (scroll && scroll.scrollTop !== scrollTop) {
|
|
131
|
+
scroll.scrollTop = scrollTop;
|
|
132
|
+
}
|
|
112
133
|
content.style.setProperty(
|
|
113
134
|
'--ui-dropdown-submenu-top',
|
|
114
135
|
`${placement.top}px`,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
figma: '29197:70337'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<!-- Synced from Figma by scripts/sync-figma-docs.mjs. Edit the copy in Figma: changes made here are overwritten. -->
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
The Empty component fills a space that has nothing in it yet and turns that absence into a next step. An empty state is not an error: it is the beginning of something, or a filter that matched nothing.
|
|
10
|
+
|
|
11
|
+
Use it wherever a list, table, panel or search result can legitimately be empty. Every such place deserves one, because a blank area reads as broken.
|
|
12
|
+
|
|
13
|
+
### Say why, then say what next
|
|
14
|
+
|
|
15
|
+
An empty state answers two questions, in order:
|
|
16
|
+
|
|
17
|
+
- The title names the situation in plain words
|
|
18
|
+
- The description explains why the space is empty
|
|
19
|
+
- The action is the thing that would fill it
|
|
20
|
+
- Nothing here implies the user has done something wrong
|
|
21
|
+
|
|
22
|
+
### Match the state to its cause
|
|
23
|
+
|
|
24
|
+
Different kinds of empty need different words:
|
|
25
|
+
|
|
26
|
+
1. Nothing created yet, so offer the action that creates the first one
|
|
27
|
+
2. Nothing matched, so offer a way to widen or clear the filter
|
|
28
|
+
3. Nothing to do, so say so plainly and offer nothing
|
|
29
|
+
4. Something failed, so explain it and offer a retry
|
|
30
|
+
|
|
31
|
+
### Consistency
|
|
32
|
+
|
|
33
|
+
Every empty state is built from the same parts:
|
|
34
|
+
|
|
35
|
+
- Empty surface, centred in the space it fills
|
|
36
|
+
- Media: an icon, an avatar, or an avatar group
|
|
37
|
+
- Title, naming the situation
|
|
38
|
+
- Description, explaining it
|
|
39
|
+
- Content: one, two or three buttons, or an input with a description
|
|
40
|
+
|
|
41
|
+
## Do
|
|
42
|
+
|
|
43
|
+
- Give every list, table and result set an empty state
|
|
44
|
+
- Name the situation in the title, and explain it in the description
|
|
45
|
+
- Offer the action that would fill the space
|
|
46
|
+
- Use a filter-specific message when a filter is what emptied it
|
|
47
|
+
- Keep the empty state centred in the space it replaces
|
|
48
|
+
- Use an icon that describes the content type, not a generic mark
|
|
49
|
+
|
|
50
|
+
## Don't
|
|
51
|
+
|
|
52
|
+
- Leave a blank area with no explanation
|
|
53
|
+
- Blame the user for an empty state
|
|
54
|
+
- Offer three actions where one would do
|
|
55
|
+
- Use the same message for nothing-yet and nothing-matched
|
|
56
|
+
- Make the empty state taller than the space it fills
|
|
57
|
+
- Use decorative illustration in place of a clear next step
|
|
58
|
+
|
|
59
|
+
## Accessibility
|
|
60
|
+
|
|
61
|
+
- Title and description carry the meaning, so the illustration is never the only explanation
|
|
62
|
+
- Text holds its contrast against the surface behind it, including on tinted backgrounds
|
|
63
|
+
- The action is a comfortable target and keeps a visible focus state
|
|
64
|
+
- Media, title, description and action follow one another in reading order
|
|
65
|
+
- The state stays legible when the panel it fills is narrow
|
|
66
|
+
- Nothing relies on colour to separate a neutral empty state from a failure
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, within } from 'storybook/test';
|
|
2
3
|
import UiEmpty from './UiEmpty.vue';
|
|
3
4
|
import { UiButton } from '../UiButton';
|
|
4
5
|
import { SearchIcon } from '@/icons/lucide';
|
|
6
|
+
import {
|
|
7
|
+
accessibilityStory,
|
|
8
|
+
designNotesStory,
|
|
9
|
+
guidanceLinks,
|
|
10
|
+
parseGuidance,
|
|
11
|
+
} from '../../../.storybook/guidance';
|
|
12
|
+
import guidanceMarkdown from './UiEmpty.guidance.md?raw';
|
|
13
|
+
|
|
14
|
+
const guidance = parseGuidance(guidanceMarkdown);
|
|
5
15
|
|
|
6
16
|
/**
|
|
7
17
|
* UiEmpty is a placeholder layout for empty states, displaying an icon, title, description, and optional actions.
|
|
@@ -29,12 +39,19 @@ const meta: Meta<typeof UiEmpty> = {
|
|
|
29
39
|
title: 'No items found',
|
|
30
40
|
description: 'There are no items to display at the moment.',
|
|
31
41
|
},
|
|
42
|
+
parameters: {
|
|
43
|
+
docs: { links: guidanceLinks(guidance) },
|
|
44
|
+
},
|
|
32
45
|
};
|
|
33
46
|
|
|
34
47
|
export default meta;
|
|
35
48
|
|
|
36
49
|
type Story = StoryObj<typeof UiEmpty>;
|
|
37
50
|
|
|
51
|
+
const onCreate = fn();
|
|
52
|
+
const onUpload = fn();
|
|
53
|
+
const onImport = fn();
|
|
54
|
+
|
|
38
55
|
const defaultTemplateSource = `<script setup lang="ts">
|
|
39
56
|
import { UiEmpty } from '@aleph-alpha/ui-library'
|
|
40
57
|
</script>
|
|
@@ -66,6 +83,31 @@ export const Default: Story = {
|
|
|
66
83
|
},
|
|
67
84
|
};
|
|
68
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Usage, guidelines, and do's and don'ts from the Figma documentation.
|
|
88
|
+
*/
|
|
89
|
+
export const DesignNotes: Story = {
|
|
90
|
+
...designNotesStory(guidance),
|
|
91
|
+
tags: ['!autodocs'],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Accessibility guidance from the Figma documentation, with the component in
|
|
96
|
+
* the default and accessible themes.
|
|
97
|
+
*/
|
|
98
|
+
export const Accessibility: Story = {
|
|
99
|
+
...accessibilityStory({
|
|
100
|
+
requirements: guidance.accessibility,
|
|
101
|
+
example: {
|
|
102
|
+
components: { UiEmpty },
|
|
103
|
+
template: `
|
|
104
|
+
<UiEmpty title="No results found" description="Try a different search term." />
|
|
105
|
+
`,
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
tags: ['!autodocs'],
|
|
109
|
+
};
|
|
110
|
+
|
|
69
111
|
const titleOnlyTemplateSource = `<script setup lang="ts">
|
|
70
112
|
import { UiEmpty } from '@aleph-alpha/ui-library'
|
|
71
113
|
</script>
|
|
@@ -149,12 +191,15 @@ import { UiEmpty, UiButton } from '@aleph-alpha/ui-library'
|
|
|
149
191
|
export const WithAction: Story = {
|
|
150
192
|
render: () => ({
|
|
151
193
|
components: { UiEmpty, UiButton },
|
|
194
|
+
setup() {
|
|
195
|
+
return { onCreate };
|
|
196
|
+
},
|
|
152
197
|
template: `
|
|
153
198
|
<UiEmpty
|
|
154
199
|
title="No projects yet"
|
|
155
200
|
description="Get started by creating your first project."
|
|
156
201
|
>
|
|
157
|
-
<UiButton>Create Project</UiButton>
|
|
202
|
+
<UiButton @click="onCreate">Create Project</UiButton>
|
|
158
203
|
</UiEmpty>
|
|
159
204
|
`,
|
|
160
205
|
}),
|
|
@@ -165,6 +210,30 @@ export const WithAction: Story = {
|
|
|
165
210
|
},
|
|
166
211
|
},
|
|
167
212
|
},
|
|
213
|
+
play: async ({ canvasElement, step }) => {
|
|
214
|
+
// Scenario (UiEmpty): the empty state explains itself and offers one next
|
|
215
|
+
// step that the user can take.
|
|
216
|
+
onCreate.mockClear();
|
|
217
|
+
const canvas = within(canvasElement);
|
|
218
|
+
|
|
219
|
+
await step(
|
|
220
|
+
'interaction: the empty state reads as a heading and a description',
|
|
221
|
+
async () => {
|
|
222
|
+
await expect(
|
|
223
|
+
canvas.getByRole('heading', { name: 'No projects yet' }),
|
|
224
|
+
).toBeVisible();
|
|
225
|
+
await expect(
|
|
226
|
+
canvas.getByText('Get started by creating your first project.'),
|
|
227
|
+
).toBeVisible();
|
|
228
|
+
},
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
await step('interaction: the action is named and activates', async () => {
|
|
232
|
+
const create = canvas.getByRole('button', { name: 'Create Project' });
|
|
233
|
+
await userEvent.click(create);
|
|
234
|
+
await expect(onCreate).toHaveBeenCalledTimes(1);
|
|
235
|
+
});
|
|
236
|
+
},
|
|
168
237
|
};
|
|
169
238
|
|
|
170
239
|
const withMultipleActionsTemplateSource = `<script setup lang="ts">
|
|
@@ -183,24 +252,29 @@ import { UiEmpty, UiButton } from '@aleph-alpha/ui-library'
|
|
|
183
252
|
</UiEmpty>
|
|
184
253
|
</template>`;
|
|
185
254
|
|
|
255
|
+
const renderMultipleActions = () => ({
|
|
256
|
+
components: { UiEmpty, UiButton },
|
|
257
|
+
setup() {
|
|
258
|
+
return { onImport, onUpload };
|
|
259
|
+
},
|
|
260
|
+
template: `
|
|
261
|
+
<UiEmpty
|
|
262
|
+
title="No files uploaded"
|
|
263
|
+
description="Upload files to get started or import from another source."
|
|
264
|
+
>
|
|
265
|
+
<div class="flex gap-2">
|
|
266
|
+
<UiButton @click="onUpload">Upload Files</UiButton>
|
|
267
|
+
<UiButton variant="outline" @click="onImport">Import</UiButton>
|
|
268
|
+
</div>
|
|
269
|
+
</UiEmpty>
|
|
270
|
+
`,
|
|
271
|
+
});
|
|
272
|
+
|
|
186
273
|
/**
|
|
187
274
|
* Empty state with multiple action buttons.
|
|
188
275
|
*/
|
|
189
276
|
export const WithMultipleActions: Story = {
|
|
190
|
-
render:
|
|
191
|
-
components: { UiEmpty, UiButton },
|
|
192
|
-
template: `
|
|
193
|
-
<UiEmpty
|
|
194
|
-
title="No files uploaded"
|
|
195
|
-
description="Upload files to get started or import from another source."
|
|
196
|
-
>
|
|
197
|
-
<div class="flex gap-2">
|
|
198
|
-
<UiButton>Upload Files</UiButton>
|
|
199
|
-
<UiButton variant="outline">Import</UiButton>
|
|
200
|
-
</div>
|
|
201
|
-
</UiEmpty>
|
|
202
|
-
`,
|
|
203
|
-
}),
|
|
277
|
+
render: renderMultipleActions,
|
|
204
278
|
parameters: {
|
|
205
279
|
docs: {
|
|
206
280
|
source: {
|
|
@@ -208,6 +282,33 @@ export const WithMultipleActions: Story = {
|
|
|
208
282
|
},
|
|
209
283
|
},
|
|
210
284
|
},
|
|
285
|
+
play: async ({ canvasElement, step }) => {
|
|
286
|
+
// Scenario (UiEmpty): two next steps are offered; each one triggers only
|
|
287
|
+
// its own action.
|
|
288
|
+
onUpload.mockClear();
|
|
289
|
+
onImport.mockClear();
|
|
290
|
+
const canvas = within(canvasElement);
|
|
291
|
+
|
|
292
|
+
await step(
|
|
293
|
+
'interaction: the primary action activates on its own',
|
|
294
|
+
async () => {
|
|
295
|
+
await userEvent.click(
|
|
296
|
+
canvas.getByRole('button', { name: 'Upload Files' }),
|
|
297
|
+
);
|
|
298
|
+
await expect(onUpload).toHaveBeenCalledTimes(1);
|
|
299
|
+
await expect(onImport).not.toHaveBeenCalled();
|
|
300
|
+
},
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
await step(
|
|
304
|
+
'interaction: the secondary action activates on its own',
|
|
305
|
+
async () => {
|
|
306
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Import' }));
|
|
307
|
+
await expect(onImport).toHaveBeenCalledTimes(1);
|
|
308
|
+
await expect(onUpload).toHaveBeenCalledTimes(1);
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
},
|
|
211
312
|
};
|
|
212
313
|
|
|
213
314
|
const minimalTemplateSource = `<script setup lang="ts">
|
|
@@ -234,3 +335,257 @@ export const Minimal: Story = {
|
|
|
234
335
|
},
|
|
235
336
|
},
|
|
236
337
|
};
|
|
338
|
+
|
|
339
|
+
const clearEmptySpies = () => {
|
|
340
|
+
onUpload.mockClear();
|
|
341
|
+
onImport.mockClear();
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Focus skips the illustration and text and lands on the actions in order;
|
|
346
|
+
* `Enter` and `Space` activate them. Hidden test-only story.
|
|
347
|
+
*/
|
|
348
|
+
export const KeyboardNavigation: Story = {
|
|
349
|
+
name: 'test - Keyboard Navigation',
|
|
350
|
+
tags: ['!dev', '!autodocs'],
|
|
351
|
+
parameters: {
|
|
352
|
+
// Focus moves during the play function.
|
|
353
|
+
chromatic: { disableSnapshot: true },
|
|
354
|
+
docs: {
|
|
355
|
+
description: {
|
|
356
|
+
story:
|
|
357
|
+
'Press `Tab` to reach the actions, then `Enter` or `Space` to activate them.',
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
render: renderMultipleActions,
|
|
362
|
+
play: async ({ canvasElement, step }) => {
|
|
363
|
+
// Scenario (UiEmpty): a keyboard user skips past the empty-state message
|
|
364
|
+
// and reaches each action in order.
|
|
365
|
+
clearEmptySpies();
|
|
366
|
+
const canvas = within(canvasElement);
|
|
367
|
+
const upload = canvas.getByRole('button', { name: 'Upload Files' });
|
|
368
|
+
const importButton = canvas.getByRole('button', { name: 'Import' });
|
|
369
|
+
|
|
370
|
+
await step(
|
|
371
|
+
'keyboard: Tab lands on the first action, skipping the message',
|
|
372
|
+
async () => {
|
|
373
|
+
await userEvent.tab();
|
|
374
|
+
await expect(upload).toHaveFocus();
|
|
375
|
+
},
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
await step('keyboard: Enter activates the focused action', async () => {
|
|
379
|
+
await userEvent.keyboard('{Enter}');
|
|
380
|
+
await expect(onUpload).toHaveBeenCalledTimes(1);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
await step(
|
|
384
|
+
'keyboard: Tab moves to the next action and Space activates it',
|
|
385
|
+
async () => {
|
|
386
|
+
await userEvent.tab();
|
|
387
|
+
await expect(importButton).toHaveFocus();
|
|
388
|
+
await userEvent.keyboard(' ');
|
|
389
|
+
await expect(onImport).toHaveBeenCalledTimes(1);
|
|
390
|
+
},
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
await step(
|
|
394
|
+
'keyboard: focus leaves the empty state after its last action',
|
|
395
|
+
async () => {
|
|
396
|
+
await userEvent.tab();
|
|
397
|
+
await expect(canvasElement.contains(document.activeElement)).toBe(
|
|
398
|
+
false,
|
|
399
|
+
);
|
|
400
|
+
},
|
|
401
|
+
);
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* What assistive technology reads for the empty state: a heading, the
|
|
407
|
+
* description, and named actions, with the illustration skipped. Hidden
|
|
408
|
+
* test-only story.
|
|
409
|
+
*/
|
|
410
|
+
export const ScreenReader: Story = {
|
|
411
|
+
name: 'test - Screen Reader',
|
|
412
|
+
tags: ['!dev', '!autodocs'],
|
|
413
|
+
parameters: {
|
|
414
|
+
docs: {
|
|
415
|
+
description: {
|
|
416
|
+
story:
|
|
417
|
+
'Verifies the heading, description, and action names that assistive technology announces.',
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
render: renderMultipleActions,
|
|
422
|
+
play: async ({ canvasElement, step }) => {
|
|
423
|
+
// Scenario (UiEmpty): a screen-reader user hears why the area is empty and
|
|
424
|
+
// what to do next, without the decorative illustration.
|
|
425
|
+
const canvas = within(canvasElement);
|
|
426
|
+
|
|
427
|
+
await step(
|
|
428
|
+
'screen-reader: the title is a level-3 heading (WCAG 1.3.1)',
|
|
429
|
+
async () => {
|
|
430
|
+
await expect(
|
|
431
|
+
canvas.getByRole('heading', { level: 3, name: 'No files uploaded' }),
|
|
432
|
+
).toBeVisible();
|
|
433
|
+
},
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
await step(
|
|
437
|
+
'screen-reader: the description follows the heading in reading order',
|
|
438
|
+
async () => {
|
|
439
|
+
const heading = canvas.getByRole('heading', {
|
|
440
|
+
name: 'No files uploaded',
|
|
441
|
+
});
|
|
442
|
+
const description = canvas.getByText(
|
|
443
|
+
'Upload files to get started or import from another source.',
|
|
444
|
+
);
|
|
445
|
+
await expect(
|
|
446
|
+
heading.compareDocumentPosition(description) &
|
|
447
|
+
Node.DOCUMENT_POSITION_FOLLOWING,
|
|
448
|
+
).toBeTruthy();
|
|
449
|
+
},
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
await step(
|
|
453
|
+
'screen-reader: the illustration is hidden from assistive technology',
|
|
454
|
+
async () => {
|
|
455
|
+
const icon = canvasElement.querySelector('svg');
|
|
456
|
+
if (!icon) throw new Error('UiEmpty rendered no illustration');
|
|
457
|
+
await expect(icon.closest('[aria-hidden="true"]')).not.toBeNull();
|
|
458
|
+
await expect(canvas.queryByRole('img')).not.toBeInTheDocument();
|
|
459
|
+
},
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
await step(
|
|
463
|
+
'screen-reader: every action has an accessible name',
|
|
464
|
+
async () => {
|
|
465
|
+
for (const name of ['Upload Files', 'Import']) {
|
|
466
|
+
await expect(
|
|
467
|
+
canvas.getByRole('button', { name }),
|
|
468
|
+
).toHaveAccessibleName(name);
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
);
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
477
|
+
* try 400% reflow (WCAG 1.4.10). Hidden test-only story.
|
|
478
|
+
*/
|
|
479
|
+
export const ZoomMagnification: Story = {
|
|
480
|
+
name: 'test - Zoom Magnification',
|
|
481
|
+
tags: ['!dev', '!autodocs'],
|
|
482
|
+
globals: { zoom: '200' },
|
|
483
|
+
parameters: {
|
|
484
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
485
|
+
// already covers magnified snapshots, so skip this one.
|
|
486
|
+
chromatic: { disableSnapshot: true },
|
|
487
|
+
docs: {
|
|
488
|
+
description: {
|
|
489
|
+
story:
|
|
490
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
render: renderMultipleActions,
|
|
495
|
+
play: async ({ canvasElement, step }) => {
|
|
496
|
+
// Scenario (UiEmpty): at 200% page zoom the message stays readable, the
|
|
497
|
+
// actions stay inside the viewport, and they still work.
|
|
498
|
+
clearEmptySpies();
|
|
499
|
+
const canvas = within(canvasElement);
|
|
500
|
+
|
|
501
|
+
await step(
|
|
502
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
503
|
+
async () => {
|
|
504
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
505
|
+
},
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
await step('zoom: title and description stay readable', async () => {
|
|
509
|
+
await expect(
|
|
510
|
+
canvas.getByRole('heading', { name: 'No files uploaded' }),
|
|
511
|
+
).toBeVisible();
|
|
512
|
+
await expect(
|
|
513
|
+
canvas.getByText(
|
|
514
|
+
'Upload files to get started or import from another source.',
|
|
515
|
+
),
|
|
516
|
+
).toBeVisible();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
await step('zoom: actions stay inside the viewport', async () => {
|
|
520
|
+
for (const control of canvas.getAllByRole('button')) {
|
|
521
|
+
const { left, right } = control.getBoundingClientRect();
|
|
522
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
523
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
await step('zoom: actions remain operable when magnified', async () => {
|
|
528
|
+
await userEvent.click(
|
|
529
|
+
canvas.getByRole('button', { name: 'Upload Files' }),
|
|
530
|
+
);
|
|
531
|
+
await expect(onUpload).toHaveBeenCalledTimes(1);
|
|
532
|
+
});
|
|
533
|
+
},
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
538
|
+
* toolbar. Hidden test-only story.
|
|
539
|
+
*/
|
|
540
|
+
export const MobileBreakpoint: Story = {
|
|
541
|
+
name: 'test - Mobile Breakpoint',
|
|
542
|
+
tags: ['!dev', '!autodocs'],
|
|
543
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
544
|
+
parameters: {
|
|
545
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
546
|
+
chromatic: { disableSnapshot: true },
|
|
547
|
+
docs: {
|
|
548
|
+
description: {
|
|
549
|
+
story:
|
|
550
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
render: renderMultipleActions,
|
|
555
|
+
play: async ({ canvasElement, step }) => {
|
|
556
|
+
// Scenario (UiEmpty): at the 320px mobile breakpoint the message and both
|
|
557
|
+
// actions fit without sideways scrolling and are big enough to tap.
|
|
558
|
+
clearEmptySpies();
|
|
559
|
+
const canvas = within(canvasElement);
|
|
560
|
+
|
|
561
|
+
await step(
|
|
562
|
+
'mobile: the empty state renders at the 320px breakpoint',
|
|
563
|
+
async () => {
|
|
564
|
+
await expect(
|
|
565
|
+
canvas.getByRole('heading', { name: 'No files uploaded' }),
|
|
566
|
+
).toBeVisible();
|
|
567
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Import' }));
|
|
568
|
+
await expect(onImport).toHaveBeenCalledTimes(1);
|
|
569
|
+
},
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
await step(
|
|
573
|
+
'mobile: the layout fits without sideways scrolling (WCAG 1.4.10 Reflow)',
|
|
574
|
+
async () => {
|
|
575
|
+
const { scrollWidth, clientWidth } = document.documentElement;
|
|
576
|
+
await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
|
|
577
|
+
},
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
await step(
|
|
581
|
+
'mobile: every action meets the minimum target size (WCAG 2.5.8)',
|
|
582
|
+
async () => {
|
|
583
|
+
for (const control of canvas.getAllByRole('button')) {
|
|
584
|
+
const { width, height } = control.getBoundingClientRect();
|
|
585
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
586
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
);
|
|
590
|
+
},
|
|
591
|
+
};
|
|
@@ -605,6 +605,72 @@ export const KeyboardNavigation: Story = {
|
|
|
605
605
|
},
|
|
606
606
|
};
|
|
607
607
|
|
|
608
|
+
/**
|
|
609
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
610
|
+
* try 400% reflow (WCAG 1.4.10). Hidden test-only story.
|
|
611
|
+
*/
|
|
612
|
+
export const ZoomMagnification: Story = {
|
|
613
|
+
name: 'test - Zoom Magnification',
|
|
614
|
+
tags: ['!dev', '!autodocs'],
|
|
615
|
+
globals: { zoom: '200' },
|
|
616
|
+
args: {
|
|
617
|
+
position: 'bottom',
|
|
618
|
+
},
|
|
619
|
+
parameters: {
|
|
620
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
621
|
+
// already covers magnified snapshots, so skip this one.
|
|
622
|
+
chromatic: { disableSnapshot: true },
|
|
623
|
+
docs: {
|
|
624
|
+
description: {
|
|
625
|
+
story:
|
|
626
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
render: (args) => ({
|
|
631
|
+
components: { UiFadeMask },
|
|
632
|
+
setup() {
|
|
633
|
+
return { args };
|
|
634
|
+
},
|
|
635
|
+
template: `<UiFadeMask
|
|
636
|
+
v-bind="args"
|
|
637
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
638
|
+
>
|
|
639
|
+
${scrollPanel}
|
|
640
|
+
</UiFadeMask>`,
|
|
641
|
+
}),
|
|
642
|
+
play: async ({ canvasElement, step }) => {
|
|
643
|
+
// Scenario (UiFadeMask): at 200% page zoom the masked content stays
|
|
644
|
+
// readable and scrollable, and the band stays decorative.
|
|
645
|
+
const canvas = within(canvasElement);
|
|
646
|
+
const band = getBand(canvasElement);
|
|
647
|
+
const region = canvas.getByRole('region', { name: SCROLL_REGION_LABEL });
|
|
648
|
+
|
|
649
|
+
await step(
|
|
650
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
651
|
+
async () => {
|
|
652
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
653
|
+
},
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
await step('zoom: the masked content stays readable', async () => {
|
|
657
|
+
await expect(region).toBeVisible();
|
|
658
|
+
await expect(
|
|
659
|
+
within(region).getByRole('heading', { name: 'Deployment boundaries' }),
|
|
660
|
+
).toBeVisible();
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
await step(
|
|
664
|
+
'zoom: the band stays decorative and out of the tab order',
|
|
665
|
+
async () => {
|
|
666
|
+
await expect(band).toHaveAttribute('aria-hidden', 'true');
|
|
667
|
+
await userEvent.tab();
|
|
668
|
+
await expect(region).toHaveFocus();
|
|
669
|
+
},
|
|
670
|
+
);
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
|
|
608
674
|
/**
|
|
609
675
|
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
610
676
|
* toolbar. The band switches to its shorter height and the masked panel reflows
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
figma: '27118:3268'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<!-- Synced from Figma by scripts/sync-figma-docs.mjs. Edit the copy in Figma: changes made here are overwritten. -->
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
The Field component establishes a consistent structure for collecting information from users. It creates a predictable relationship between inputs, labels, help text, and validation messages, making forms easier to scan, understand, and complete.
|
|
10
|
+
|
|
11
|
+
The component should be used whenever a user is expected to provide, select, or modify information.
|
|
12
|
+
|
|
13
|
+
### Clarity first
|
|
14
|
+
|
|
15
|
+
Users should immediately understand:
|
|
16
|
+
|
|
17
|
+
- What information is being requested
|
|
18
|
+
- Whether the field is required or optional
|
|
19
|
+
- How to successfully complete the field
|
|
20
|
+
- What needs to be corrected when errors occur
|
|
21
|
+
|
|
22
|
+
### Progressive guidance
|
|
23
|
+
|
|
24
|
+
Provide information only when it helps the user complete a task:
|
|
25
|
+
|
|
26
|
+
1. Label explains what is needed
|
|
27
|
+
2. Description provides additional guidance
|
|
28
|
+
3. Error message appears only when required
|
|
29
|
+
|
|
30
|
+
### Consistency
|
|
31
|
+
|
|
32
|
+
All form controls should follow the same structure regardless of input type:
|
|
33
|
+
|
|
34
|
+
- Text Input
|
|
35
|
+
- Select
|
|
36
|
+
- Checkbox
|
|
37
|
+
- Switch
|
|
38
|
+
- Radio Group
|
|
39
|
+
- Text Area
|
|
40
|
+
- Slider
|
|
41
|
+
|
|
42
|
+
## Do
|
|
43
|
+
|
|
44
|
+
- Use a clear label for every field
|
|
45
|
+
- Provide helpful descriptions when needed
|
|
46
|
+
- Group related information together
|
|
47
|
+
- Write actionable error messages
|
|
48
|
+
- Use vertical layouts for complex forms
|
|
49
|
+
|
|
50
|
+
## Don't
|
|
51
|
+
|
|
52
|
+
- Use placeholders as labels
|
|
53
|
+
- Display errors before interaction
|
|
54
|
+
- Overload fields with excessive guidance
|
|
55
|
+
- Create inconsistent field layouts across screens
|
|
56
|
+
- Depend solely on color to indicate validation states
|
|
57
|
+
|
|
58
|
+
## Accessibility
|
|
59
|
+
|
|
60
|
+
- Every field has a visible label
|
|
61
|
+
- Error states are communicated through more than color alone
|
|
62
|
+
- Descriptions remain readable and associated with the field
|
|
63
|
+
- Form sections use meaningful group labels
|