@aleph-alpha/ui-library 7.0.1 → 7.1.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/dist/system/components/UiSlider/step-marks.d.ts +45 -0
- package/dist/system/components/UiSlider/types.d.ts +28 -0
- package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
- package/dist/system/icons/story-sidebar-icons.json +74 -17
- package/dist/system/lib.js +2026 -1912
- package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +74 -17
- package/package.json +15 -10
- 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 +127 -86
- 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 +885 -153
- package/src/components/UiSlider/UiSlider.vue +109 -1
- package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
- package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
- package/src/components/UiSlider/step-marks.ts +96 -0
- package/src/components/UiSlider/types.ts +32 -0
- 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/components/core/slider/Slider.vue +16 -6
- 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 +86 -84
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
|
@@ -3,6 +3,16 @@ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
|
3
3
|
import { ref } from 'vue';
|
|
4
4
|
import UiChip from './UiChip.vue';
|
|
5
5
|
import { InfoIcon, TagIcon } from '@/icons/lucide';
|
|
6
|
+
import {
|
|
7
|
+
accessibilityRequirementsTemplate,
|
|
8
|
+
designNotesStory,
|
|
9
|
+
guidanceLinks,
|
|
10
|
+
guidanceSectionClass,
|
|
11
|
+
parseGuidance,
|
|
12
|
+
} from '../../../.storybook/guidance';
|
|
13
|
+
import guidanceMarkdown from './UiChip.guidance.md?raw';
|
|
14
|
+
|
|
15
|
+
const guidance = parseGuidance(guidanceMarkdown);
|
|
6
16
|
|
|
7
17
|
/**
|
|
8
18
|
* UiChip is a compact, optionally interactive token for tags, filters, or selected values.
|
|
@@ -47,6 +57,9 @@ const meta: Meta<typeof UiChip> = {
|
|
|
47
57
|
removeLabel: 'Remove chip',
|
|
48
58
|
modelValue: false,
|
|
49
59
|
},
|
|
60
|
+
parameters: {
|
|
61
|
+
docs: { links: guidanceLinks(guidance) },
|
|
62
|
+
},
|
|
50
63
|
};
|
|
51
64
|
|
|
52
65
|
export default meta;
|
|
@@ -108,6 +121,155 @@ export const Static: Story = {
|
|
|
108
121
|
},
|
|
109
122
|
};
|
|
110
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Usage, guidelines, and do's and don'ts from the Figma documentation.
|
|
126
|
+
*/
|
|
127
|
+
export const DesignNotes: Story = {
|
|
128
|
+
...designNotesStory(guidance),
|
|
129
|
+
tags: ['!autodocs'],
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Accessibility guidance for choosing a variant, naming the remove control,
|
|
134
|
+
* exposing selection, and contrast.
|
|
135
|
+
*/
|
|
136
|
+
export const Accessibility: Story = {
|
|
137
|
+
render: () => ({
|
|
138
|
+
components: { UiChip },
|
|
139
|
+
setup() {
|
|
140
|
+
const selected = ref(true);
|
|
141
|
+
const accessibleSelected = ref(true);
|
|
142
|
+
return { selected, accessibleSelected, TagIcon };
|
|
143
|
+
},
|
|
144
|
+
template: `
|
|
145
|
+
<section class="${guidanceSectionClass}">
|
|
146
|
+
<div>
|
|
147
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
148
|
+
Accessibility
|
|
149
|
+
</h2>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
${accessibilityRequirementsTemplate(guidance.accessibility, 'Requirements')}
|
|
153
|
+
|
|
154
|
+
<div class="flex flex-col gap-6">
|
|
155
|
+
<div class="flex flex-col gap-2">
|
|
156
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
157
|
+
Let the variant match the behaviour
|
|
158
|
+
</h3>
|
|
159
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
160
|
+
Each variant renders different semantics on purpose:
|
|
161
|
+
<code>static</code> is a plain <code>span</code> with no role and
|
|
162
|
+
no tab stop, <code>selectable</code> is a toggle button, and
|
|
163
|
+
<code>removable</code> exposes a remove button. Don't wire a
|
|
164
|
+
click handler onto a static chip — it would look interactive
|
|
165
|
+
while being invisible to keyboard and screen-reader users.
|
|
166
|
+
</p>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div class="flex flex-col gap-2">
|
|
170
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
171
|
+
Name the remove control after its chip
|
|
172
|
+
</h3>
|
|
173
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
174
|
+
The remove control is icon-only, so
|
|
175
|
+
<code>removeLabel</code> is the only thing announced. The default
|
|
176
|
+
<code>Remove chip</code> is fine for a single chip, but in a list
|
|
177
|
+
every control would read identically — pass
|
|
178
|
+
<code>removeLabel="Remove Data Analysis"</code> so it is clear
|
|
179
|
+
which chip is about to go.
|
|
180
|
+
</p>
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
<div class="flex flex-col gap-2">
|
|
184
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
185
|
+
Selection is announced, not just coloured
|
|
186
|
+
</h3>
|
|
187
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
188
|
+
A selected chip changes its background, and
|
|
189
|
+
<code>aria-pressed</code> carries the same state for anyone who
|
|
190
|
+
cannot see it (WCAG 1.4.1). This only applies to interactive
|
|
191
|
+
chips; set <code>selectable</code> on a removable chip when it
|
|
192
|
+
should toggle as well as dismiss.
|
|
193
|
+
</p>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
<div class="flex flex-col gap-2">
|
|
197
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
198
|
+
Keep chips reachable
|
|
199
|
+
</h3>
|
|
200
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
201
|
+
Interactive chips are ordinary buttons: <code>Tab</code> reaches
|
|
202
|
+
them and <code>Enter</code> or <code>Space</code> activates them.
|
|
203
|
+
A removable chip that also selects contributes two tab stops —
|
|
204
|
+
the label, then the remove control.
|
|
205
|
+
</p>
|
|
206
|
+
</div>
|
|
207
|
+
|
|
208
|
+
<div class="flex flex-col gap-2">
|
|
209
|
+
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
210
|
+
Enable accessibility theme
|
|
211
|
+
</h3>
|
|
212
|
+
<p class="body-m-regular text-content-on-surface-primary">
|
|
213
|
+
When accessibility is required, enable our accessibility theme.
|
|
214
|
+
This increases contrast and makes sure there are no color
|
|
215
|
+
contrast issues.
|
|
216
|
+
</p>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
221
|
+
<div class="flex flex-col gap-3">
|
|
222
|
+
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
223
|
+
Default
|
|
224
|
+
</h3>
|
|
225
|
+
<div class="flex flex-wrap items-center gap-3 border border-border-surface-default p-6">
|
|
226
|
+
<UiChip variant="static">Static</UiChip>
|
|
227
|
+
<UiChip v-model="selected" variant="selectable">Selectable</UiChip>
|
|
228
|
+
<UiChip
|
|
229
|
+
variant="removable"
|
|
230
|
+
:start-icon="TagIcon"
|
|
231
|
+
remove-label="Remove Data Analysis"
|
|
232
|
+
>
|
|
233
|
+
Data Analysis
|
|
234
|
+
</UiChip>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
239
|
+
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
240
|
+
Accessible
|
|
241
|
+
</h3>
|
|
242
|
+
<div class="flex flex-wrap items-center gap-3 border border-border-surface-default p-6">
|
|
243
|
+
<UiChip variant="static">Static</UiChip>
|
|
244
|
+
<UiChip v-model="accessibleSelected" variant="selectable">Selectable</UiChip>
|
|
245
|
+
<UiChip
|
|
246
|
+
variant="removable"
|
|
247
|
+
:start-icon="TagIcon"
|
|
248
|
+
remove-label="Remove Data Analysis"
|
|
249
|
+
>
|
|
250
|
+
Data Analysis
|
|
251
|
+
</UiChip>
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
</div>
|
|
255
|
+
</section>
|
|
256
|
+
`,
|
|
257
|
+
}),
|
|
258
|
+
tags: ['!autodocs'],
|
|
259
|
+
parameters: {
|
|
260
|
+
surface: 'primary',
|
|
261
|
+
a11y: { test: 'off' },
|
|
262
|
+
chromatic: {
|
|
263
|
+
disableSnapshot: true,
|
|
264
|
+
},
|
|
265
|
+
docs: {
|
|
266
|
+
canvas: {
|
|
267
|
+
sourceState: 'none',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
|
|
111
273
|
/**
|
|
112
274
|
* Selectable chips support hover, focus, selected and disabled states.
|
|
113
275
|
*/
|
|
@@ -408,144 +570,6 @@ export const FocusOrderInteractive: Story = {
|
|
|
408
570
|
},
|
|
409
571
|
};
|
|
410
572
|
|
|
411
|
-
/**
|
|
412
|
-
* Accessibility guidance for choosing a variant, naming the remove control,
|
|
413
|
-
* exposing selection, and contrast.
|
|
414
|
-
*/
|
|
415
|
-
export const Accessibility: Story = {
|
|
416
|
-
render: () => ({
|
|
417
|
-
components: { UiChip },
|
|
418
|
-
setup() {
|
|
419
|
-
const selected = ref(true);
|
|
420
|
-
const accessibleSelected = ref(true);
|
|
421
|
-
return { selected, accessibleSelected, TagIcon };
|
|
422
|
-
},
|
|
423
|
-
template: `
|
|
424
|
-
<section class="flex flex-col gap-6 p-4">
|
|
425
|
-
<div>
|
|
426
|
-
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
427
|
-
Accessibility
|
|
428
|
-
</h2>
|
|
429
|
-
</div>
|
|
430
|
-
|
|
431
|
-
<div class="flex flex-col gap-6">
|
|
432
|
-
<div class="flex flex-col gap-2">
|
|
433
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
434
|
-
Let the variant match the behaviour
|
|
435
|
-
</h3>
|
|
436
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
437
|
-
Each variant renders different semantics on purpose:
|
|
438
|
-
<code>static</code> is a plain <code>span</code> with no role and
|
|
439
|
-
no tab stop, <code>selectable</code> is a toggle button, and
|
|
440
|
-
<code>removable</code> exposes a remove button. Don't wire a
|
|
441
|
-
click handler onto a static chip — it would look interactive
|
|
442
|
-
while being invisible to keyboard and screen-reader users.
|
|
443
|
-
</p>
|
|
444
|
-
</div>
|
|
445
|
-
|
|
446
|
-
<div class="flex flex-col gap-2">
|
|
447
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
448
|
-
Name the remove control after its chip
|
|
449
|
-
</h3>
|
|
450
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
451
|
-
The remove control is icon-only, so
|
|
452
|
-
<code>removeLabel</code> is the only thing announced. The default
|
|
453
|
-
<code>Remove chip</code> is fine for a single chip, but in a list
|
|
454
|
-
every control would read identically — pass
|
|
455
|
-
<code>removeLabel="Remove Data Analysis"</code> so it is clear
|
|
456
|
-
which chip is about to go.
|
|
457
|
-
</p>
|
|
458
|
-
</div>
|
|
459
|
-
|
|
460
|
-
<div class="flex flex-col gap-2">
|
|
461
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
462
|
-
Selection is announced, not just coloured
|
|
463
|
-
</h3>
|
|
464
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
465
|
-
A selected chip changes its background, and
|
|
466
|
-
<code>aria-pressed</code> carries the same state for anyone who
|
|
467
|
-
cannot see it (WCAG 1.4.1). This only applies to interactive
|
|
468
|
-
chips; set <code>selectable</code> on a removable chip when it
|
|
469
|
-
should toggle as well as dismiss.
|
|
470
|
-
</p>
|
|
471
|
-
</div>
|
|
472
|
-
|
|
473
|
-
<div class="flex flex-col gap-2">
|
|
474
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
475
|
-
Keep chips reachable
|
|
476
|
-
</h3>
|
|
477
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
478
|
-
Interactive chips are ordinary buttons: <code>Tab</code> reaches
|
|
479
|
-
them and <code>Enter</code> or <code>Space</code> activates them.
|
|
480
|
-
A removable chip that also selects contributes two tab stops —
|
|
481
|
-
the label, then the remove control.
|
|
482
|
-
</p>
|
|
483
|
-
</div>
|
|
484
|
-
|
|
485
|
-
<div class="flex flex-col gap-2">
|
|
486
|
-
<h3 class="body-m-medium text-content-on-surface-primary">
|
|
487
|
-
Enable accessibility theme
|
|
488
|
-
</h3>
|
|
489
|
-
<p class="body-m-regular text-content-on-surface-primary">
|
|
490
|
-
When accessibility is required, enable our accessibility theme.
|
|
491
|
-
This increases contrast and makes sure there are no color
|
|
492
|
-
contrast issues.
|
|
493
|
-
</p>
|
|
494
|
-
</div>
|
|
495
|
-
</div>
|
|
496
|
-
|
|
497
|
-
<div class="grid gap-4 md:grid-cols-2">
|
|
498
|
-
<div class="flex flex-col gap-3">
|
|
499
|
-
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
500
|
-
Default
|
|
501
|
-
</h3>
|
|
502
|
-
<div class="flex flex-wrap items-center gap-3 border border-border-surface-default p-6">
|
|
503
|
-
<UiChip variant="static">Static</UiChip>
|
|
504
|
-
<UiChip v-model="selected" variant="selectable">Selectable</UiChip>
|
|
505
|
-
<UiChip
|
|
506
|
-
variant="removable"
|
|
507
|
-
:start-icon="TagIcon"
|
|
508
|
-
remove-label="Remove Data Analysis"
|
|
509
|
-
>
|
|
510
|
-
Data Analysis
|
|
511
|
-
</UiChip>
|
|
512
|
-
</div>
|
|
513
|
-
</div>
|
|
514
|
-
|
|
515
|
-
<div class="accessible-theme flex flex-col gap-3">
|
|
516
|
-
<h3 class="label-m-medium text-center text-content-on-surface-primary">
|
|
517
|
-
Accessible
|
|
518
|
-
</h3>
|
|
519
|
-
<div class="flex flex-wrap items-center gap-3 border border-border-surface-default p-6">
|
|
520
|
-
<UiChip variant="static">Static</UiChip>
|
|
521
|
-
<UiChip v-model="accessibleSelected" variant="selectable">Selectable</UiChip>
|
|
522
|
-
<UiChip
|
|
523
|
-
variant="removable"
|
|
524
|
-
:start-icon="TagIcon"
|
|
525
|
-
remove-label="Remove Data Analysis"
|
|
526
|
-
>
|
|
527
|
-
Data Analysis
|
|
528
|
-
</UiChip>
|
|
529
|
-
</div>
|
|
530
|
-
</div>
|
|
531
|
-
</div>
|
|
532
|
-
</section>
|
|
533
|
-
`,
|
|
534
|
-
}),
|
|
535
|
-
tags: ['!autodocs'],
|
|
536
|
-
parameters: {
|
|
537
|
-
a11y: { test: 'off' },
|
|
538
|
-
chromatic: {
|
|
539
|
-
disableSnapshot: true,
|
|
540
|
-
},
|
|
541
|
-
docs: {
|
|
542
|
-
canvas: {
|
|
543
|
-
sourceState: 'none',
|
|
544
|
-
},
|
|
545
|
-
},
|
|
546
|
-
},
|
|
547
|
-
};
|
|
548
|
-
|
|
549
573
|
/*
|
|
550
574
|
* ─────────────────────────────────────────────────────────────────────────────
|
|
551
575
|
* Interaction & accessibility tests (play functions)
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { ref, onMounted, onUnmounted } from 'vue';
|
|
2
2
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
3
|
+
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
|
|
3
4
|
import UiCodeBlock from './UiCodeBlock.vue';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Swaps in a resolving `navigator.clipboard.writeText` for the duration of a
|
|
8
|
+
* play function; the real one needs a permission the test browsers don't grant.
|
|
9
|
+
* @param run - Play body; receives the `writeText` spy to assert against.
|
|
10
|
+
*/
|
|
11
|
+
async function withStubbedClipboard(
|
|
12
|
+
run: (writeText: ReturnType<typeof fn>) => Promise<void>,
|
|
13
|
+
) {
|
|
14
|
+
const writeText = fn(() => Promise.resolve());
|
|
15
|
+
Object.defineProperty(navigator, 'clipboard', {
|
|
16
|
+
configurable: true,
|
|
17
|
+
value: { writeText },
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
await run(writeText);
|
|
21
|
+
} finally {
|
|
22
|
+
delete (navigator as { clipboard?: unknown }).clipboard;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
5
26
|
/**
|
|
6
27
|
* UiCodeBlock is a pre-formatted block for rendering code snippets with syntax highlighting and copy-to-clipboard support.
|
|
7
28
|
* Use it in documentation, AI assistant responses, and knowledge-base content where readable, monospaced code matters.
|
|
@@ -110,6 +131,32 @@ export const Default: Story = {
|
|
|
110
131
|
},
|
|
111
132
|
},
|
|
112
133
|
},
|
|
134
|
+
play: async ({ canvasElement, step }) => {
|
|
135
|
+
// Scenario (UiCodeBlock): the snippet renders and the copy button copies
|
|
136
|
+
// the raw code, then confirms it.
|
|
137
|
+
const canvas = within(canvasElement);
|
|
138
|
+
|
|
139
|
+
await step('interaction: the snippet renders its code', async () => {
|
|
140
|
+
await waitFor(async () => {
|
|
141
|
+
await expect(canvasElement).toHaveTextContent('interface User');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await step(
|
|
146
|
+
'interaction: Copy code copies the snippet and confirms it',
|
|
147
|
+
async () => {
|
|
148
|
+
await withStubbedClipboard(async (writeText) => {
|
|
149
|
+
await userEvent.click(
|
|
150
|
+
canvas.getByRole('button', { name: 'Copy code' }),
|
|
151
|
+
);
|
|
152
|
+
await expect(writeText).toHaveBeenCalledWith(typescriptExample);
|
|
153
|
+
await expect(
|
|
154
|
+
await canvas.findByRole('button', { name: 'Copied' }),
|
|
155
|
+
).toBeVisible();
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
);
|
|
159
|
+
},
|
|
113
160
|
};
|
|
114
161
|
|
|
115
162
|
const pythonExample = `import pandas as pd
|
|
@@ -503,3 +550,247 @@ export const Streaming: Story = {
|
|
|
503
550
|
},
|
|
504
551
|
},
|
|
505
552
|
};
|
|
553
|
+
|
|
554
|
+
const renderTestCodeBlock = () => ({
|
|
555
|
+
components: { UiCodeBlock },
|
|
556
|
+
setup() {
|
|
557
|
+
return { code: longCode };
|
|
558
|
+
},
|
|
559
|
+
template: `<UiCodeBlock :code="code" language="javascript" filename="process.js" max-height="200px" />`,
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
const waitForCode = async (canvasElement: HTMLElement) => {
|
|
563
|
+
await waitFor(async () => {
|
|
564
|
+
await expect(canvasElement).toHaveTextContent('Line 30');
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* The copy button and the scrollable code area are both Tab stops, so keyboard
|
|
570
|
+
* users can copy the snippet and scroll it (WCAG 2.1.1). Hidden test-only story.
|
|
571
|
+
*/
|
|
572
|
+
export const KeyboardNavigation: Story = {
|
|
573
|
+
name: 'test - Keyboard Navigation',
|
|
574
|
+
tags: ['!dev', '!autodocs'],
|
|
575
|
+
parameters: {
|
|
576
|
+
// Focus moves during the play function.
|
|
577
|
+
chromatic: { disableSnapshot: true },
|
|
578
|
+
docs: {
|
|
579
|
+
description: {
|
|
580
|
+
story:
|
|
581
|
+
'Press `Tab` to reach the copy button and `Enter` to copy, then `Tab` into the code area and use the arrow keys to scroll it.',
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
render: renderTestCodeBlock,
|
|
586
|
+
play: async ({ canvasElement, step }) => {
|
|
587
|
+
// Scenario (UiCodeBlock): a keyboard user copies the snippet, then moves
|
|
588
|
+
// into the capped code area to scroll it.
|
|
589
|
+
const canvas = within(canvasElement);
|
|
590
|
+
const copyButton = canvas.getByRole('button', { name: 'Copy code' });
|
|
591
|
+
const region = canvas.getByRole('region', {
|
|
592
|
+
name: 'Scrollable code block',
|
|
593
|
+
});
|
|
594
|
+
await waitForCode(canvasElement);
|
|
595
|
+
|
|
596
|
+
await step('keyboard: Tab reaches the copy button first', async () => {
|
|
597
|
+
await userEvent.tab();
|
|
598
|
+
await expect(copyButton).toHaveFocus();
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
await step('keyboard: Enter copies the snippet', async () => {
|
|
602
|
+
await withStubbedClipboard(async (writeText) => {
|
|
603
|
+
await userEvent.keyboard('{Enter}');
|
|
604
|
+
await expect(writeText).toHaveBeenCalledWith(longCode);
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
await step(
|
|
609
|
+
'keyboard: the scrollable code area is the next Tab stop (WCAG 2.1.1)',
|
|
610
|
+
async () => {
|
|
611
|
+
await userEvent.tab();
|
|
612
|
+
await expect(region).toHaveFocus();
|
|
613
|
+
},
|
|
614
|
+
);
|
|
615
|
+
},
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* What assistive technology reads: a named copy button whose name confirms the
|
|
620
|
+
* copy, and a named region for the scrollable code (WCAG 4.1.2, 4.1.3).
|
|
621
|
+
* Hidden test-only story.
|
|
622
|
+
*/
|
|
623
|
+
export const ScreenReader: Story = {
|
|
624
|
+
name: 'test - Screen Reader',
|
|
625
|
+
tags: ['!dev', '!autodocs'],
|
|
626
|
+
parameters: {
|
|
627
|
+
chromatic: { disableSnapshot: true },
|
|
628
|
+
docs: {
|
|
629
|
+
description: {
|
|
630
|
+
story:
|
|
631
|
+
'Verifies the copy button name, its confirmation, and the scrollable region name that assistive technology announces.',
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
render: renderTestCodeBlock,
|
|
636
|
+
play: async ({ canvasElement, step }) => {
|
|
637
|
+
// Scenario (UiCodeBlock): a screen-reader user hears what the button does,
|
|
638
|
+
// hears that the copy worked, and can find the scrollable code by name.
|
|
639
|
+
const canvas = within(canvasElement);
|
|
640
|
+
await waitForCode(canvasElement);
|
|
641
|
+
|
|
642
|
+
await step(
|
|
643
|
+
'screen-reader: the filename labels the snippet in the header',
|
|
644
|
+
async () => {
|
|
645
|
+
await expect(canvas.getByText('process.js')).toBeVisible();
|
|
646
|
+
},
|
|
647
|
+
);
|
|
648
|
+
|
|
649
|
+
await step(
|
|
650
|
+
'screen-reader: the icon-only copy button has a name (WCAG 4.1.2)',
|
|
651
|
+
async () => {
|
|
652
|
+
await expect(
|
|
653
|
+
canvas.getByRole('button', { name: 'Copy code' }),
|
|
654
|
+
).toBeInTheDocument();
|
|
655
|
+
},
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
await step(
|
|
659
|
+
'screen-reader: the button name changes to Copied after copying',
|
|
660
|
+
async () => {
|
|
661
|
+
await withStubbedClipboard(async () => {
|
|
662
|
+
await userEvent.click(
|
|
663
|
+
canvas.getByRole('button', { name: 'Copy code' }),
|
|
664
|
+
);
|
|
665
|
+
await expect(
|
|
666
|
+
await canvas.findByRole('button', { name: 'Copied' }),
|
|
667
|
+
).toBeInTheDocument();
|
|
668
|
+
});
|
|
669
|
+
},
|
|
670
|
+
);
|
|
671
|
+
|
|
672
|
+
await step(
|
|
673
|
+
'screen-reader: the capped code area is a named region',
|
|
674
|
+
async () => {
|
|
675
|
+
await expect(
|
|
676
|
+
canvas.getByRole('region', { name: 'Scrollable code block' }),
|
|
677
|
+
).toHaveTextContent('Line 1');
|
|
678
|
+
},
|
|
679
|
+
);
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
685
|
+
* try 400% reflow (WCAG 1.4.10). Hidden test-only story.
|
|
686
|
+
*/
|
|
687
|
+
export const ZoomMagnification: Story = {
|
|
688
|
+
name: 'test - Zoom Magnification',
|
|
689
|
+
tags: ['!dev', '!autodocs'],
|
|
690
|
+
globals: { zoom: '200' },
|
|
691
|
+
parameters: {
|
|
692
|
+
// Zoom changes the layout scale; the accessible-reflow Chromatic mode
|
|
693
|
+
// already covers magnified snapshots, so skip this one.
|
|
694
|
+
chromatic: { disableSnapshot: true },
|
|
695
|
+
docs: {
|
|
696
|
+
description: {
|
|
697
|
+
story:
|
|
698
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
},
|
|
702
|
+
render: renderTestCodeBlock,
|
|
703
|
+
play: async ({ canvasElement, step }) => {
|
|
704
|
+
// Scenario (UiCodeBlock): at 200% page zoom the code stays readable, long
|
|
705
|
+
// lines scroll inside the block, and copying still works.
|
|
706
|
+
const canvas = within(canvasElement);
|
|
707
|
+
await waitForCode(canvasElement);
|
|
708
|
+
|
|
709
|
+
await step(
|
|
710
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
711
|
+
async () => {
|
|
712
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
713
|
+
},
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
await step('zoom: the header and code stay readable', async () => {
|
|
717
|
+
await expect(canvas.getByText('process.js')).toBeVisible();
|
|
718
|
+
await expect(
|
|
719
|
+
canvas.getByRole('region', { name: 'Scrollable code block' }),
|
|
720
|
+
).toBeVisible();
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
await step(
|
|
724
|
+
'zoom: long lines scroll inside the block, not the page',
|
|
725
|
+
async () => {
|
|
726
|
+
const { scrollWidth, clientWidth } = document.documentElement;
|
|
727
|
+
await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
|
|
728
|
+
},
|
|
729
|
+
);
|
|
730
|
+
|
|
731
|
+
await step('zoom: the copy button still works', async () => {
|
|
732
|
+
await withStubbedClipboard(async (writeText) => {
|
|
733
|
+
await userEvent.click(
|
|
734
|
+
canvas.getByRole('button', { name: 'Copy code' }),
|
|
735
|
+
);
|
|
736
|
+
await expect(writeText).toHaveBeenCalledWith(longCode);
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
},
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
744
|
+
* toolbar. Code is exempt from single-column reflow (WCAG 1.4.10), so it
|
|
745
|
+
* scrolls inside the block. Hidden test-only story.
|
|
746
|
+
*/
|
|
747
|
+
export const MobileBreakpoint: Story = {
|
|
748
|
+
name: 'test - Mobile Breakpoint',
|
|
749
|
+
tags: ['!dev', '!autodocs'],
|
|
750
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
751
|
+
parameters: {
|
|
752
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
753
|
+
chromatic: { disableSnapshot: true },
|
|
754
|
+
docs: {
|
|
755
|
+
description: {
|
|
756
|
+
story:
|
|
757
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
758
|
+
},
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
render: renderTestCodeBlock,
|
|
762
|
+
play: async ({ canvasElement, step }) => {
|
|
763
|
+
// Scenario (UiCodeBlock): at the 320px breakpoint the block fits the
|
|
764
|
+
// viewport, the code scrolls inside it, and the copy button can be tapped.
|
|
765
|
+
const canvas = within(canvasElement);
|
|
766
|
+
const copyButton = canvas.getByRole('button', { name: 'Copy code' });
|
|
767
|
+
await waitForCode(canvasElement);
|
|
768
|
+
|
|
769
|
+
await step(
|
|
770
|
+
'mobile: the block fits the 320px viewport (WCAG 1.4.10 Reflow)',
|
|
771
|
+
async () => {
|
|
772
|
+
const block = canvasElement.querySelector('.ui-code-block');
|
|
773
|
+
if (!block) throw new Error('UiCodeBlock did not render');
|
|
774
|
+
const { left, right } = block.getBoundingClientRect();
|
|
775
|
+
await expect(left).toBeGreaterThanOrEqual(0);
|
|
776
|
+
await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
|
|
777
|
+
},
|
|
778
|
+
);
|
|
779
|
+
|
|
780
|
+
await step(
|
|
781
|
+
'mobile: the copy button meets the minimum target size (WCAG 2.5.8)',
|
|
782
|
+
async () => {
|
|
783
|
+
const { width, height } = copyButton.getBoundingClientRect();
|
|
784
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
785
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
786
|
+
},
|
|
787
|
+
);
|
|
788
|
+
|
|
789
|
+
await step('mobile: copying works by tap', async () => {
|
|
790
|
+
await withStubbedClipboard(async (writeText) => {
|
|
791
|
+
await userEvent.click(copyButton);
|
|
792
|
+
await expect(writeText).toHaveBeenCalledWith(longCode);
|
|
793
|
+
});
|
|
794
|
+
});
|
|
795
|
+
},
|
|
796
|
+
};
|
|
@@ -185,13 +185,14 @@ onUnmounted(() => {
|
|
|
185
185
|
:aria-label="isCopied ? copiedLabel : copyLabel"
|
|
186
186
|
@click="handleCopy"
|
|
187
187
|
>
|
|
188
|
-
<UiIcon :name="isCopied ? CheckIcon : CopyIcon" :size="
|
|
188
|
+
<UiIcon :name="isCopied ? CheckIcon : CopyIcon" :size="16" />
|
|
189
189
|
</UiButton>
|
|
190
190
|
</div>
|
|
191
191
|
|
|
192
192
|
<div
|
|
193
193
|
class="overflow-auto"
|
|
194
194
|
:style="maxHeight ? { maxHeight } : undefined"
|
|
195
|
+
:role="maxHeight ? 'region' : undefined"
|
|
195
196
|
:tabindex="maxHeight ? 0 : undefined"
|
|
196
197
|
:aria-label="maxHeight ? 'Scrollable code block' : undefined"
|
|
197
198
|
>
|
|
@@ -196,6 +196,24 @@ describe('UiCodeBlock', () => {
|
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
|
|
199
|
+
test('exposes the capped code area as a focusable named region', () => {
|
|
200
|
+
const { getByRole } = render(UiCodeBlock, {
|
|
201
|
+
props: { code: 'code', language: 'typescript', maxHeight: '200px' },
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const region = getByRole('region', { name: 'Scrollable code block' });
|
|
205
|
+
expect(region).toHaveAttribute('tabindex', '0');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('has no region or tab stop without maxHeight', () => {
|
|
209
|
+
const { queryByRole, container } = render(UiCodeBlock, {
|
|
210
|
+
props: { code: 'code', language: 'typescript' },
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
expect(queryByRole('region')).not.toBeInTheDocument();
|
|
214
|
+
expect(container.querySelector('[tabindex="0"]')).toBeNull();
|
|
215
|
+
});
|
|
216
|
+
|
|
199
217
|
test('uses custom copy labels when provided', async () => {
|
|
200
218
|
const user = userEvent.setup();
|
|
201
219
|
|