@aleph-alpha/ui-library 7.0.1 → 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.
Files changed (115) hide show
  1. package/dist/system/icons/story-sidebar-icons.json +74 -17
  2. package/dist/system/lib.js +8 -5
  3. package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
  4. package/dist/system/story-sidebar-icons.json +74 -17
  5. package/package.json +8 -3
  6. package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
  7. package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
  8. package/src/components/UiAlert/UiAlert.guidance.md +66 -0
  9. package/src/components/UiAlert/UiAlert.stories.ts +167 -143
  10. package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
  11. package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
  12. package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
  13. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
  14. package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
  15. package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
  16. package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
  17. package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
  18. package/src/components/UiBadge/UiBadge.guidance.md +65 -0
  19. package/src/components/UiBadge/UiBadge.stories.ts +325 -0
  20. package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
  21. package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
  22. package/src/components/UiButton/UiButton.stories.ts +5 -2
  23. package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
  24. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
  25. package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
  26. package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
  27. package/src/components/UiCard/UiCard.guidance.md +65 -0
  28. package/src/components/UiCard/UiCard.stories.ts +393 -0
  29. package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
  30. package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
  31. package/src/components/UiChip/UiChip.guidance.md +64 -0
  32. package/src/components/UiChip/UiChip.stories.ts +162 -138
  33. package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
  34. package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
  35. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
  36. package/src/components/UiDialog/UiDialog.guidance.md +66 -0
  37. package/src/components/UiDialog/UiDialog.stories.ts +90 -66
  38. package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
  39. package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
  40. package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
  41. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +127 -86
  42. package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
  43. package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
  44. package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
  45. package/src/components/UiField/UiField.guidance.md +63 -0
  46. package/src/components/UiField/UiField.stories.ts +90 -113
  47. package/src/components/UiFileType/UiFileType.stories.ts +254 -0
  48. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
  49. package/src/components/UiIcon/UiIcon.stories.ts +256 -1
  50. package/src/components/UiInput/UiInput.guidance.md +64 -0
  51. package/src/components/UiInput/UiInput.stories.ts +132 -80
  52. package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
  53. package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
  54. package/src/components/UiItem/UiItem.guidance.md +66 -0
  55. package/src/components/UiItem/UiItem.stories.ts +81 -28
  56. package/src/components/UiKbd/UiKbd.guidance.md +65 -0
  57. package/src/components/UiKbd/UiKbd.stories.ts +373 -3
  58. package/src/components/UiLabel/UiLabel.guidance.md +65 -0
  59. package/src/components/UiLabel/UiLabel.stories.ts +163 -139
  60. package/src/components/UiListbox/UiListbox.stories.ts +197 -195
  61. package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
  62. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
  63. package/src/components/UiPopover/UiPopover.guidance.md +65 -0
  64. package/src/components/UiPopover/UiPopover.stories.ts +115 -91
  65. package/src/components/UiProgress/UiProgress.guidance.md +65 -0
  66. package/src/components/UiProgress/UiProgress.stories.ts +300 -0
  67. package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
  68. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
  69. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
  70. package/src/components/UiResizable/UiResizable.guidance.md +65 -0
  71. package/src/components/UiResizable/UiResizable.stories.ts +176 -152
  72. package/src/components/UiSelect/UiSelect.guidance.md +66 -0
  73. package/src/components/UiSelect/UiSelect.stories.ts +150 -126
  74. package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
  75. package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
  76. package/src/components/UiSheet/UiSheet.guidance.md +66 -0
  77. package/src/components/UiSheet/UiSheet.stories.ts +194 -170
  78. package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
  79. package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
  80. package/src/components/UiSlider/UiSlider.guidance.md +66 -0
  81. package/src/components/UiSlider/UiSlider.stories.ts +150 -126
  82. package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
  83. package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
  84. package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
  85. package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
  86. package/src/components/UiStepper/UiStepper.guidance.md +66 -0
  87. package/src/components/UiStepper/UiStepper.stories.ts +142 -124
  88. package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
  89. package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
  90. package/src/components/UiTable/UiTable.guidance.md +66 -0
  91. package/src/components/UiTable/UiTable.stories.ts +530 -12
  92. package/src/components/UiTabs/UiTabs.guidance.md +66 -0
  93. package/src/components/UiTabs/UiTabs.stories.ts +174 -150
  94. package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
  95. package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
  96. package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
  97. package/src/components/UiToggle/UiToggle.guidance.md +66 -0
  98. package/src/components/UiToggle/UiToggle.stories.ts +183 -159
  99. package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
  100. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
  101. package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
  102. package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
  103. package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
  104. package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
  105. package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
  106. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
  107. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
  108. package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
  109. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
  110. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
  111. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
  112. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
  113. package/src/patterns/UiPlaceholder/types.ts +1 -0
  114. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +74 -72
  115. package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, fn, userEvent, within } from 'storybook/test';
2
3
  import { UiButton } from '../UiButton';
3
4
  import { UiInput } from '../UiInput';
4
5
  import {
@@ -10,6 +11,15 @@ import {
10
11
  UiCardHeader,
11
12
  UiCardTitle,
12
13
  } from './index';
14
+ import {
15
+ accessibilityStory,
16
+ designNotesStory,
17
+ guidanceLinks,
18
+ parseGuidance,
19
+ } from '../../../.storybook/guidance';
20
+ import guidanceMarkdown from './UiCard.guidance.md?raw';
21
+
22
+ const guidance = parseGuidance(guidanceMarkdown);
13
23
 
14
24
  /**
15
25
  * UiCard is a surface container that groups related content using `UiCardHeader`, `UiCardContent`, `UiCardFooter`, and an optional `UiCardAction`.
@@ -21,12 +31,19 @@ const meta: Meta<typeof UiCard> = {
21
31
  tags: ['autodocs'],
22
32
  argTypes: {},
23
33
  args: {},
34
+ parameters: {
35
+ docs: { links: guidanceLinks(guidance) },
36
+ },
24
37
  };
25
38
 
26
39
  export default meta;
27
40
 
28
41
  type Story = StoryObj<typeof UiCard>;
29
42
 
43
+ const onEdit = fn();
44
+ const onCancel = fn();
45
+ const onSave = fn();
46
+
30
47
  const defaultTemplateSource = `<script setup lang="ts">
31
48
  import {
32
49
  UiCard,
@@ -137,6 +154,78 @@ export const Default: Story = {
137
154
  },
138
155
  },
139
156
  },
157
+ play: async ({ canvasElement, step }) => {
158
+ // Scenario (UiCard): the login card composes a header action, labelled
159
+ // fields, and footer buttons; the card itself only groups them.
160
+ const canvas = within(canvasElement);
161
+
162
+ await step(
163
+ 'interaction: the header action is a named, enabled button',
164
+ async () => {
165
+ const signUp = canvas.getByRole('button', { name: 'Sign Up' });
166
+ await expect(signUp).toBeEnabled();
167
+ await expect(
168
+ canvas.getByRole('heading', { name: 'Login to your account' }),
169
+ ).toBeVisible();
170
+ },
171
+ );
172
+
173
+ await step('interaction: the form fields are labelled', async () => {
174
+ await expect(canvas.getByLabelText('Email')).toBeVisible();
175
+ await expect(canvas.getByLabelText('Password')).toBeVisible();
176
+ });
177
+
178
+ await step(
179
+ 'interaction: the footer exposes both login actions',
180
+ async () => {
181
+ await expect(
182
+ canvas.getByRole('button', { name: 'Login' }),
183
+ ).toBeEnabled();
184
+ await expect(
185
+ canvas.getByRole('button', { name: 'Login with Google' }),
186
+ ).toBeEnabled();
187
+ },
188
+ );
189
+ },
190
+ };
191
+
192
+ /**
193
+ * Usage, guidelines, and do's and don'ts from the Figma documentation.
194
+ */
195
+ export const DesignNotes: Story = {
196
+ ...designNotesStory(guidance),
197
+ tags: ['!autodocs'],
198
+ };
199
+
200
+ /**
201
+ * Accessibility guidance from the Figma documentation, with the component in
202
+ * the default and accessible themes.
203
+ */
204
+ export const Accessibility: Story = {
205
+ ...accessibilityStory({
206
+ requirements: guidance.accessibility,
207
+ example: {
208
+ components: {
209
+ UiCard,
210
+ UiCardContent,
211
+ UiCardDescription,
212
+ UiCardHeader,
213
+ UiCardTitle,
214
+ },
215
+ template: `
216
+ <UiCard class="w-full max-w-64">
217
+ <UiCardHeader>
218
+ <UiCardTitle>Project Alpha</UiCardTitle>
219
+ <UiCardDescription>Updated 2 hours ago</UiCardDescription>
220
+ </UiCardHeader>
221
+ <UiCardContent>
222
+ <p class="body-s-regular">Three tasks are due this week.</p>
223
+ </UiCardContent>
224
+ </UiCard>
225
+ `,
226
+ },
227
+ }),
228
+ tags: ['!autodocs'],
140
229
  };
141
230
 
142
231
  const simpleTemplateSource = `<script setup lang="ts">
@@ -198,4 +287,308 @@ export const Simple: Story = {
198
287
  },
199
288
  },
200
289
  },
290
+ play: async ({ canvasElement, step }) => {
291
+ // Scenario (UiCard): a card with no actions is a plain container, so
292
+ // keyboard users never stop on it.
293
+ const card = canvasElement.querySelector<HTMLElement>('[data-slot="card"]');
294
+ if (!card) throw new Error('UiCard did not render');
295
+
296
+ await step('interaction: a static card is not focusable', async () => {
297
+ await expect(card).not.toHaveAttribute('tabindex');
298
+ card.focus();
299
+ await expect(card).not.toHaveFocus();
300
+ });
301
+ },
302
+ };
303
+
304
+ const renderTestCard = () => ({
305
+ components: {
306
+ UiButton,
307
+ UiCard,
308
+ UiCardAction,
309
+ UiCardContent,
310
+ UiCardDescription,
311
+ UiCardFooter,
312
+ UiCardHeader,
313
+ UiCardTitle,
314
+ },
315
+ setup() {
316
+ return { onCancel, onEdit, onSave };
317
+ },
318
+ template: `
319
+ <UiCard class="w-full max-w-sm">
320
+ <UiCardHeader>
321
+ <UiCardTitle>Project Alpha</UiCardTitle>
322
+ <UiCardDescription>Updated 2 hours ago</UiCardDescription>
323
+ <UiCardAction>
324
+ <UiButton variant="outline" size="sm" @click="onEdit">Edit</UiButton>
325
+ </UiCardAction>
326
+ </UiCardHeader>
327
+ <UiCardContent>
328
+ <p class="body-s-regular">Three tasks are due this week.</p>
329
+ </UiCardContent>
330
+ <UiCardFooter class="flex gap-2">
331
+ <UiButton variant="outline" @click="onCancel">Cancel</UiButton>
332
+ <UiButton @click="onSave">Save</UiButton>
333
+ </UiCardFooter>
334
+ </UiCard>
335
+ `,
336
+ });
337
+
338
+ const clearCardSpies = () => {
339
+ onEdit.mockClear();
340
+ onCancel.mockClear();
341
+ onSave.mockClear();
342
+ };
343
+
344
+ /**
345
+ * Focus follows the reading order of the card: the header action first, then
346
+ * the footer actions, and never the card container itself (WCAG 2.4.3).
347
+ * Hidden test-only story.
348
+ */
349
+ export const KeyboardNavigation: Story = {
350
+ name: 'test - Keyboard Navigation',
351
+ tags: ['!dev', '!autodocs'],
352
+ parameters: {
353
+ // Focus moves during the play function.
354
+ chromatic: { disableSnapshot: true },
355
+ docs: {
356
+ description: {
357
+ story:
358
+ 'Press `Tab` to move through the card actions, then `Enter` or `Space` to activate them.',
359
+ },
360
+ },
361
+ },
362
+ render: renderTestCard,
363
+ play: async ({ canvasElement, step }) => {
364
+ // Scenario (UiCard): a keyboard user tabs through the card's actions in
365
+ // reading order and activates them; the container is never a tab stop.
366
+ clearCardSpies();
367
+ const canvas = within(canvasElement);
368
+ const card = canvasElement.querySelector('[data-slot="card"]');
369
+ const edit = canvas.getByRole('button', { name: 'Edit' });
370
+ const cancel = canvas.getByRole('button', { name: 'Cancel' });
371
+ const save = canvas.getByRole('button', { name: 'Save' });
372
+
373
+ await step(
374
+ 'keyboard: Tab reaches the header action first (WCAG 2.4.3 Focus Order)',
375
+ async () => {
376
+ await userEvent.tab();
377
+ await expect(edit).toHaveFocus();
378
+ await expect(card).not.toHaveFocus();
379
+ },
380
+ );
381
+
382
+ await step('keyboard: Enter activates the header action', async () => {
383
+ await userEvent.keyboard('{Enter}');
384
+ await expect(onEdit).toHaveBeenCalledTimes(1);
385
+ });
386
+
387
+ await step(
388
+ 'keyboard: Tab continues to the footer actions in reading order',
389
+ async () => {
390
+ await userEvent.tab();
391
+ await expect(cancel).toHaveFocus();
392
+ await userEvent.tab();
393
+ await expect(save).toHaveFocus();
394
+ },
395
+ );
396
+
397
+ await step('keyboard: Space activates the focused action', async () => {
398
+ await userEvent.keyboard(' ');
399
+ await expect(onSave).toHaveBeenCalledTimes(1);
400
+ await expect(onCancel).not.toHaveBeenCalled();
401
+ });
402
+
403
+ await step(
404
+ 'keyboard: focus leaves the card after its last action',
405
+ async () => {
406
+ await userEvent.tab();
407
+ await expect(card?.contains(document.activeElement)).toBe(false);
408
+ },
409
+ );
410
+ },
411
+ };
412
+
413
+ /**
414
+ * What assistive technology reads for the card: a heading, then its
415
+ * description, content, and named actions in DOM order. Hidden test-only
416
+ * story.
417
+ */
418
+ export const ScreenReader: Story = {
419
+ name: 'test - Screen Reader',
420
+ tags: ['!dev', '!autodocs'],
421
+ parameters: {
422
+ docs: {
423
+ description: {
424
+ story:
425
+ 'Verifies the heading, reading order, and action names that assistive technology announces.',
426
+ },
427
+ },
428
+ },
429
+ render: renderTestCard,
430
+ play: async ({ canvasElement, step }) => {
431
+ // Scenario (UiCard): a screen-reader user can find the card by its heading
432
+ // and hears its parts in the same order they are shown.
433
+ const canvas = within(canvasElement);
434
+
435
+ await step(
436
+ 'screen-reader: the title is a level-3 heading (WCAG 1.3.1)',
437
+ async () => {
438
+ await expect(
439
+ canvas.getByRole('heading', { level: 3, name: 'Project Alpha' }),
440
+ ).toBeVisible();
441
+ },
442
+ );
443
+
444
+ await step(
445
+ 'screen-reader: description and content follow the title in reading order',
446
+ async () => {
447
+ const follows = (before: Node, after: Node) =>
448
+ Boolean(
449
+ before.compareDocumentPosition(after) &
450
+ Node.DOCUMENT_POSITION_FOLLOWING,
451
+ );
452
+ const title = canvas.getByRole('heading', { name: 'Project Alpha' });
453
+ const description = canvas.getByText('Updated 2 hours ago');
454
+ const content = canvas.getByText('Three tasks are due this week.');
455
+ const action = canvas.getByRole('button', { name: 'Save' });
456
+
457
+ await expect(follows(title, description)).toBe(true);
458
+ await expect(follows(description, content)).toBe(true);
459
+ await expect(follows(content, action)).toBe(true);
460
+ },
461
+ );
462
+
463
+ await step(
464
+ 'screen-reader: the card container adds no role or landmark',
465
+ async () => {
466
+ const card = canvasElement.querySelector('[data-slot="card"]');
467
+ await expect(card).not.toHaveAttribute('role');
468
+ await expect(canvas.queryByRole('region')).not.toBeInTheDocument();
469
+ },
470
+ );
471
+
472
+ await step(
473
+ 'screen-reader: every action has an accessible name',
474
+ async () => {
475
+ for (const name of ['Edit', 'Cancel', 'Save']) {
476
+ await expect(
477
+ canvas.getByRole('button', { name }),
478
+ ).toHaveAccessibleName(name);
479
+ }
480
+ },
481
+ );
482
+ },
483
+ };
484
+
485
+ /**
486
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
487
+ * try 400% reflow (WCAG 1.4.10). Hidden test-only story.
488
+ */
489
+ export const ZoomMagnification: Story = {
490
+ name: 'test - Zoom Magnification',
491
+ tags: ['!dev', '!autodocs'],
492
+ globals: { zoom: '200' },
493
+ parameters: {
494
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
495
+ // already covers magnified snapshots, so skip this one.
496
+ chromatic: { disableSnapshot: true },
497
+ docs: {
498
+ description: {
499
+ story:
500
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
501
+ },
502
+ },
503
+ },
504
+ render: renderTestCard,
505
+ play: async ({ canvasElement, step }) => {
506
+ // Scenario (UiCard): at 200% page zoom the card's text stays readable, it
507
+ // stays inside the viewport, and its actions still work.
508
+ clearCardSpies();
509
+ const canvas = within(canvasElement);
510
+
511
+ await step(
512
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
513
+ async () => {
514
+ await expect(document.documentElement.style.zoom).toBe('200%');
515
+ },
516
+ );
517
+
518
+ await step('zoom: title and content stay readable', async () => {
519
+ await expect(
520
+ canvas.getByRole('heading', { name: 'Project Alpha' }),
521
+ ).toBeVisible();
522
+ await expect(
523
+ canvas.getByText('Three tasks are due this week.'),
524
+ ).toBeVisible();
525
+ });
526
+
527
+ await step('zoom: the card stays inside the viewport', async () => {
528
+ const card = canvasElement.querySelector('[data-slot="card"]');
529
+ if (!card) throw new Error('UiCard did not render');
530
+ const { left, right } = card.getBoundingClientRect();
531
+ await expect(left).toBeGreaterThanOrEqual(0);
532
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
533
+ });
534
+
535
+ await step('zoom: actions remain operable when magnified', async () => {
536
+ await userEvent.click(canvas.getByRole('button', { name: 'Save' }));
537
+ await expect(onSave).toHaveBeenCalledTimes(1);
538
+ });
539
+ },
540
+ };
541
+
542
+ /**
543
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
544
+ * toolbar. Hidden test-only story.
545
+ */
546
+ export const MobileBreakpoint: Story = {
547
+ name: 'test - Mobile Breakpoint',
548
+ tags: ['!dev', '!autodocs'],
549
+ globals: { mediaBreakpoint: 'reflow' },
550
+ parameters: {
551
+ // Reflow snapshots are already covered by the accessible-reflow mode.
552
+ chromatic: { disableSnapshot: true },
553
+ docs: {
554
+ description: {
555
+ story:
556
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
557
+ },
558
+ },
559
+ },
560
+ render: renderTestCard,
561
+ play: async ({ canvasElement, step }) => {
562
+ // Scenario (UiCard): at the 320px mobile breakpoint the card fits without
563
+ // sideways scrolling and every action is big enough to tap.
564
+ clearCardSpies();
565
+ const canvas = within(canvasElement);
566
+
567
+ await step('mobile: the card renders at the 320px breakpoint', async () => {
568
+ await expect(
569
+ canvas.getByRole('heading', { name: 'Project Alpha' }),
570
+ ).toBeVisible();
571
+ await userEvent.click(canvas.getByRole('button', { name: 'Edit' }));
572
+ await expect(onEdit).toHaveBeenCalledTimes(1);
573
+ });
574
+
575
+ await step(
576
+ 'mobile: the card fits without sideways scrolling (WCAG 1.4.10 Reflow)',
577
+ async () => {
578
+ const { scrollWidth, clientWidth } = document.documentElement;
579
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
580
+ },
581
+ );
582
+
583
+ await step(
584
+ 'mobile: every action meets the minimum target size (WCAG 2.5.8)',
585
+ async () => {
586
+ for (const control of canvas.getAllByRole('button')) {
587
+ const { width, height } = control.getBoundingClientRect();
588
+ await expect(width).toBeGreaterThanOrEqual(24);
589
+ await expect(height).toBeGreaterThanOrEqual(24);
590
+ }
591
+ },
592
+ );
593
+ },
201
594
  };
@@ -0,0 +1,62 @@
1
+ ---
2
+ figma: '27148:5361'
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 Checkbox component lets a user turn an option on or off, and lets several options be on at once. Each checkbox is independent: choosing one says nothing about the others.
10
+
11
+ Use it wherever choices are independent and more than one may apply. When exactly one option must be chosen use Radio Group, and when the choice takes effect immediately use Switch.
12
+
13
+ ### Independent choices
14
+
15
+ A checkbox answers one question on its own:
16
+
17
+ - Each option can be on or off regardless of the others
18
+ - More than one option in a group may be chosen
19
+ - The indeterminate state describes a partial selection of children
20
+ - A single checkbox is a yes-or-no, not a choice between two things
21
+
22
+ ### The label carries the meaning
23
+
24
+ The user reads the label rather than the box, so write it first:
25
+
26
+ 1. Label states what being checked means
27
+ 2. Description adds a consequence or a limit, where one exists
28
+ 3. Control placement puts the box at the start, or at the end for list rows
29
+ 4. The whole row is the target, label included
30
+
31
+ ### Consistency
32
+
33
+ Every checkbox is built from the same parts:
34
+
35
+ - Checkbox, default or box type
36
+ - Control placement, at the start or the end
37
+ - Label, always present
38
+ - Description, when guidance helps
39
+ - States: default, focus, pressed and disabled
40
+ - Checkbox group, for related options
41
+
42
+ ## Do
43
+
44
+ - Use checkboxes for independent choices
45
+ - Allow multiple selections when appropriate
46
+ - Write descriptive labels
47
+ - Group related options together
48
+ - Provide supporting descriptions when needed
49
+ - Use indeterminate states for partial selection patterns
50
+
51
+ ## Don't
52
+
53
+ - Use checkboxes when only one choice is allowed (use radio instead)
54
+ - Present unrelated options in the same group
55
+ - Use vague labels like “Enable” or “Yes”
56
+ - Depend solely on color to communicate state
57
+
58
+ ## Accessibility
59
+
60
+ - Every checkbox has a visible label
61
+ - Descriptions remain readable and associated with the field
62
+ - Keyboard focus is correct in a checkbox group
@@ -12,6 +12,16 @@ import {
12
12
  UiFieldTitle,
13
13
  } from '../UiField';
14
14
  import { ref } from 'vue';
15
+ import {
16
+ accessibilityRequirementsTemplate,
17
+ designNotesStory,
18
+ guidanceLinks,
19
+ guidanceSectionClass,
20
+ parseGuidance,
21
+ } from '../../../.storybook/guidance';
22
+ import guidanceMarkdown from './UiCheckbox.guidance.md?raw';
23
+
24
+ const guidance = parseGuidance(guidanceMarkdown);
15
25
 
16
26
  /**
17
27
  * A control that allows the user to toggle between checked and not checked.
@@ -35,6 +45,9 @@ const meta: Meta<typeof UiCheckbox> = {
35
45
  disabled: false,
36
46
  required: false,
37
47
  },
48
+ parameters: {
49
+ docs: { links: guidanceLinks(guidance) },
50
+ },
38
51
  };
39
52
 
40
53
  export default meta;
@@ -114,54 +127,11 @@ export const Default: Story = {
114
127
  };
115
128
 
116
129
  /**
117
- * Design guidance for choosing checkbox patterns and writing clear option labels.
130
+ * Usage, guidelines, and do's and don'ts from the Figma documentation.
118
131
  */
119
132
  export const DesignNotes: Story = {
120
- render: () => ({
121
- template: `
122
- <section class="flex flex-col gap-8 p-4 bg-surface-secondary">
123
- <div>
124
- <h2 class="heading-m font-bold text-content-on-surface-primary">Do's and Don'ts</h2>
125
- </div>
126
-
127
- <div class="grid gap-8 md:grid-cols-2">
128
- <div class="flex flex-col gap-3">
129
- <h3 class="body-m-medium text-content-on-surface-primary">Do</h3>
130
- <ul class="body-m-regular list-disc space-y-2 pl-5 text-content-on-surface-primary">
131
- <li>Use checkboxes for independent choices</li>
132
- <li>Allow multiple selections when appropriate</li>
133
- <li>Write descriptive labels</li>
134
- <li>Group related options together</li>
135
- <li>Provide supporting descriptions when needed</li>
136
- <li>Use indeterminate states for partial selection patterns</li>
137
- </ul>
138
- </div>
139
-
140
- <div class="flex flex-col gap-3">
141
- <h3 class="body-m-medium text-content-on-surface-primary">Don't</h3>
142
- <ul class="body-m-regular list-disc space-y-2 pl-5 text-content-on-surface-primary">
143
- <li>Use checkboxes when only one choice is allowed (use radio instead)</li>
144
- <li>Present unrelated options in the same group</li>
145
- <li>Use vague labels like "Enable" or "Yes"</li>
146
- <li>Depend solely on color to communicate state</li>
147
- </ul>
148
- </div>
149
- </div>
150
- </section>
151
- `,
152
- }),
133
+ ...designNotesStory(guidance),
153
134
  tags: ['!autodocs'],
154
- parameters: {
155
- a11y: { test: 'off' },
156
- chromatic: {
157
- disableSnapshot: true,
158
- },
159
- docs: {
160
- canvas: {
161
- sourceState: 'none',
162
- },
163
- },
164
- },
165
135
  };
166
136
 
167
137
  /**
@@ -176,7 +146,7 @@ export const Accessibility: Story = {
176
146
  return { defaultChecked, accessibleChecked };
177
147
  },
178
148
  template: `
179
- <section class="flex flex-col gap-6 p-4">
149
+ <section class="${guidanceSectionClass}">
180
150
  <div>
181
151
  <h2 class="heading-m font-bold text-content-on-surface-primary">
182
152
  Accessibility
@@ -184,16 +154,7 @@ export const Accessibility: Story = {
184
154
  </div>
185
155
 
186
156
  <div class="flex flex-col gap-6">
187
- <div class="flex flex-col gap-2">
188
- <h3 class="body-m-medium text-content-on-surface-primary">
189
- Requirements
190
- </h3>
191
- <ul class="body-m-regular list-disc pl-5 text-content-on-surface-primary">
192
- <li>Every checkbox has a visible label</li>
193
- <li>Descriptions remain readable and associated with the field</li>
194
- <li>Keyboard focus is correct in a checkbox group</li>
195
- </ul>
196
- </div>
157
+ ${accessibilityRequirementsTemplate(guidance.accessibility, 'Requirements')}
197
158
 
198
159
  <div class="flex flex-col gap-2">
199
160
  <h3 class="body-m-medium text-content-on-surface-primary">
@@ -260,6 +221,7 @@ export const Accessibility: Story = {
260
221
  }),
261
222
  tags: ['!autodocs'],
262
223
  parameters: {
224
+ surface: 'primary',
263
225
  a11y: { test: 'off' },
264
226
  chromatic: {
265
227
  disableSnapshot: true,
@@ -0,0 +1,64 @@
1
+ ---
2
+ figma: '29190:69457'
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 Chips component turns choices into compact elements the user can select, deselect and remove. Each chip stays visible once chosen, so the whole set of current selections can be read at a glance.
10
+
11
+ Use chips where selections accumulate and must stay in view: filters, tags, chosen options. When the choice is single and hidden until opened, use Select or Combobox.
12
+
13
+ ### The selected state has to be unmistakable
14
+
15
+ A chip's whole job is showing whether it is on:
16
+
17
+ - Active and default differ in fill and border, not only in colour
18
+ - Hover and focus stay distinguishable from active
19
+ - The close icon appears only on chips the user can remove
20
+ - Disabled chips read as unavailable rather than merely faint
21
+
22
+ ### Let the set grow and shrink
23
+
24
+ A chip group is a live list, so it has to behave like one:
25
+
26
+ 1. Chips wrap to new lines rather than scrolling out of view
27
+ 2. New selections join at the end of the set
28
+ 3. Removing a chip reflows the rest without moving the add action
29
+ 4. The add action stays at the end, where the next chip will appear
30
+
31
+ ### Consistency
32
+
33
+ Every chip group is built from the same parts:
34
+
35
+ - Chip, with an optional leading icon and an optional close icon
36
+ - Chip states: default, hover, focus, active, active hover, active focus and disabled
37
+ - Chips group, holding up to nine chips
38
+ - Add action, closing the group
39
+
40
+ ## Do
41
+
42
+ - Show the selected state through fill and border together
43
+ - Keep chip labels to a few words, so the set stays scannable
44
+ - Let chips wrap to more lines rather than clipping the set
45
+ - Put the close icon only on chips the user may remove
46
+ - Keep the add action in a fixed position at the end of the group
47
+
48
+ ## Don't
49
+
50
+ - Use chips as buttons for actions
51
+ - Rely on colour alone to show which chips are active
52
+ - Let a long label stretch a chip across the row
53
+ - Hide selected chips behind a count
54
+ - Mix removable and non-removable chips with no visible difference
55
+ - Reorder the set when a chip is selected
56
+
57
+ ## Accessibility
58
+
59
+ - Active and inactive chips differ in fill and border, so the state survives without colour
60
+ - Focus is visible on a chip in every state, including when the chip is already active
61
+ - The close icon is a comfortable target of its own, separate from the chip's label
62
+ - Disabled chips are distinguishable by more than reduced opacity
63
+ - Labels stay legible within the chip's padding, and are never tightened to fit
64
+ - The group reads in a stable order, so removing a chip does not shuffle the rest