@aleph-alpha/ui-library 5.8.0 → 5.9.0
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/README.md +8 -7
- package/dist/system/__tests__/test-utils.d.ts +24 -0
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
- package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
- package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
- package/dist/system/components/UiFadeMask/index.d.ts +2 -0
- package/dist/system/components/UiFadeMask/types.d.ts +33 -0
- package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiListbox/index.d.ts +1 -0
- package/dist/system/components/UiListbox/types.d.ts +36 -0
- package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiSelect/index.d.ts +1 -0
- package/dist/system/components/UiSelect/types.d.ts +36 -0
- package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
- package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +22249 -21090
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -1
- package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
- package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
- package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
- package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
- package/dist/system/patterns/index.d.ts +2 -0
- package/dist/system/story-sidebar-icons.json +4 -1
- package/package.json +2 -1
- package/src/__tests__/test-utils.ts +74 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
- package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
- package/src/components/UiAutocomplete/types.ts +11 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
- package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
- package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
- package/src/components/UiFadeMask/index.ts +6 -0
- package/src/components/UiFadeMask/types.ts +35 -0
- package/src/components/UiListbox/UiListbox.stories.ts +121 -0
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
- package/src/components/UiListbox/index.ts +1 -0
- package/src/components/UiListbox/types.ts +42 -0
- package/src/components/UiSelect/UiSelect.stories.ts +109 -1
- package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
- package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
- package/src/components/UiSelect/index.ts +1 -0
- package/src/components/UiSelect/types.ts +38 -0
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -5
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -11
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -1
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1064 -0
- package/src/patterns/UiProfileCard/index.ts +7 -0
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
- package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
- package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
- package/src/patterns/UiTopBar/index.ts +2 -0
- package/src/patterns/UiTopBar/types.ts +29 -0
- package/src/patterns/index.ts +2 -0
|
@@ -0,0 +1,1121 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
3
|
+
import { ref } from 'vue';
|
|
4
|
+
import UiTopBar from './UiTopBar.vue';
|
|
5
|
+
import type { UiTopBarProps } from './types';
|
|
6
|
+
import { UiAvatar, UiAvatarFallback } from '../../components/UiAvatar';
|
|
7
|
+
import { UiIcon } from '../../components/UiIcon';
|
|
8
|
+
import { UiSwitch } from '../../components/UiSwitch';
|
|
9
|
+
import { UiTooltip } from '../../components/UiTooltip';
|
|
10
|
+
import { UiFloatActionItems } from '../UiFloatActions';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* The bar itself ships no controls — these are the pieces of the reference
|
|
14
|
+
* design, composed in story land exactly as a product would compose them.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The Aleph Alpha mark, inlined from `public/aa_logo.svg` rather than loaded as
|
|
19
|
+
* an image so it fills with `currentColor` and follows the theme.
|
|
20
|
+
*/
|
|
21
|
+
const BRAND_MARK = `
|
|
22
|
+
<svg
|
|
23
|
+
class="h-5 w-5 shrink-0"
|
|
24
|
+
viewBox="24 24 102 102"
|
|
25
|
+
fill="currentColor"
|
|
26
|
+
aria-hidden="true"
|
|
27
|
+
focusable="false"
|
|
28
|
+
>
|
|
29
|
+
<path d="m34.67 106.43-5.55-13.55A19.14 19.14 0 0 0 29 57.42l5.47-13.59a33.78 33.78 0 0 1 .2 62.6Zm22.93 17.12-8.68-11.8a45.28 45.28 0 0 0 8.61-8.27L69 112.62a59.82 59.82 0 0 1-11.4 10.93Z" />
|
|
30
|
+
<path d="M82.23 75.17a60.37 60.37 0 0 0-24.64-48.39l-8.68 11.81a45.63 45.63 0 0 1 18.68 36.58 60.28 60.28 0 0 0 24.48 48.38l8.68-11.8a45.6 45.6 0 0 1-18.52-36.58Zm9.85-28.23-11.47-9.12a60.14 60.14 0 0 1 11.94-11.37l8.56 11.88a45.5 45.5 0 0 0-9.03 8.61ZM115 106.52a34.32 34.32 0 0 1-.29-62.52l6.1 13.32a19.68 19.68 0 0 0 .19 35.83Z" />
|
|
31
|
+
</svg>
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
/** `body-16-medium` is the 1rem / 600 step — the wordmark treatment. */
|
|
35
|
+
const WORDMARK_CLASS = 'body-16-medium';
|
|
36
|
+
|
|
37
|
+
/** Desktop wordmark: the product mark plus its name. */
|
|
38
|
+
const LOGO = `
|
|
39
|
+
<span class="flex items-center gap-2">
|
|
40
|
+
${BRAND_MARK}
|
|
41
|
+
<span class="${WORDMARK_CLASS} text-content-on-surface-primary">Phoenix</span>
|
|
42
|
+
</span>
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
/** Mobile brand content: the mark plus the product version. */
|
|
46
|
+
const BRAND_CONTENT = `
|
|
47
|
+
${BRAND_MARK}
|
|
48
|
+
<span class="${WORDMARK_CLASS}">Phoenix 1.2</span>
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* Every action carries a `UiTooltip`, on `side="bottom"` so the tip opens into
|
|
53
|
+
* the page instead of off the top edge. Each trigger is a real button, so the
|
|
54
|
+
* tip is reachable by keyboard focus and not only by hover.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/** The profile control: an avatar in a button, so it can be focused and named. */
|
|
58
|
+
const PROFILE = `
|
|
59
|
+
<UiTooltip content="Open profile menu" side="bottom">
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
aria-label="Open profile menu"
|
|
63
|
+
class="ui-focus-ring shrink-0 cursor-pointer rounded-full"
|
|
64
|
+
>
|
|
65
|
+
<UiAvatar :size="10">
|
|
66
|
+
<UiAvatarFallback class="bg-background-accent-pink">CN</UiAvatarFallback>
|
|
67
|
+
</UiAvatar>
|
|
68
|
+
</button>
|
|
69
|
+
</UiTooltip>
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The sidebar toggle: a plain icon button. `UiSidebarTrigger` would be the real
|
|
74
|
+
* control in an app, but it injects the sidebar context and so only works inside
|
|
75
|
+
* a `UiSidebarProvider` — scaffolding these stories don't need, since they show
|
|
76
|
+
* the bar rather than a sidebar.
|
|
77
|
+
*/
|
|
78
|
+
const SIDEBAR_TOGGLE = `
|
|
79
|
+
<UiTooltip content="Toggle sidebar" side="bottom">
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
aria-label="Toggle sidebar"
|
|
83
|
+
class="ui-focus-ring inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-sm text-content-on-surface-primary transition-colors hover:bg-background-surface-muted"
|
|
84
|
+
>
|
|
85
|
+
<UiIcon name="panel-left" size="s" />
|
|
86
|
+
</button>
|
|
87
|
+
</UiTooltip>
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
/** The desktop layout switch: a single-select pill toolbar. */
|
|
91
|
+
const LAYOUT_ACTIONS = `
|
|
92
|
+
<UiFloatActionItems v-model="layout" aria-label="Layout actions">
|
|
93
|
+
<UiTooltip content="Focus layout" side="bottom">
|
|
94
|
+
<UiFloatActionItems type="button" value="focus" aria-label="Focus layout">
|
|
95
|
+
<UiIcon name="scan" size="s" />
|
|
96
|
+
</UiFloatActionItems>
|
|
97
|
+
</UiTooltip>
|
|
98
|
+
<UiTooltip content="Split layout" side="bottom">
|
|
99
|
+
<UiFloatActionItems type="button" value="split" aria-label="Split layout">
|
|
100
|
+
<UiIcon name="panel-right" size="s" />
|
|
101
|
+
</UiFloatActionItems>
|
|
102
|
+
</UiTooltip>
|
|
103
|
+
</UiFloatActionItems>
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* Both mobile controls are `UiFloatActionItems`: the `toolbar` root supplies the
|
|
108
|
+
* pill — floating surface, border, radius, shadow — and each `button` item is the
|
|
109
|
+
* action inside it, the same chrome the desktop layout switch uses. The item is a
|
|
110
|
+
* 32px square by default, which the brand pill widens to fit its content.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/** The mobile brand pill: the logo, the version, and a chevron in one control. */
|
|
114
|
+
const BRAND_PILL = `
|
|
115
|
+
<UiFloatActionItems aria-label="Workspace">
|
|
116
|
+
<UiTooltip content="Switch workspace" side="bottom">
|
|
117
|
+
<UiFloatActionItems
|
|
118
|
+
type="button"
|
|
119
|
+
class="w-auto gap-2 px-3 text-content-on-surface-primary"
|
|
120
|
+
@click="onBrandClick"
|
|
121
|
+
>
|
|
122
|
+
${BRAND_CONTENT}
|
|
123
|
+
<UiIcon name="chevron-down" size="s" />
|
|
124
|
+
</UiFloatActionItems>
|
|
125
|
+
</UiTooltip>
|
|
126
|
+
</UiFloatActionItems>
|
|
127
|
+
`;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The mobile menu button, swapping its icon between hamburger and close. The tip
|
|
131
|
+
* follows the state, since the icon alone doesn't say what the next tap does.
|
|
132
|
+
*/
|
|
133
|
+
const MENU_BUTTON = `
|
|
134
|
+
<UiFloatActionItems aria-label="Navigation">
|
|
135
|
+
<UiTooltip :content="menuOpen ? 'Close menu' : 'Open menu'" side="bottom">
|
|
136
|
+
<UiFloatActionItems
|
|
137
|
+
type="button"
|
|
138
|
+
aria-label="Menu"
|
|
139
|
+
class="text-content-on-surface-primary"
|
|
140
|
+
:aria-expanded="menuOpen"
|
|
141
|
+
@click="menuOpen = !menuOpen"
|
|
142
|
+
>
|
|
143
|
+
<UiIcon :name="menuOpen ? 'x' : 'menu'" size="m" />
|
|
144
|
+
</UiFloatActionItems>
|
|
145
|
+
</UiTooltip>
|
|
146
|
+
</UiFloatActionItems>
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
/** Shared setup for the desktop reference design. */
|
|
150
|
+
function desktopSetup() {
|
|
151
|
+
const layout = ref('focus');
|
|
152
|
+
return { layout };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Shared setup for the mobile reference design. */
|
|
156
|
+
function mobileSetup() {
|
|
157
|
+
const menuOpen = ref(false);
|
|
158
|
+
return {
|
|
159
|
+
menuOpen,
|
|
160
|
+
// Stands in for opening a workspace or version menu, and shows up in the
|
|
161
|
+
// Actions panel so the pill's wiring is visible while browsing the story.
|
|
162
|
+
onBrandClick: fn(),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A labelled switch row. The label carries the name and extends the target,
|
|
168
|
+
* which the 36×20px track needs to clear the 24px minimum (WCAG 2.5.8).
|
|
169
|
+
* @param id Switch id, also used as its form name.
|
|
170
|
+
* @param model Ref to bind with `v-model`.
|
|
171
|
+
* @param label Visible label text.
|
|
172
|
+
* @returns Template string for the row.
|
|
173
|
+
*/
|
|
174
|
+
function switchRow(id: string, model: string, label: string): string {
|
|
175
|
+
return `
|
|
176
|
+
<label
|
|
177
|
+
for="${id}"
|
|
178
|
+
class="flex min-h-6 w-fit cursor-pointer items-center gap-x-3 py-1 label-14-medium text-content-on-surface-primary"
|
|
179
|
+
>
|
|
180
|
+
<UiSwitch id="${id}" v-model="${model}" name="${id}" />
|
|
181
|
+
<span>${label}</span>
|
|
182
|
+
</label>
|
|
183
|
+
`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The bar with a switch per region below it, shared by the visible story and
|
|
188
|
+
* its play function. Each slot is passed through `v-if`, so turning a switch off
|
|
189
|
+
* removes the slot rather than hiding its content.
|
|
190
|
+
* @param args Story args bound to the bar.
|
|
191
|
+
* @returns Story render definition.
|
|
192
|
+
*/
|
|
193
|
+
function renderSlotVisibility(args: UiTopBarProps = {}) {
|
|
194
|
+
return {
|
|
195
|
+
components: {
|
|
196
|
+
UiTopBar,
|
|
197
|
+
UiFloatActionItems,
|
|
198
|
+
UiAvatar,
|
|
199
|
+
UiAvatarFallback,
|
|
200
|
+
UiIcon,
|
|
201
|
+
UiSwitch,
|
|
202
|
+
UiTooltip,
|
|
203
|
+
},
|
|
204
|
+
setup() {
|
|
205
|
+
return {
|
|
206
|
+
args,
|
|
207
|
+
...desktopSetup(),
|
|
208
|
+
showLogo: ref(true),
|
|
209
|
+
showSidebarToggle: ref(true),
|
|
210
|
+
showLayoutActions: ref(true),
|
|
211
|
+
showProfile: ref(true),
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
template: `
|
|
215
|
+
<div class="flex flex-col gap-6">
|
|
216
|
+
<UiTopBar v-bind="args">
|
|
217
|
+
<template v-if="showLogo" #logo>${LOGO}</template>
|
|
218
|
+
<template v-if="showSidebarToggle" #sidebar-toggle>${SIDEBAR_TOGGLE}</template>
|
|
219
|
+
<template v-if="showLayoutActions" #layout-actions>${LAYOUT_ACTIONS}</template>
|
|
220
|
+
<template v-if="showProfile" #profile>${PROFILE}</template>
|
|
221
|
+
</UiTopBar>
|
|
222
|
+
|
|
223
|
+
<div class="flex flex-col gap-2 px-4">
|
|
224
|
+
<p class="label-14-medium text-content-on-surface-muted">Slots</p>
|
|
225
|
+
<div class="flex flex-wrap items-center gap-x-6 gap-y-1">
|
|
226
|
+
${switchRow('top-bar-show-logo', 'showLogo', 'Show logo')}
|
|
227
|
+
${switchRow('top-bar-show-sidebar-action', 'showSidebarToggle', 'Show sidebar action')}
|
|
228
|
+
${switchRow('top-bar-show-layout-switch', 'showLayoutActions', 'Show layout switch')}
|
|
229
|
+
${switchRow('top-bar-show-profile', 'showProfile', 'Show profile')}
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
</div>
|
|
233
|
+
`,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const meta = {
|
|
238
|
+
title: 'Patterns/UiTopBar',
|
|
239
|
+
component: UiTopBar,
|
|
240
|
+
tags: ['autodocs', 'experimental'],
|
|
241
|
+
parameters: {
|
|
242
|
+
// The top bar is part of the app's base layer, like the sidebar, so it is
|
|
243
|
+
// previewed directly on `background.surface.primary` rather than on a sheet.
|
|
244
|
+
surface: 'primary',
|
|
245
|
+
},
|
|
246
|
+
argTypes: {
|
|
247
|
+
leadingWidth: {
|
|
248
|
+
control: { type: 'number', min: 120, max: 400, step: 2 },
|
|
249
|
+
description:
|
|
250
|
+
'Width of the leading gutter (logo + sidebar toggle) in desktop mode',
|
|
251
|
+
},
|
|
252
|
+
ariaLabel: {
|
|
253
|
+
control: 'text',
|
|
254
|
+
description: 'Accessible name for the `banner` landmark',
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
args: {
|
|
258
|
+
leadingWidth: 238,
|
|
259
|
+
ariaLabel: 'Top bar',
|
|
260
|
+
},
|
|
261
|
+
} satisfies Meta<typeof UiTopBar>;
|
|
262
|
+
|
|
263
|
+
export default meta;
|
|
264
|
+
type Story = StoryObj<typeof meta>;
|
|
265
|
+
|
|
266
|
+
const desktopTemplateSource = `<template>
|
|
267
|
+
<UiTopBar>
|
|
268
|
+
<template #logo>
|
|
269
|
+
<AppWordmark />
|
|
270
|
+
</template>
|
|
271
|
+
|
|
272
|
+
<!-- Inside a UiSidebarProvider, reach for UiSidebarTrigger instead. -->
|
|
273
|
+
<template #sidebar-toggle>
|
|
274
|
+
<UiTooltip content="Toggle sidebar" side="bottom">
|
|
275
|
+
<button type="button" aria-label="Toggle sidebar" class="…icon button…">
|
|
276
|
+
<UiIcon name="panel-left" size="s" />
|
|
277
|
+
</button>
|
|
278
|
+
</UiTooltip>
|
|
279
|
+
</template>
|
|
280
|
+
|
|
281
|
+
<template #layout-actions>
|
|
282
|
+
<UiFloatActionItems v-model="layout" aria-label="Layout actions">
|
|
283
|
+
<UiTooltip content="Focus layout" side="bottom">
|
|
284
|
+
<UiFloatActionItems type="button" value="focus" aria-label="Focus layout">
|
|
285
|
+
<UiIcon name="scan" size="s" />
|
|
286
|
+
</UiFloatActionItems>
|
|
287
|
+
</UiTooltip>
|
|
288
|
+
<UiTooltip content="Split layout" side="bottom">
|
|
289
|
+
<UiFloatActionItems type="button" value="split" aria-label="Split layout">
|
|
290
|
+
<UiIcon name="panel-right" size="s" />
|
|
291
|
+
</UiFloatActionItems>
|
|
292
|
+
</UiTooltip>
|
|
293
|
+
</UiFloatActionItems>
|
|
294
|
+
</template>
|
|
295
|
+
|
|
296
|
+
<template #profile>
|
|
297
|
+
<UiTooltip content="Open profile menu" side="bottom">
|
|
298
|
+
<button
|
|
299
|
+
type="button"
|
|
300
|
+
aria-label="Open profile menu"
|
|
301
|
+
class="ui-focus-ring cursor-pointer rounded-full"
|
|
302
|
+
>
|
|
303
|
+
<UiAvatar :size="8">
|
|
304
|
+
<UiAvatarFallback class="bg-background-accent-pink">CN</UiAvatarFallback>
|
|
305
|
+
</UiAvatar>
|
|
306
|
+
</button>
|
|
307
|
+
</UiTooltip>
|
|
308
|
+
</template>
|
|
309
|
+
</UiTopBar>
|
|
310
|
+
</template>`;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* The reference design in desktop mode: a 238px leading gutter with the logo at
|
|
314
|
+
* its start and the sidebar toggle at its end, then the layout switch and the
|
|
315
|
+
* profile pinned to the far end.
|
|
316
|
+
*
|
|
317
|
+
* Nothing here comes from the bar itself. Each control is passed into a slot, so
|
|
318
|
+
* a product can swap the layout switch for its own toolbar without touching the
|
|
319
|
+
* shell.
|
|
320
|
+
*/
|
|
321
|
+
export const Desktop: Story = {
|
|
322
|
+
globals: { mediaBreakpoint: 'default' },
|
|
323
|
+
render: (args) => ({
|
|
324
|
+
components: {
|
|
325
|
+
UiTopBar,
|
|
326
|
+
UiFloatActionItems,
|
|
327
|
+
UiAvatar,
|
|
328
|
+
UiAvatarFallback,
|
|
329
|
+
UiIcon,
|
|
330
|
+
UiTooltip,
|
|
331
|
+
},
|
|
332
|
+
setup() {
|
|
333
|
+
return { args, ...desktopSetup() };
|
|
334
|
+
},
|
|
335
|
+
template: `
|
|
336
|
+
<UiTopBar v-bind="args">
|
|
337
|
+
<template #logo>${LOGO}</template>
|
|
338
|
+
<template #sidebar-toggle>${SIDEBAR_TOGGLE}</template>
|
|
339
|
+
<template #layout-actions>${LAYOUT_ACTIONS}</template>
|
|
340
|
+
<template #profile>${PROFILE}</template>
|
|
341
|
+
</UiTopBar>
|
|
342
|
+
`,
|
|
343
|
+
}),
|
|
344
|
+
parameters: {
|
|
345
|
+
docs: { source: { code: desktopTemplateSource } },
|
|
346
|
+
},
|
|
347
|
+
play: async ({ canvasElement, step }) => {
|
|
348
|
+
// Scenario (UiTopBar): a screen-reader user lands on the desktop bar and
|
|
349
|
+
// finds a named banner landmark holding the composed controls, each with its
|
|
350
|
+
// own accessible name. Non-mutating assertions only, so the Chromatic
|
|
351
|
+
// snapshot for this story stays valid.
|
|
352
|
+
const canvas = within(canvasElement);
|
|
353
|
+
|
|
354
|
+
await step(
|
|
355
|
+
'screen-reader: the bar is a named banner landmark (WCAG 1.3.1 / 4.1.2)',
|
|
356
|
+
async () => {
|
|
357
|
+
const banner = canvas.getByRole('banner', { name: 'Top bar' });
|
|
358
|
+
await expect(banner).toBeVisible();
|
|
359
|
+
await expect(banner).toHaveAttribute('data-mode', 'desktop');
|
|
360
|
+
},
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
await step(
|
|
364
|
+
'screen-reader: every composed control exposes an accessible name (WCAG 4.1.2)',
|
|
365
|
+
async () => {
|
|
366
|
+
await expect(
|
|
367
|
+
canvas.getByRole('button', { name: 'Toggle sidebar' }),
|
|
368
|
+
).toBeVisible();
|
|
369
|
+
await expect(
|
|
370
|
+
canvas.getByRole('toolbar', { name: 'Layout actions' }),
|
|
371
|
+
).toBeVisible();
|
|
372
|
+
await expect(
|
|
373
|
+
canvas.getByRole('button', { name: 'Focus layout' }),
|
|
374
|
+
).toHaveAttribute('aria-pressed', 'true');
|
|
375
|
+
},
|
|
376
|
+
);
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const mobileTemplateSource = `<template>
|
|
381
|
+
<UiTopBar>
|
|
382
|
+
<template #logo><AppWordmark /></template>
|
|
383
|
+
|
|
384
|
+
<template #mobile-logo>
|
|
385
|
+
<UiFloatActionItems aria-label="Workspace">
|
|
386
|
+
<UiTooltip content="Switch workspace" side="bottom">
|
|
387
|
+
<UiFloatActionItems
|
|
388
|
+
type="button"
|
|
389
|
+
class="w-auto gap-2 px-3"
|
|
390
|
+
@click="openWorkspaces"
|
|
391
|
+
>
|
|
392
|
+
<AppMark />
|
|
393
|
+
<span class="body-16-medium">Phoenix 1.2</span>
|
|
394
|
+
<UiIcon name="chevron-down" size="s" />
|
|
395
|
+
</UiFloatActionItems>
|
|
396
|
+
</UiTooltip>
|
|
397
|
+
</UiFloatActionItems>
|
|
398
|
+
</template>
|
|
399
|
+
|
|
400
|
+
<template #mobile-layout-actions>
|
|
401
|
+
<UiFloatActionItems aria-label="Navigation">
|
|
402
|
+
<UiTooltip :content="menuOpen ? 'Close menu' : 'Open menu'" side="bottom">
|
|
403
|
+
<UiFloatActionItems
|
|
404
|
+
type="button"
|
|
405
|
+
aria-label="Menu"
|
|
406
|
+
:aria-expanded="menuOpen"
|
|
407
|
+
@click="menuOpen = !menuOpen"
|
|
408
|
+
>
|
|
409
|
+
<UiIcon :name="menuOpen ? 'x' : 'menu'" size="m" />
|
|
410
|
+
</UiFloatActionItems>
|
|
411
|
+
</UiTooltip>
|
|
412
|
+
</UiFloatActionItems>
|
|
413
|
+
</template>
|
|
414
|
+
</UiTopBar>
|
|
415
|
+
</template>`;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* The reference design in mobile mode: the logo inside a brand pill that opens a
|
|
419
|
+
* workspace menu, and a round menu button whose icon swaps to a close icon while
|
|
420
|
+
* the menu is open.
|
|
421
|
+
*
|
|
422
|
+
* The bar contributes only the mode switch: `data-mode="mobile"`, no fixed
|
|
423
|
+
* gutter width, and `mobile-logo` / `mobile-layout-actions` taking precedence
|
|
424
|
+
* over their desktop counterparts. Switch the Media breakpoint toolbar between
|
|
425
|
+
* Mobile and Desktop to see both sets of slots.
|
|
426
|
+
*/
|
|
427
|
+
export const Mobile: Story = {
|
|
428
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
429
|
+
render: (args) => ({
|
|
430
|
+
components: { UiTopBar, UiIcon, UiFloatActionItems, UiTooltip },
|
|
431
|
+
setup() {
|
|
432
|
+
return { args, ...mobileSetup() };
|
|
433
|
+
},
|
|
434
|
+
template: `
|
|
435
|
+
<UiTopBar v-bind="args">
|
|
436
|
+
<template #logo>${LOGO}</template>
|
|
437
|
+
<template #mobile-logo>${BRAND_PILL}</template>
|
|
438
|
+
<template #mobile-layout-actions>${MENU_BUTTON}</template>
|
|
439
|
+
</UiTopBar>
|
|
440
|
+
`,
|
|
441
|
+
}),
|
|
442
|
+
parameters: {
|
|
443
|
+
docs: { source: { code: mobileTemplateSource } },
|
|
444
|
+
},
|
|
445
|
+
play: async ({ canvasElement, step }) => {
|
|
446
|
+
// Scenario (UiTopBar): the mobile bar offers the two designed controls — the
|
|
447
|
+
// brand pill and the collapsed menu button — and reports mobile mode.
|
|
448
|
+
// Non-mutating assertions only, so the snapshot stays valid.
|
|
449
|
+
const canvas = within(canvasElement);
|
|
450
|
+
|
|
451
|
+
await step(
|
|
452
|
+
'mobile: the bar reports mobile mode at the 320px breakpoint',
|
|
453
|
+
async () => {
|
|
454
|
+
await expect(canvas.getByRole('banner')).toHaveAttribute(
|
|
455
|
+
'data-mode',
|
|
456
|
+
'mobile',
|
|
457
|
+
);
|
|
458
|
+
},
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
await step(
|
|
462
|
+
'screen-reader: the mobile slots replace the desktop logo (WCAG 4.1.2)',
|
|
463
|
+
async () => {
|
|
464
|
+
await expect(
|
|
465
|
+
canvas.getByRole('button', { name: /Phoenix 1\.2/ }),
|
|
466
|
+
).toBeVisible();
|
|
467
|
+
await expect(
|
|
468
|
+
canvas.getByRole('button', { name: 'Menu' }),
|
|
469
|
+
).toHaveAttribute('aria-expanded', 'false');
|
|
470
|
+
},
|
|
471
|
+
);
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const slotVisibilityTemplateSource = `<script setup lang="ts">
|
|
476
|
+
import { ref } from 'vue'
|
|
477
|
+
import { UiSwitch, UiTopBar } from '@aleph-alpha/ui-library'
|
|
478
|
+
|
|
479
|
+
const showLogo = ref(true)
|
|
480
|
+
const showSidebarToggle = ref(true)
|
|
481
|
+
const showLayoutActions = ref(true)
|
|
482
|
+
const showProfile = ref(true)
|
|
483
|
+
</script>
|
|
484
|
+
|
|
485
|
+
<template>
|
|
486
|
+
<UiTopBar>
|
|
487
|
+
<template v-if="showLogo" #logo>
|
|
488
|
+
<AppWordmark />
|
|
489
|
+
</template>
|
|
490
|
+
|
|
491
|
+
<template v-if="showSidebarToggle" #sidebar-toggle>
|
|
492
|
+
<SidebarToggle />
|
|
493
|
+
</template>
|
|
494
|
+
|
|
495
|
+
<template v-if="showLayoutActions" #layout-actions>
|
|
496
|
+
<LayoutSwitch v-model="layout" />
|
|
497
|
+
</template>
|
|
498
|
+
|
|
499
|
+
<template v-if="showProfile" #profile>
|
|
500
|
+
<ProfileMenu />
|
|
501
|
+
</template>
|
|
502
|
+
</UiTopBar>
|
|
503
|
+
|
|
504
|
+
<label for="show-logo" class="flex min-h-6 w-fit items-center gap-x-3 py-1 label-14-medium">
|
|
505
|
+
<UiSwitch id="show-logo" v-model="showLogo" name="show-logo" />
|
|
506
|
+
<span>Show logo</span>
|
|
507
|
+
</label>
|
|
508
|
+
</template>`;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Which regions the bar shows is entirely up to what you pass in. Toggle the
|
|
512
|
+
* switches below to add and remove each slot.
|
|
513
|
+
*
|
|
514
|
+
* Guarding a slot with `v-if` removes it, so the bar sees no slot at all rather
|
|
515
|
+
* than an empty one. The surrounding layout is unaffected: the trailing actions
|
|
516
|
+
* stay pinned to the end, and the leading gutter keeps its width so the logo
|
|
517
|
+
* still lines up with the sidebar — even when the gutter is empty.
|
|
518
|
+
*/
|
|
519
|
+
export const SlotVisibility: Story = {
|
|
520
|
+
globals: { mediaBreakpoint: 'default' },
|
|
521
|
+
render: (args) => renderSlotVisibility(args),
|
|
522
|
+
parameters: {
|
|
523
|
+
docs: { source: { code: slotVisibilityTemplateSource } },
|
|
524
|
+
},
|
|
525
|
+
play: async ({ canvasElement, step }) => {
|
|
526
|
+
// Scenario (UiTopBar): the story opens with every region filled and each
|
|
527
|
+
// switch on, so the labels match what the bar shows. Non-mutating, so the
|
|
528
|
+
// Chromatic snapshot for this story stays valid — the toggling itself is
|
|
529
|
+
// covered by the hidden `test - Slot visibility` story.
|
|
530
|
+
const canvas = within(canvasElement);
|
|
531
|
+
|
|
532
|
+
await step(
|
|
533
|
+
'screen-reader: each switch is named by its visible label and reports its state (WCAG 1.3.1 / 4.1.2)',
|
|
534
|
+
async () => {
|
|
535
|
+
for (const name of [
|
|
536
|
+
'Show logo',
|
|
537
|
+
'Show sidebar action',
|
|
538
|
+
'Show layout switch',
|
|
539
|
+
'Show profile',
|
|
540
|
+
]) {
|
|
541
|
+
await expect(canvas.getByRole('switch', { name })).toBeChecked();
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
await step('interaction: every region starts filled', async () => {
|
|
547
|
+
await expect(canvas.getByText('Phoenix')).toBeVisible();
|
|
548
|
+
await expect(
|
|
549
|
+
canvas.getByRole('button', { name: 'Toggle sidebar' }),
|
|
550
|
+
).toBeVisible();
|
|
551
|
+
await expect(
|
|
552
|
+
canvas.getByRole('toolbar', { name: 'Layout actions' }),
|
|
553
|
+
).toBeVisible();
|
|
554
|
+
await expect(
|
|
555
|
+
canvas.getByRole('button', { name: 'Open profile menu' }),
|
|
556
|
+
).toBeVisible();
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Accessibility guidance for the top bar: the banner landmark, naming the
|
|
563
|
+
* controls you pass in, focus order, and the accessibility theme for contrast.
|
|
564
|
+
*/
|
|
565
|
+
export const Accessibility: Story = {
|
|
566
|
+
render: () => ({
|
|
567
|
+
components: {
|
|
568
|
+
UiTopBar,
|
|
569
|
+
UiFloatActionItems,
|
|
570
|
+
UiAvatar,
|
|
571
|
+
UiAvatarFallback,
|
|
572
|
+
UiIcon,
|
|
573
|
+
UiTooltip,
|
|
574
|
+
},
|
|
575
|
+
setup: desktopSetup,
|
|
576
|
+
template: `
|
|
577
|
+
<section class="flex flex-col gap-6 p-4">
|
|
578
|
+
<div>
|
|
579
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
580
|
+
Accessibility
|
|
581
|
+
</h2>
|
|
582
|
+
</div>
|
|
583
|
+
|
|
584
|
+
<div class="flex flex-col gap-6">
|
|
585
|
+
<div class="flex flex-col gap-2">
|
|
586
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
587
|
+
Requirements
|
|
588
|
+
</h3>
|
|
589
|
+
<ul class="body-16-regular list-disc pl-5 text-content-on-surface-primary">
|
|
590
|
+
<li>The bar renders a <code class="label-14-regular">header</code> element, so it is a <code class="label-14-regular">banner</code> landmark. Name it with <code class="label-14-regular">aria-label</code> when a page has more than one.</li>
|
|
591
|
+
<li>Only one bar per page may be a banner — nest the rest inside a landmark, or drop the label.</li>
|
|
592
|
+
<li>The bar ships no controls, so naming them is on you: every icon-only control you pass in needs an <code class="label-14-regular">aria-label</code>.</li>
|
|
593
|
+
<li>A control that toggles something (a menu button, the sidebar trigger) must carry <code class="label-14-regular">aria-expanded</code>, so a swapped icon is never the only signal.</li>
|
|
594
|
+
<li>Use <code class="label-14-regular">aria-pressed</code> on a layout switch so the selection is not conveyed by colour alone.</li>
|
|
595
|
+
<li>Focus order follows DOM order: leading gutter, then trailing actions, then profile. Keep that order in the default slot too.</li>
|
|
596
|
+
<li>Mobile controls need a 24px minimum target; the reference pills are 40px.</li>
|
|
597
|
+
<li>Wrap each icon-only action in <code class="label-14-regular">UiTooltip</code> on a focusable trigger, so the tip is reachable by keyboard and not only by hover. A tooltip supplements the accessible name, it never replaces it.</li>
|
|
598
|
+
</ul>
|
|
599
|
+
</div>
|
|
600
|
+
|
|
601
|
+
<div class="flex flex-col gap-2">
|
|
602
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
603
|
+
Enable accessibility theme
|
|
604
|
+
</h3>
|
|
605
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
606
|
+
When accessibility is required, enable our accessibility theme. This
|
|
607
|
+
increases contrast and ensures there are no color contrast issues.
|
|
608
|
+
</p>
|
|
609
|
+
</div>
|
|
610
|
+
</div>
|
|
611
|
+
|
|
612
|
+
<div class="flex flex-col gap-4">
|
|
613
|
+
<div class="flex flex-col gap-3">
|
|
614
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
615
|
+
Default
|
|
616
|
+
</h3>
|
|
617
|
+
<UiTopBar aria-label="Default top bar">
|
|
618
|
+
<template #logo>${LOGO}</template>
|
|
619
|
+
<template #sidebar-toggle>${SIDEBAR_TOGGLE}</template>
|
|
620
|
+
<template #layout-actions>${LAYOUT_ACTIONS}</template>
|
|
621
|
+
<template #profile>${PROFILE}</template>
|
|
622
|
+
</UiTopBar>
|
|
623
|
+
</div>
|
|
624
|
+
|
|
625
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
626
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
627
|
+
Accessible
|
|
628
|
+
</h3>
|
|
629
|
+
<UiTopBar aria-label="Accessible top bar">
|
|
630
|
+
<template #logo>${LOGO}</template>
|
|
631
|
+
<template #sidebar-toggle>${SIDEBAR_TOGGLE}</template>
|
|
632
|
+
<template #layout-actions>${LAYOUT_ACTIONS}</template>
|
|
633
|
+
<template #profile>${PROFILE}</template>
|
|
634
|
+
</UiTopBar>
|
|
635
|
+
</div>
|
|
636
|
+
</div>
|
|
637
|
+
</section>
|
|
638
|
+
`,
|
|
639
|
+
}),
|
|
640
|
+
tags: ['!autodocs'],
|
|
641
|
+
parameters: {
|
|
642
|
+
a11y: { test: 'off' },
|
|
643
|
+
chromatic: { disableSnapshot: true },
|
|
644
|
+
docs: { canvas: { sourceState: 'none' } },
|
|
645
|
+
},
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
/*
|
|
649
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
650
|
+
* Interaction & accessibility tests (play functions)
|
|
651
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
652
|
+
* Each story below is a hidden, test-only story (`name: 'test - …'`,
|
|
653
|
+
* `tags: ['!dev', '!autodocs']`): excluded from the sidebar and docs, but still
|
|
654
|
+
* run by the Storybook `test-runner` on every PR, in the accessible theme,
|
|
655
|
+
* alongside the axe audit. Assertions are grouped into category-labelled
|
|
656
|
+
* `step()` calls, and the prefix is parsed into the per-story summary table and
|
|
657
|
+
* the scenarios PDF (`pnpm report:scenarios-pdf`), so keep it accurate:
|
|
658
|
+
* • `interaction:` behaviour, guards, emitted events (WCAG 4.1.2)
|
|
659
|
+
* • `keyboard:` Tab order, Enter / Space / Arrow / Escape (WCAG 2.1.1, 2.4.3)
|
|
660
|
+
* • `screen-reader:` accessible names, roles, ARIA state (WCAG 4.1.2)
|
|
661
|
+
* • `zoom:` usable at 200% page zoom (WCAG 1.4.4)
|
|
662
|
+
* • `mobile:` 320px reflow + touch-target size (WCAG 1.4.10, 2.5.8)
|
|
663
|
+
* The Accessibility column is filled by the axe audit that runs on every story
|
|
664
|
+
* — never add an `a11y:` prefix. Non-mutating checks live on the visible
|
|
665
|
+
* `Desktop` and `Mobile` stories so their snapshots stay valid; anything that
|
|
666
|
+
* moves focus or changes state lives here. Since the bar owns layout rather than
|
|
667
|
+
* controls, these plays exercise the reference design through its slots.
|
|
668
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
669
|
+
*/
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Focus order across the composed desktop controls, and the layout switch as a
|
|
673
|
+
* single Tab stop. Hidden test-only story.
|
|
674
|
+
*/
|
|
675
|
+
export const KeyboardFocusOrder: Story = {
|
|
676
|
+
name: 'test - Keyboard focus order',
|
|
677
|
+
tags: ['!dev', '!autodocs'],
|
|
678
|
+
render: () => ({
|
|
679
|
+
components: {
|
|
680
|
+
UiTopBar,
|
|
681
|
+
UiFloatActionItems,
|
|
682
|
+
UiAvatar,
|
|
683
|
+
UiAvatarFallback,
|
|
684
|
+
UiIcon,
|
|
685
|
+
UiTooltip,
|
|
686
|
+
},
|
|
687
|
+
setup: desktopSetup,
|
|
688
|
+
template: `
|
|
689
|
+
<UiTopBar>
|
|
690
|
+
<template #logo>${LOGO}</template>
|
|
691
|
+
<template #sidebar-toggle>${SIDEBAR_TOGGLE}</template>
|
|
692
|
+
<template #layout-actions>${LAYOUT_ACTIONS}</template>
|
|
693
|
+
<template #profile>${PROFILE}</template>
|
|
694
|
+
</UiTopBar>
|
|
695
|
+
`,
|
|
696
|
+
}),
|
|
697
|
+
parameters: {
|
|
698
|
+
// The play moves focus, so the focus ring would register as a diff.
|
|
699
|
+
chromatic: { disableSnapshot: true },
|
|
700
|
+
},
|
|
701
|
+
play: async ({ canvasElement, step }) => {
|
|
702
|
+
// Scenario (UiTopBar): a keyboard user Tabs across the bar. Focus follows the
|
|
703
|
+
// visual left-to-right order — gutter toggle, layout switch, profile — and
|
|
704
|
+
// the switch consumes a single Tab stop with Arrow keys moving between its
|
|
705
|
+
// modes.
|
|
706
|
+
const canvas = within(canvasElement);
|
|
707
|
+
const toggle = canvas.getByRole('button', { name: 'Toggle sidebar' });
|
|
708
|
+
const focusAction = canvas.getByRole('button', { name: 'Focus layout' });
|
|
709
|
+
const splitAction = canvas.getByRole('button', { name: 'Split layout' });
|
|
710
|
+
const profile = canvas.getByRole('button', { name: 'Open profile menu' });
|
|
711
|
+
|
|
712
|
+
await step(
|
|
713
|
+
'keyboard: Tab reaches the gutter toggle first (WCAG 2.4.3)',
|
|
714
|
+
async () => {
|
|
715
|
+
await userEvent.tab();
|
|
716
|
+
await expect(toggle).toHaveFocus();
|
|
717
|
+
},
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
await step(
|
|
721
|
+
'keyboard: the layout switch is one Tab stop with Arrow-key movement (WCAG 2.1.1)',
|
|
722
|
+
async () => {
|
|
723
|
+
await userEvent.tab();
|
|
724
|
+
await expect(focusAction).toHaveFocus();
|
|
725
|
+
await userEvent.keyboard('{ArrowRight}');
|
|
726
|
+
await expect(splitAction).toHaveFocus();
|
|
727
|
+
},
|
|
728
|
+
);
|
|
729
|
+
|
|
730
|
+
await step(
|
|
731
|
+
'screen-reader: the focused action describes itself through its tooltip (WCAG 4.1.2)',
|
|
732
|
+
async () => {
|
|
733
|
+
await waitFor(() =>
|
|
734
|
+
expect(splitAction).toHaveAccessibleDescription('Split layout'),
|
|
735
|
+
);
|
|
736
|
+
},
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
await step(
|
|
740
|
+
'keyboard: Tab leaves the switch and lands on the profile (WCAG 2.4.3)',
|
|
741
|
+
async () => {
|
|
742
|
+
await userEvent.tab();
|
|
743
|
+
await expect(profile).toHaveFocus();
|
|
744
|
+
},
|
|
745
|
+
);
|
|
746
|
+
|
|
747
|
+
await step(
|
|
748
|
+
'interaction: activating a layout moves the pressed state (WCAG 4.1.2)',
|
|
749
|
+
async () => {
|
|
750
|
+
await userEvent.click(splitAction);
|
|
751
|
+
await expect(splitAction).toHaveAttribute('aria-pressed', 'true');
|
|
752
|
+
await expect(focusAction).toHaveAttribute('aria-pressed', 'false');
|
|
753
|
+
},
|
|
754
|
+
);
|
|
755
|
+
},
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Filling the default slot replaces the region layout while the padded banner
|
|
760
|
+
* shell stays. Hidden test-only story.
|
|
761
|
+
*/
|
|
762
|
+
export const DefaultSlotWrapper: Story = {
|
|
763
|
+
name: 'test - Default slot wrapper',
|
|
764
|
+
tags: ['!dev', '!autodocs'],
|
|
765
|
+
render: () => ({
|
|
766
|
+
components: { UiTopBar },
|
|
767
|
+
template: `
|
|
768
|
+
<UiTopBar v-slot="{ isMobile }">
|
|
769
|
+
${LOGO}
|
|
770
|
+
<span data-testid="mode" class="body-14-regular text-content-on-surface-muted">
|
|
771
|
+
{{ isMobile ? 'mobile' : 'desktop' }}
|
|
772
|
+
</span>
|
|
773
|
+
<button type="button" class="ml-auto label-14-medium">Publish</button>
|
|
774
|
+
</UiTopBar>
|
|
775
|
+
`,
|
|
776
|
+
}),
|
|
777
|
+
parameters: { chromatic: { disableSnapshot: true } },
|
|
778
|
+
play: async ({ canvasElement, step }) => {
|
|
779
|
+
// Scenario (UiTopBar): a product composes the whole bar by hand. The default
|
|
780
|
+
// slot replaces the leading and trailing regions, keeps the banner landmark
|
|
781
|
+
// and padding, and reports the current mode to its content.
|
|
782
|
+
const canvas = within(canvasElement);
|
|
783
|
+
|
|
784
|
+
await step(
|
|
785
|
+
'screen-reader: the banner landmark survives custom content (WCAG 1.3.1)',
|
|
786
|
+
async () => {
|
|
787
|
+
const banner = canvas.getByRole('banner', { name: 'Top bar' });
|
|
788
|
+
await expect(banner).toBeVisible();
|
|
789
|
+
await expect(banner).toHaveClass('px-4', 'py-2.5');
|
|
790
|
+
},
|
|
791
|
+
);
|
|
792
|
+
|
|
793
|
+
await step('interaction: the region layout is replaced', async () => {
|
|
794
|
+
await expect(
|
|
795
|
+
canvasElement.querySelector('[data-slot="top-bar-leading"]'),
|
|
796
|
+
).toBeNull();
|
|
797
|
+
await expect(
|
|
798
|
+
canvasElement.querySelector('[data-slot="top-bar-trailing"]'),
|
|
799
|
+
).toBeNull();
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
await step(
|
|
803
|
+
'interaction: the current mode is exposed to the slot',
|
|
804
|
+
async () => {
|
|
805
|
+
await expect(canvas.getByTestId('mode')).toHaveTextContent('desktop');
|
|
806
|
+
},
|
|
807
|
+
);
|
|
808
|
+
},
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Each switch adds and removes its slot, leaving the rest of the bar in place.
|
|
813
|
+
* Hidden test-only story.
|
|
814
|
+
*/
|
|
815
|
+
export const SlotVisibilityToggles: Story = {
|
|
816
|
+
name: 'test - Slot visibility',
|
|
817
|
+
tags: ['!dev', '!autodocs'],
|
|
818
|
+
render: () => renderSlotVisibility(),
|
|
819
|
+
parameters: {
|
|
820
|
+
// The play empties the bar, so the snapshot would differ from the story.
|
|
821
|
+
chromatic: { disableSnapshot: true },
|
|
822
|
+
},
|
|
823
|
+
play: async ({ canvasElement, step }) => {
|
|
824
|
+
// Scenario (UiTopBar): someone turns each region off in turn and finds its
|
|
825
|
+
// control gone from the bar, while the bar itself and the regions that are
|
|
826
|
+
// still filled stay put. Turning a switch back on restores its control.
|
|
827
|
+
const canvas = within(canvasElement);
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Turns a switch off, or back on, by its visible label.
|
|
831
|
+
* @param label Visible label of the switch to flip.
|
|
832
|
+
*/
|
|
833
|
+
const toggle = async (label: string) => {
|
|
834
|
+
await userEvent.click(canvas.getByRole('switch', { name: label }));
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
await step(
|
|
838
|
+
'interaction: turning off a switch removes its control from the bar',
|
|
839
|
+
async () => {
|
|
840
|
+
await toggle('Show logo');
|
|
841
|
+
await waitFor(() => expect(canvas.queryByText('Phoenix')).toBeNull());
|
|
842
|
+
|
|
843
|
+
await toggle('Show sidebar action');
|
|
844
|
+
await waitFor(() =>
|
|
845
|
+
expect(
|
|
846
|
+
canvas.queryByRole('button', { name: 'Toggle sidebar' }),
|
|
847
|
+
).toBeNull(),
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
await toggle('Show layout switch');
|
|
851
|
+
await waitFor(() =>
|
|
852
|
+
expect(
|
|
853
|
+
canvas.queryByRole('toolbar', { name: 'Layout actions' }),
|
|
854
|
+
).toBeNull(),
|
|
855
|
+
);
|
|
856
|
+
|
|
857
|
+
await toggle('Show profile');
|
|
858
|
+
await waitFor(() =>
|
|
859
|
+
expect(
|
|
860
|
+
canvas.queryByRole('button', { name: 'Open profile menu' }),
|
|
861
|
+
).toBeNull(),
|
|
862
|
+
);
|
|
863
|
+
},
|
|
864
|
+
);
|
|
865
|
+
|
|
866
|
+
await step(
|
|
867
|
+
'interaction: the emptied bar keeps its landmark and its regions',
|
|
868
|
+
async () => {
|
|
869
|
+
await expect(
|
|
870
|
+
canvas.getByRole('banner', { name: 'Top bar' }),
|
|
871
|
+
).toBeVisible();
|
|
872
|
+
await expect(
|
|
873
|
+
canvasElement.querySelector('[data-slot="top-bar-leading"]'),
|
|
874
|
+
).not.toBeNull();
|
|
875
|
+
await expect(
|
|
876
|
+
canvasElement.querySelector('[data-slot="top-bar-trailing"]'),
|
|
877
|
+
).not.toBeNull();
|
|
878
|
+
},
|
|
879
|
+
);
|
|
880
|
+
|
|
881
|
+
await step(
|
|
882
|
+
'interaction: turning a switch back on restores its control',
|
|
883
|
+
async () => {
|
|
884
|
+
await toggle('Show profile');
|
|
885
|
+
await waitFor(() =>
|
|
886
|
+
expect(
|
|
887
|
+
canvas.getByRole('button', { name: 'Open profile menu' }),
|
|
888
|
+
).toBeVisible(),
|
|
889
|
+
);
|
|
890
|
+
// The regions it shares the bar with are still off.
|
|
891
|
+
await expect(canvas.queryByText('Phoenix')).toBeNull();
|
|
892
|
+
},
|
|
893
|
+
);
|
|
894
|
+
|
|
895
|
+
await step(
|
|
896
|
+
'keyboard: a switch can be flipped without a pointer (WCAG 2.1.1)',
|
|
897
|
+
async () => {
|
|
898
|
+
const showLogo = canvas.getByRole('switch', { name: 'Show logo' });
|
|
899
|
+
showLogo.focus();
|
|
900
|
+
await userEvent.keyboard(' ');
|
|
901
|
+
await expect(showLogo).toBeChecked();
|
|
902
|
+
await waitFor(() => expect(canvas.getByText('Phoenix')).toBeVisible());
|
|
903
|
+
},
|
|
904
|
+
);
|
|
905
|
+
},
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
910
|
+
* try 400% reflow (WCAG 1.4.10). Hidden test-only story.
|
|
911
|
+
*/
|
|
912
|
+
export const ZoomMagnification: Story = {
|
|
913
|
+
name: 'test - Zoom magnification',
|
|
914
|
+
tags: ['!dev', '!autodocs'],
|
|
915
|
+
globals: { zoom: '200' },
|
|
916
|
+
render: () => ({
|
|
917
|
+
components: {
|
|
918
|
+
UiTopBar,
|
|
919
|
+
UiFloatActionItems,
|
|
920
|
+
UiAvatar,
|
|
921
|
+
UiAvatarFallback,
|
|
922
|
+
UiIcon,
|
|
923
|
+
UiTooltip,
|
|
924
|
+
},
|
|
925
|
+
setup: desktopSetup,
|
|
926
|
+
template: `
|
|
927
|
+
<UiTopBar>
|
|
928
|
+
<template #logo>${LOGO}</template>
|
|
929
|
+
<template #layout-actions>${LAYOUT_ACTIONS}</template>
|
|
930
|
+
<template #profile>${PROFILE}</template>
|
|
931
|
+
</UiTopBar>
|
|
932
|
+
`,
|
|
933
|
+
}),
|
|
934
|
+
parameters: {
|
|
935
|
+
// Magnified snapshots are already covered by the accessible-reflow
|
|
936
|
+
// Chromatic mode.
|
|
937
|
+
chromatic: { disableSnapshot: true },
|
|
938
|
+
docs: {
|
|
939
|
+
description: {
|
|
940
|
+
story:
|
|
941
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
},
|
|
945
|
+
play: async ({ canvasElement, step }) => {
|
|
946
|
+
// Scenario (UiTopBar): at 200% page zoom the bar keeps its landmark, the logo
|
|
947
|
+
// and composed actions stay visible, and the layout switch stays operable.
|
|
948
|
+
const canvas = within(canvasElement);
|
|
949
|
+
const splitAction = canvas.getByRole('button', { name: 'Split layout' });
|
|
950
|
+
|
|
951
|
+
await step(
|
|
952
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
953
|
+
async () => {
|
|
954
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
955
|
+
},
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
await step(
|
|
959
|
+
'zoom: the bar, its logo, and the composed actions stay visible',
|
|
960
|
+
async () => {
|
|
961
|
+
await expect(canvas.getByRole('banner')).toBeVisible();
|
|
962
|
+
await expect(canvas.getByText('Phoenix')).toBeVisible();
|
|
963
|
+
await expect(
|
|
964
|
+
canvas.getByRole('toolbar', { name: 'Layout actions' }),
|
|
965
|
+
).toBeVisible();
|
|
966
|
+
},
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
await step('zoom: remains operable when magnified', async () => {
|
|
970
|
+
await userEvent.click(splitAction);
|
|
971
|
+
await expect(splitAction).toHaveAttribute('aria-pressed', 'true');
|
|
972
|
+
});
|
|
973
|
+
},
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Rendered at the 320px mobile reflow breakpoint: the bar switches modes, the
|
|
978
|
+
* mobile slots take over, and both controls stay reachable and tappable. Hidden
|
|
979
|
+
* test-only story.
|
|
980
|
+
*/
|
|
981
|
+
export const MobileBreakpoint: Story = {
|
|
982
|
+
name: 'test - Mobile breakpoint',
|
|
983
|
+
tags: ['!dev', '!autodocs'],
|
|
984
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
985
|
+
render: () => ({
|
|
986
|
+
components: { UiTopBar, UiIcon, UiFloatActionItems, UiTooltip },
|
|
987
|
+
setup: mobileSetup,
|
|
988
|
+
template: `
|
|
989
|
+
<UiTopBar>
|
|
990
|
+
<template #logo>${LOGO}</template>
|
|
991
|
+
<template #mobile-logo>${BRAND_PILL}</template>
|
|
992
|
+
<template #mobile-layout-actions>${MENU_BUTTON}</template>
|
|
993
|
+
</UiTopBar>
|
|
994
|
+
`,
|
|
995
|
+
}),
|
|
996
|
+
parameters: {
|
|
997
|
+
// Reflow snapshots are covered by the accessible-reflow Chromatic mode, and
|
|
998
|
+
// the play moves focus.
|
|
999
|
+
chromatic: { disableSnapshot: true },
|
|
1000
|
+
docs: {
|
|
1001
|
+
description: {
|
|
1002
|
+
story:
|
|
1003
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1004
|
+
},
|
|
1005
|
+
},
|
|
1006
|
+
},
|
|
1007
|
+
play: async ({ canvasElement, step }) => {
|
|
1008
|
+
// Scenario (UiTopBar): at 320px the bar switches to mobile mode, swaps the
|
|
1009
|
+
// desktop logo for the brand pill, keeps both controls reachable in visual
|
|
1010
|
+
// order by keyboard, and leaves them large enough to tap.
|
|
1011
|
+
const canvas = within(canvasElement);
|
|
1012
|
+
const brand = canvas.getByRole('button', { name: /Phoenix 1\.2/ });
|
|
1013
|
+
const menu = canvas.getByRole('button', { name: 'Menu' });
|
|
1014
|
+
|
|
1015
|
+
await step(
|
|
1016
|
+
'mobile: the bar switches to mobile mode and drops the gutter width (WCAG 1.4.10)',
|
|
1017
|
+
async () => {
|
|
1018
|
+
await expect(canvas.getByRole('banner')).toHaveAttribute(
|
|
1019
|
+
'data-mode',
|
|
1020
|
+
'mobile',
|
|
1021
|
+
);
|
|
1022
|
+
const leading = canvasElement.querySelector<HTMLElement>(
|
|
1023
|
+
'[data-slot="top-bar-leading"]',
|
|
1024
|
+
);
|
|
1025
|
+
await expect(leading).not.toBeNull();
|
|
1026
|
+
await expect(leading?.className).not.toContain('w-[var(');
|
|
1027
|
+
},
|
|
1028
|
+
);
|
|
1029
|
+
|
|
1030
|
+
await step(
|
|
1031
|
+
'mobile: Tab reaches the brand pill, then the menu button (WCAG 2.1.1 / 2.4.3)',
|
|
1032
|
+
async () => {
|
|
1033
|
+
await userEvent.tab();
|
|
1034
|
+
await expect(brand).toHaveFocus();
|
|
1035
|
+
await userEvent.tab();
|
|
1036
|
+
await expect(menu).toHaveFocus();
|
|
1037
|
+
},
|
|
1038
|
+
);
|
|
1039
|
+
|
|
1040
|
+
await step(
|
|
1041
|
+
'mobile: both controls meet the minimum touch-target size (WCAG 2.5.8)',
|
|
1042
|
+
async () => {
|
|
1043
|
+
for (const control of [brand, menu]) {
|
|
1044
|
+
const { width, height } = control.getBoundingClientRect();
|
|
1045
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1046
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1047
|
+
}
|
|
1048
|
+
},
|
|
1049
|
+
);
|
|
1050
|
+
},
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* The mobile menu button swaps its icon between hamburger and close while
|
|
1055
|
+
* reporting `aria-expanded`. Hidden test-only story.
|
|
1056
|
+
*/
|
|
1057
|
+
export const MobileMenuToggle: Story = {
|
|
1058
|
+
name: 'test - Mobile menu toggle',
|
|
1059
|
+
tags: ['!dev', '!autodocs'],
|
|
1060
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1061
|
+
render: () => ({
|
|
1062
|
+
components: { UiTopBar, UiIcon, UiFloatActionItems, UiTooltip },
|
|
1063
|
+
setup: mobileSetup,
|
|
1064
|
+
template: `
|
|
1065
|
+
<UiTopBar>
|
|
1066
|
+
<template #mobile-logo>${BRAND_PILL}</template>
|
|
1067
|
+
<template #mobile-layout-actions>${MENU_BUTTON}</template>
|
|
1068
|
+
</UiTopBar>
|
|
1069
|
+
`,
|
|
1070
|
+
}),
|
|
1071
|
+
parameters: {
|
|
1072
|
+
// The play opens the menu, so the swapped icon would register as a diff.
|
|
1073
|
+
chromatic: { disableSnapshot: true },
|
|
1074
|
+
},
|
|
1075
|
+
play: async ({ canvasElement, step }) => {
|
|
1076
|
+
// Scenario (UiTopBar): a mobile user taps the menu button in the reference
|
|
1077
|
+
// design. The icon becomes a close icon and the expanded state is announced,
|
|
1078
|
+
// so whatever the app opens from that state reads as expanded too. Pressing
|
|
1079
|
+
// again restores the hamburger.
|
|
1080
|
+
const canvas = within(canvasElement);
|
|
1081
|
+
const menu = canvas.getByRole('button', { name: 'Menu' });
|
|
1082
|
+
|
|
1083
|
+
/** Reads the lucide icon currently rendered inside the button. */
|
|
1084
|
+
const iconName = () =>
|
|
1085
|
+
menu.querySelector('svg')?.classList.contains('lucide-x') ? 'x' : 'menu';
|
|
1086
|
+
|
|
1087
|
+
await step(
|
|
1088
|
+
'interaction: opens closed, showing the hamburger icon',
|
|
1089
|
+
async () => {
|
|
1090
|
+
await expect(iconName()).toBe('menu');
|
|
1091
|
+
await expect(menu).toHaveAttribute('aria-expanded', 'false');
|
|
1092
|
+
},
|
|
1093
|
+
);
|
|
1094
|
+
|
|
1095
|
+
await step(
|
|
1096
|
+
'interaction: activating the button swaps in the close icon',
|
|
1097
|
+
async () => {
|
|
1098
|
+
await userEvent.click(menu);
|
|
1099
|
+
await expect(iconName()).toBe('x');
|
|
1100
|
+
},
|
|
1101
|
+
);
|
|
1102
|
+
|
|
1103
|
+
await step(
|
|
1104
|
+
'screen-reader: the open menu reports aria-expanded="true" with a stable name (WCAG 4.1.2)',
|
|
1105
|
+
async () => {
|
|
1106
|
+
await expect(menu).toHaveAttribute('aria-expanded', 'true');
|
|
1107
|
+
await expect(menu).toHaveAccessibleName('Menu');
|
|
1108
|
+
},
|
|
1109
|
+
);
|
|
1110
|
+
|
|
1111
|
+
await step(
|
|
1112
|
+
'keyboard: Enter toggles the menu back to the hamburger (WCAG 2.1.1)',
|
|
1113
|
+
async () => {
|
|
1114
|
+
menu.focus();
|
|
1115
|
+
await userEvent.keyboard('{Enter}');
|
|
1116
|
+
await expect(iconName()).toBe('menu');
|
|
1117
|
+
await expect(menu).toHaveAttribute('aria-expanded', 'false');
|
|
1118
|
+
},
|
|
1119
|
+
);
|
|
1120
|
+
},
|
|
1121
|
+
};
|