@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.
Files changed (124) hide show
  1. package/dist/system/components/UiSlider/step-marks.d.ts +45 -0
  2. package/dist/system/components/UiSlider/types.d.ts +28 -0
  3. package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
  4. package/dist/system/icons/story-sidebar-icons.json +74 -17
  5. package/dist/system/lib.js +2026 -1912
  6. package/dist/system/patterns/UiPlaceholder/types.d.ts +1 -0
  7. package/dist/system/story-sidebar-icons.json +74 -17
  8. package/package.json +15 -10
  9. package/src/components/UiAccordion/UiAccordion.guidance.md +66 -0
  10. package/src/components/UiAccordion/UiAccordion.stories.ts +131 -139
  11. package/src/components/UiAlert/UiAlert.guidance.md +66 -0
  12. package/src/components/UiAlert/UiAlert.stories.ts +167 -143
  13. package/src/components/UiAlertDialog/UiAlertDialog.guidance.md +66 -0
  14. package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +136 -112
  15. package/src/components/UiAutocomplete/UiAutocomplete.guidance.md +66 -0
  16. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +123 -99
  17. package/src/components/UiAvatar/UiAvatar.guidance.md +63 -0
  18. package/src/components/UiAvatar/UiAvatar.stories.ts +340 -0
  19. package/src/components/UiAvatar/UiAvatarImage.vue +5 -1
  20. package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +14 -0
  21. package/src/components/UiBadge/UiBadge.guidance.md +65 -0
  22. package/src/components/UiBadge/UiBadge.stories.ts +325 -0
  23. package/src/components/UiBreadcrumb/UiBreadcrumb.guidance.md +67 -0
  24. package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +165 -141
  25. package/src/components/UiButton/UiButton.stories.ts +5 -2
  26. package/src/components/UiButtonGroup/UiButtonGroup.guidance.md +63 -0
  27. package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +91 -67
  28. package/src/components/UiCalendar/UiCalendar.guidance.md +65 -0
  29. package/src/components/UiCalendar/UiCalendar.stories.ts +103 -110
  30. package/src/components/UiCard/UiCard.guidance.md +65 -0
  31. package/src/components/UiCard/UiCard.stories.ts +393 -0
  32. package/src/components/UiCheckbox/UiCheckbox.guidance.md +62 -0
  33. package/src/components/UiCheckbox/UiCheckbox.stories.ts +18 -56
  34. package/src/components/UiChip/UiChip.guidance.md +64 -0
  35. package/src/components/UiChip/UiChip.stories.ts +162 -138
  36. package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +291 -0
  37. package/src/components/UiCodeBlock/UiCodeBlock.vue +2 -1
  38. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +18 -0
  39. package/src/components/UiDialog/UiDialog.guidance.md +66 -0
  40. package/src/components/UiDialog/UiDialog.stories.ts +90 -66
  41. package/src/components/UiDrawer/UiDrawer.guidance.md +66 -0
  42. package/src/components/UiDrawer/UiDrawer.stories.ts +186 -162
  43. package/src/components/UiDropdownMenu/UiDropdownMenu.guidance.md +68 -0
  44. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +127 -86
  45. package/src/components/UiEmpty/UiEmpty.guidance.md +66 -0
  46. package/src/components/UiEmpty/UiEmpty.stories.ts +370 -15
  47. package/src/components/UiFadeMask/UiFadeMask.stories.ts +66 -0
  48. package/src/components/UiField/UiField.guidance.md +63 -0
  49. package/src/components/UiField/UiField.stories.ts +90 -113
  50. package/src/components/UiFileType/UiFileType.stories.ts +254 -0
  51. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +74 -72
  52. package/src/components/UiIcon/UiIcon.stories.ts +256 -1
  53. package/src/components/UiInput/UiInput.guidance.md +64 -0
  54. package/src/components/UiInput/UiInput.stories.ts +132 -80
  55. package/src/components/UiInputGroup/UiInputGroup.guidance.md +66 -0
  56. package/src/components/UiInputGroup/UiInputGroup.stories.ts +127 -103
  57. package/src/components/UiItem/UiItem.guidance.md +66 -0
  58. package/src/components/UiItem/UiItem.stories.ts +81 -28
  59. package/src/components/UiKbd/UiKbd.guidance.md +65 -0
  60. package/src/components/UiKbd/UiKbd.stories.ts +373 -3
  61. package/src/components/UiLabel/UiLabel.guidance.md +65 -0
  62. package/src/components/UiLabel/UiLabel.stories.ts +163 -139
  63. package/src/components/UiListbox/UiListbox.stories.ts +197 -195
  64. package/src/components/UiNavigationMenu/UiNavigationMenu.guidance.md +66 -0
  65. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +169 -169
  66. package/src/components/UiPopover/UiPopover.guidance.md +65 -0
  67. package/src/components/UiPopover/UiPopover.stories.ts +115 -91
  68. package/src/components/UiProgress/UiProgress.guidance.md +65 -0
  69. package/src/components/UiProgress/UiProgress.stories.ts +300 -0
  70. package/src/components/UiRadioGroup/UiRadioGroup.guidance.md +66 -0
  71. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +163 -139
  72. package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +128 -127
  73. package/src/components/UiResizable/UiResizable.guidance.md +65 -0
  74. package/src/components/UiResizable/UiResizable.stories.ts +176 -152
  75. package/src/components/UiSelect/UiSelect.guidance.md +66 -0
  76. package/src/components/UiSelect/UiSelect.stories.ts +150 -126
  77. package/src/components/UiSeparator/UiSeparator.guidance.md +64 -0
  78. package/src/components/UiSeparator/UiSeparator.stories.ts +350 -0
  79. package/src/components/UiSheet/UiSheet.guidance.md +66 -0
  80. package/src/components/UiSheet/UiSheet.stories.ts +194 -170
  81. package/src/components/UiSkeleton/UiSkeleton.guidance.md +65 -0
  82. package/src/components/UiSkeleton/UiSkeleton.stories.ts +253 -0
  83. package/src/components/UiSlider/UiSlider.guidance.md +66 -0
  84. package/src/components/UiSlider/UiSlider.stories.ts +885 -153
  85. package/src/components/UiSlider/UiSlider.vue +109 -1
  86. package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
  87. package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
  88. package/src/components/UiSlider/step-marks.ts +96 -0
  89. package/src/components/UiSlider/types.ts +32 -0
  90. package/src/components/UiSnackbar/UiSnackbar.guidance.md +66 -0
  91. package/src/components/UiSnackbar/UiSnackbar.stories.ts +106 -96
  92. package/src/components/UiSpinner/UiSpinner.guidance.md +65 -0
  93. package/src/components/UiSpinner/UiSpinner.stories.ts +249 -0
  94. package/src/components/UiStepper/UiStepper.guidance.md +66 -0
  95. package/src/components/UiStepper/UiStepper.stories.ts +142 -124
  96. package/src/components/UiSwitch/UiSwitch.guidance.md +66 -0
  97. package/src/components/UiSwitch/UiSwitch.stories.ts +170 -146
  98. package/src/components/UiTable/UiTable.guidance.md +66 -0
  99. package/src/components/UiTable/UiTable.stories.ts +530 -12
  100. package/src/components/UiTabs/UiTabs.guidance.md +66 -0
  101. package/src/components/UiTabs/UiTabs.stories.ts +174 -150
  102. package/src/components/UiTagsInput/UiTagsInput.stories.ts +154 -152
  103. package/src/components/UiTextarea/UiTextarea.guidance.md +66 -0
  104. package/src/components/UiTextarea/UiTextarea.stories.ts +86 -62
  105. package/src/components/UiToggle/UiToggle.guidance.md +66 -0
  106. package/src/components/UiToggle/UiToggle.stories.ts +183 -159
  107. package/src/components/UiToggleGroup/UiToggleGroup.guidance.md +64 -0
  108. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +222 -200
  109. package/src/components/UiTooltip/UiTooltip.guidance.md +66 -0
  110. package/src/components/UiTooltip/UiTooltip.stories.ts +90 -66
  111. package/src/components/core/slider/Slider.vue +16 -6
  112. package/src/patterns/UiDataTable/UiDataTable.guidance.md +66 -0
  113. package/src/patterns/UiDataTable/UiDataTable.stories.ts +177 -155
  114. package/src/patterns/UiDatePicker/UiDatePicker.guidance.md +66 -0
  115. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +136 -112
  116. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +77 -75
  117. package/src/patterns/UiFileUpload/UiFileUpload.guidance.md +68 -0
  118. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +169 -145
  119. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +103 -101
  120. package/src/patterns/UiLayout/UiLayoutContent.stories.ts +14 -13
  121. package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +65 -65
  122. package/src/patterns/UiPlaceholder/types.ts +1 -0
  123. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +86 -84
  124. package/src/patterns/UiTopBar/UiTopBar.stories.ts +84 -82
@@ -1,10 +1,20 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect, userEvent, waitFor, within } from 'storybook/test';
2
3
  import {
3
4
  UiAvatar,
4
5
  UiAvatarFallback,
5
6
  UiAvatarGroup,
6
7
  UiAvatarImage,
7
8
  } from './index';
9
+ import {
10
+ accessibilityStory,
11
+ designNotesStory,
12
+ guidanceLinks,
13
+ parseGuidance,
14
+ } from '../../../.storybook/guidance';
15
+ import guidanceMarkdown from './UiAvatar.guidance.md?raw';
16
+
17
+ const guidance = parseGuidance(guidanceMarkdown);
8
18
 
9
19
  /**
10
20
  * UiAvatar is a small image-based representation of a user or entity, with a graceful text or icon fallback when the image fails to load.
@@ -25,12 +35,49 @@ const meta: Meta<typeof UiAvatar> = {
25
35
  args: {
26
36
  size: 8,
27
37
  },
38
+ parameters: {
39
+ docs: { links: guidanceLinks(guidance) },
40
+ },
28
41
  };
29
42
 
30
43
  export default meta;
31
44
 
32
45
  type Story = StoryObj<typeof UiAvatar>;
33
46
 
47
+ /**
48
+ * Inline image for the test-only stories, so reaching the loaded state
49
+ * doesn't depend on network access.
50
+ */
51
+ const TEST_IMAGE_SRC =
52
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' fill='%23c9b8f0'/%3E%3C/svg%3E";
53
+
54
+ function createSizeStory(size: 5 | 6 | 10 | 12): Story {
55
+ const template = `<UiAvatar :size="${size}">
56
+ <UiAvatarImage src="https://github.com/shadcn.png" alt="@shadcn" />
57
+ <UiAvatarFallback>CN</UiAvatarFallback>
58
+ </UiAvatar>`;
59
+
60
+ return {
61
+ render: () => ({
62
+ components: { UiAvatar, UiAvatarFallback, UiAvatarImage },
63
+ template,
64
+ }),
65
+ parameters: {
66
+ docs: {
67
+ source: {
68
+ code: `<script setup lang="ts">
69
+ import { UiAvatar, UiAvatarFallback, UiAvatarImage } from '@aleph-alpha/ui-library'
70
+ </script>
71
+
72
+ <template>
73
+ ${template}
74
+ </template>`,
75
+ },
76
+ },
77
+ },
78
+ };
79
+ }
80
+
34
81
  const defaultTemplateSource = `<script setup lang="ts">
35
82
  import { UiAvatar, UiAvatarFallback, UiAvatarImage } from '@aleph-alpha/ui-library'
36
83
  </script>
@@ -71,6 +118,40 @@ export const Default: Story = {
71
118
  },
72
119
  };
73
120
 
121
+ /**
122
+ * Design guidance for identifying people with an image or initials fallback.
123
+ */
124
+ export const DesignNotes: Story = {
125
+ ...designNotesStory(guidance),
126
+ tags: ['!autodocs'],
127
+ };
128
+
129
+ /**
130
+ * Accessibility guidance for naming the person beside the avatar and keeping
131
+ * the fallback legible — shown in the default and accessible themes.
132
+ */
133
+ export const Accessibility: Story = {
134
+ ...accessibilityStory({
135
+ requirements: guidance.accessibility,
136
+ implementation: [
137
+ 'Give UiAvatarImage an alt naming the person, or alt="" when the name is already shown beside it',
138
+ 'UiAvatarFallback text is read out when the image fails, so use the real initials',
139
+ ],
140
+ example: {
141
+ components: { UiAvatar, UiAvatarFallback, UiAvatarImage },
142
+ template: `
143
+ <div class="flex items-center gap-3">
144
+ <UiAvatar :size="10">
145
+ <UiAvatarFallback>JD</UiAvatarFallback>
146
+ </UiAvatar>
147
+ <span class="body-m-medium text-content-on-surface-primary">Jane Doe</span>
148
+ </div>
149
+ `,
150
+ },
151
+ }),
152
+ tags: ['!autodocs'],
153
+ };
154
+
74
155
  const sizesTemplateSource = `<script setup lang="ts">
75
156
  import { UiAvatar, UiAvatarFallback, UiAvatarImage } from '@aleph-alpha/ui-library'
76
157
  </script>
@@ -144,6 +225,26 @@ export const Sizes: Story = {
144
225
  },
145
226
  };
146
227
 
228
+ /**
229
+ * Extra-small avatar (`size-5`, 20px) for dense lists and inline mentions.
230
+ */
231
+ export const Size5: Story = createSizeStory(5);
232
+
233
+ /**
234
+ * Small avatar (`size-6`, 24px) for compact rows and chips.
235
+ */
236
+ export const Size6: Story = createSizeStory(6);
237
+
238
+ /**
239
+ * Medium-large avatar (`size-10`, 40px) for comments and list items.
240
+ */
241
+ export const Size10: Story = createSizeStory(10);
242
+
243
+ /**
244
+ * Large avatar (`size-12`, 48px) for profile headers and cards.
245
+ */
246
+ export const Size12: Story = createSizeStory(12);
247
+
147
248
  const fallbackTemplateSource = `<script setup lang="ts">
148
249
  import { UiAvatar, UiAvatarFallback, UiAvatarImage } from '@aleph-alpha/ui-library'
149
250
  </script>
@@ -179,6 +280,19 @@ export const Fallback: Story = {
179
280
  },
180
281
  },
181
282
  },
283
+ play: async ({ canvasElement, step }) => {
284
+ // Scenario (UiAvatar): the image source is empty, so the avatar swaps the
285
+ // broken image for the initials.
286
+ const canvas = within(canvasElement);
287
+
288
+ await step(
289
+ 'interaction: shows the initials when the image fails to load',
290
+ async () => {
291
+ await expect(await canvas.findByText('CN')).toBeVisible();
292
+ await expect(canvas.queryByRole('img')).not.toBeInTheDocument();
293
+ },
294
+ );
295
+ },
182
296
  };
183
297
 
184
298
  const multipleTemplateSource = `<script setup lang="ts">
@@ -287,3 +401,229 @@ export const AvatarGroup: Story = {
287
401
  },
288
402
  },
289
403
  };
404
+
405
+ const renderTestAvatars = () => ({
406
+ components: { UiAvatar, UiAvatarFallback, UiAvatarGroup, UiAvatarImage },
407
+ setup() {
408
+ return { TEST_IMAGE_SRC };
409
+ },
410
+ template: `
411
+ <div class="flex flex-col gap-4">
412
+ <div class="flex items-center gap-4">
413
+ <UiAvatar :size="10">
414
+ <UiAvatarImage :src="TEST_IMAGE_SRC" alt="Jane Doe" />
415
+ <UiAvatarFallback>JD</UiAvatarFallback>
416
+ </UiAvatar>
417
+ <UiAvatar :size="10">
418
+ <UiAvatarImage src="" alt="Alex Brown" />
419
+ <UiAvatarFallback>AB</UiAvatarFallback>
420
+ </UiAvatar>
421
+ </div>
422
+ <div class="flex items-center gap-3">
423
+ <UiAvatar>
424
+ <UiAvatarImage :src="TEST_IMAGE_SRC" alt="" />
425
+ <UiAvatarFallback>SK</UiAvatarFallback>
426
+ </UiAvatar>
427
+ <span class="body-m-medium">Sam Kim</span>
428
+ </div>
429
+ <UiAvatarGroup>
430
+ <UiAvatar><UiAvatarFallback>LR</UiAvatarFallback></UiAvatar>
431
+ <UiAvatar><UiAvatarFallback>ER</UiAvatarFallback></UiAvatar>
432
+ <UiAvatar><UiAvatarFallback>MP</UiAvatarFallback></UiAvatar>
433
+ </UiAvatarGroup>
434
+ </div>
435
+ `,
436
+ });
437
+
438
+ /**
439
+ * Avatars are presentational, so there is nothing to focus: the keyboard
440
+ * check asserts they stay out of the tab order. Hidden test-only story.
441
+ */
442
+ export const KeyboardNavigation: Story = {
443
+ name: 'test - Keyboard Navigation',
444
+ tags: ['!dev', '!autodocs'],
445
+ parameters: {
446
+ // Focus moves during the play function.
447
+ chromatic: { disableSnapshot: true },
448
+ docs: {
449
+ description: {
450
+ story:
451
+ 'Press `Tab`: focus skips the avatars, which are not interactive.',
452
+ },
453
+ },
454
+ },
455
+ render: renderTestAvatars,
456
+ play: async ({ canvasElement, step }) => {
457
+ // Scenario (UiAvatar): a keyboard user tabs through the page and never
458
+ // lands on an avatar, image, or fallback.
459
+ await step('keyboard: avatars are not tab stops', async () => {
460
+ await userEvent.tab();
461
+ await expect(canvasElement.contains(document.activeElement)).toBe(false);
462
+ });
463
+
464
+ await step('keyboard: no avatar part carries a tabindex', async () => {
465
+ await expect(canvasElement.querySelectorAll('[tabindex]')).toHaveLength(
466
+ 0,
467
+ );
468
+ });
469
+ },
470
+ };
471
+
472
+ /**
473
+ * What assistive technology announces for a loaded image, a failed image, and
474
+ * a decorative avatar beside a visible name (WCAG 1.1.1). Hidden test-only
475
+ * story.
476
+ */
477
+ export const ScreenReader: Story = {
478
+ name: 'test - Screen Reader',
479
+ tags: ['!dev', '!autodocs'],
480
+ parameters: {
481
+ docs: {
482
+ description: {
483
+ story:
484
+ 'Verifies the image names and fallback text that assistive technology announces.',
485
+ },
486
+ },
487
+ },
488
+ render: renderTestAvatars,
489
+ play: async ({ canvasElement, step }) => {
490
+ // Scenario (UiAvatar): a loaded image is named by its alt text, a failed
491
+ // image falls back to initials, and an avatar next to the person's name
492
+ // is skipped so the name isn't read twice.
493
+ const canvas = within(canvasElement);
494
+
495
+ await step(
496
+ 'screen-reader: a loaded image is announced by its alt text (WCAG 1.1.1)',
497
+ async () => {
498
+ const image = await canvas.findByRole('img', { name: 'Jane Doe' });
499
+ await expect(image).toHaveAccessibleName('Jane Doe');
500
+ },
501
+ );
502
+
503
+ await step(
504
+ 'screen-reader: a failed image falls back to readable initials',
505
+ async () => {
506
+ await expect(canvas.getByText('AB')).toBeVisible();
507
+ await expect(
508
+ canvas.queryByRole('img', { name: 'Alex Brown' }),
509
+ ).not.toBeInTheDocument();
510
+ },
511
+ );
512
+
513
+ await step(
514
+ 'screen-reader: an avatar beside a visible name is decorative (alt="")',
515
+ async () => {
516
+ await waitFor(async () => {
517
+ await expect(canvas.queryByText('SK')).not.toBeInTheDocument();
518
+ });
519
+ await expect(canvas.getAllByRole('img')).toHaveLength(1);
520
+ await expect(canvas.getByText('Sam Kim')).toBeVisible();
521
+ },
522
+ );
523
+ },
524
+ };
525
+
526
+ /**
527
+ * Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
528
+ * try 400% reflow (WCAG 1.4.10). Hidden test-only story.
529
+ */
530
+ export const ZoomMagnification: Story = {
531
+ name: 'test - Zoom Magnification',
532
+ tags: ['!dev', '!autodocs'],
533
+ globals: { zoom: '200' },
534
+ parameters: {
535
+ // Zoom changes the layout scale; the accessible-reflow Chromatic mode
536
+ // already covers magnified snapshots, so skip this one.
537
+ chromatic: { disableSnapshot: true },
538
+ docs: {
539
+ description: {
540
+ story:
541
+ 'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
542
+ },
543
+ },
544
+ },
545
+ render: renderTestAvatars,
546
+ play: async ({ canvasElement, step }) => {
547
+ // Scenario (UiAvatar): at 200% page zoom the avatars stay inside the
548
+ // viewport and keep their names and initials.
549
+ const canvas = within(canvasElement);
550
+
551
+ await step(
552
+ 'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
553
+ async () => {
554
+ await expect(document.documentElement.style.zoom).toBe('200%');
555
+ },
556
+ );
557
+
558
+ await step('zoom: image and initials stay readable', async () => {
559
+ await expect(
560
+ await canvas.findByRole('img', { name: 'Jane Doe' }),
561
+ ).toBeVisible();
562
+ await expect(canvas.getByText('AB')).toBeVisible();
563
+ });
564
+
565
+ await step('zoom: avatars stay inside the viewport', async () => {
566
+ const avatars = canvasElement.querySelectorAll<HTMLElement>(
567
+ '[data-slot="avatar"]',
568
+ );
569
+ await expect(avatars.length).toBeGreaterThan(0);
570
+
571
+ for (const avatar of avatars) {
572
+ const { left, right } = avatar.getBoundingClientRect();
573
+ await expect(left).toBeGreaterThanOrEqual(0);
574
+ await expect(right).toBeLessThanOrEqual(window.innerWidth + 1);
575
+ }
576
+ });
577
+ },
578
+ };
579
+
580
+ /**
581
+ * Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
582
+ * toolbar. Hidden test-only story.
583
+ */
584
+ export const MobileBreakpoint: Story = {
585
+ name: 'test - Mobile Breakpoint',
586
+ tags: ['!dev', '!autodocs'],
587
+ globals: { mediaBreakpoint: 'reflow' },
588
+ parameters: {
589
+ // Reflow snapshots are already covered by the accessible-reflow mode.
590
+ chromatic: { disableSnapshot: true },
591
+ docs: {
592
+ description: {
593
+ story:
594
+ 'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
595
+ },
596
+ },
597
+ },
598
+ render: renderTestAvatars,
599
+ play: async ({ canvasElement, step }) => {
600
+ // Scenario (UiAvatar): at the 320px mobile breakpoint the avatars and the
601
+ // group fit without sideways scrolling.
602
+ const canvas = within(canvasElement);
603
+
604
+ await step('mobile: avatars render at the 320px breakpoint', async () => {
605
+ await expect(
606
+ await canvas.findByRole('img', { name: 'Jane Doe' }),
607
+ ).toBeVisible();
608
+ await expect(canvas.getByText('MP')).toBeVisible();
609
+ });
610
+
611
+ await step(
612
+ 'mobile: the layout fits without sideways scrolling (WCAG 1.4.10 Reflow)',
613
+ async () => {
614
+ const { scrollWidth, clientWidth } = document.documentElement;
615
+ await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
616
+ },
617
+ );
618
+
619
+ await step(
620
+ 'mobile: avatars add no touch targets of their own',
621
+ async () => {
622
+ // The 2.5.8 target-size check applies to whatever control wraps an
623
+ // avatar (a link or button), not to the avatar itself.
624
+ await expect(canvas.queryAllByRole('button')).toHaveLength(0);
625
+ await expect(canvas.queryAllByRole('link')).toHaveLength(0);
626
+ },
627
+ );
628
+ },
629
+ };
@@ -10,5 +10,9 @@ const props = defineProps<UiAvatarImageProps>();
10
10
  </script>
11
11
 
12
12
  <template>
13
- <ShadcnAvatarImage v-bind="props" />
13
+ <!-- Reka sets role="img" on every image; alt="" must stay decorative. -->
14
+ <ShadcnAvatarImage
15
+ v-bind="props"
16
+ :role="props.alt === '' ? 'presentation' : 'img'"
17
+ />
14
18
  </template>
@@ -24,6 +24,20 @@ describe('UiAvatar', () => {
24
24
  expect(img).toHaveAttribute('alt', 'User avatar');
25
25
  });
26
26
 
27
+ test('marks an image with empty alt as decorative', () => {
28
+ const { container } = render(UiAvatar, {
29
+ slots: {
30
+ default: () =>
31
+ h(UiAvatarImage, { src: 'https://example.com/avatar.png', alt: '' }),
32
+ },
33
+ });
34
+
35
+ expect(container.querySelector('img')).toHaveAttribute(
36
+ 'role',
37
+ 'presentation',
38
+ );
39
+ });
40
+
27
41
  test('renders fallback content', () => {
28
42
  const { container, getByText } = render(UiAvatar, {
29
43
  slots: {
@@ -0,0 +1,65 @@
1
+ ---
2
+ figma: '29184:69294'
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 Badge component attaches a short label or a count to something else — a row, a tab, a name, a menu item. It is read as part of that thing rather than as a message of its own.
10
+
11
+ Use it for status that fits in a word and counts of two or three digits. When the message needs a sentence use Alert, and when it needs an answer use a dialog.
12
+
13
+ ### One word, one meaning
14
+
15
+ A badge only works if its vocabulary is fixed:
16
+
17
+ - The same word always means the same thing across the product
18
+ - Variants map to meaning: success, warning, destructive, verified
19
+ - Default and secondary carry neutral labels, not states
20
+ - Outline is for labels that should recede beside their content
21
+
22
+ ### Keep it attached
23
+
24
+ A badge belongs to something, so place it accordingly:
25
+
26
+ 1. Sit it directly beside, or on, the element it describes
27
+ 2. Keep it on the same line, aligned to the text it qualifies
28
+ 3. Use the small size in dense rows and the default size elsewhere
29
+ 4. Use Badge Number when the value is a count rather than a label
30
+
31
+ ### Consistency
32
+
33
+ Every badge is built from the same parts:
34
+
35
+ - Badge, with text and an optional icon on either side
36
+ - Badge number, for counts
37
+ - Variants: default, secondary, outline, success, warning, destructive, verified
38
+ - Sizes: default and small
39
+ - States: default and disabled
40
+
41
+ ## Do
42
+
43
+ - Fix the vocabulary and use the same word for the same state everywhere
44
+ - Pair a colour variant with an icon or a word carrying the same meaning
45
+ - Use the small size in tables and dense lists
46
+ - Cap counts at a sensible maximum and show the overflow, such as 99+
47
+ - Keep the badge on the same line as what it describes
48
+
49
+ ## Don't
50
+
51
+ - Use a badge as a button
52
+ - Write a sentence inside a badge
53
+ - Rely on the variant colour alone to convey status
54
+ - Mix badge sizes within one row or list
55
+ - Let a count grow wide enough to change the row's layout
56
+ - Use the success or warning variants for things that are not states
57
+
58
+ ## Accessibility
59
+
60
+ - Every status badge carries its meaning in the word or icon, so colour is never the only signal
61
+ - Badge text holds its contrast against its own fill in all seven variants
62
+ - The disabled state is distinguishable by more than reduced opacity
63
+ - Badge text stays legible at the small size, without tightening below the type's intended spacing
64
+ - Counts stay readable at the widest value the badge is expected to hold
65
+ - A badge beside a label reads as part of it, inside the same line and reading order