@aleph-alpha/ui-library 5.8.0 → 5.10.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 (111) hide show
  1. package/README.md +8 -7
  2. package/config.js +157 -4
  3. package/dist/system/__tests__/test-utils.d.ts +24 -0
  4. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
  5. package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
  6. package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
  7. package/dist/system/components/UiFadeMask/index.d.ts +2 -0
  8. package/dist/system/components/UiFadeMask/types.d.ts +33 -0
  9. package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +3 -1
  10. package/dist/system/components/UiFileType/types.d.ts +2 -1
  11. package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
  12. package/dist/system/components/UiListbox/index.d.ts +1 -0
  13. package/dist/system/components/UiListbox/types.d.ts +36 -0
  14. package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
  15. package/dist/system/components/UiSelect/index.d.ts +1 -0
  16. package/dist/system/components/UiSelect/types.d.ts +36 -0
  17. package/dist/system/components/UiSwitch/UiSwitch.vue.d.ts +1 -0
  18. package/dist/system/components/UiSwitch/types.d.ts +12 -0
  19. package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
  20. package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
  21. package/dist/system/components/core/switch/Switch.vue.d.ts +2 -0
  22. package/dist/system/components/core/switch/index.d.ts +8 -0
  23. package/dist/system/components/index.d.ts +1 -0
  24. package/dist/system/index.d.ts +1 -0
  25. package/dist/system/lib/scrollbar.d.ts +37 -0
  26. package/dist/system/lib/useAnchorFloat.d.ts +0 -2
  27. package/dist/system/lib/useIsTruncated.d.ts +15 -0
  28. package/dist/system/lib.js +22660 -21292
  29. package/dist/system/mobile-device-frame.png +0 -0
  30. package/dist/system/patterns/UiFloatActions/types.d.ts +2 -2
  31. package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
  32. package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
  33. package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
  34. package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
  35. package/dist/system/patterns/index.d.ts +2 -0
  36. package/dist/system/story-sidebar-icons.json +7 -1
  37. package/docs/public-docs/foundations.md +17 -15
  38. package/package.json +4 -3
  39. package/src/__tests__/test-utils.ts +74 -0
  40. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
  41. package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
  42. package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
  43. package/src/components/UiAutocomplete/types.ts +11 -0
  44. package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +54 -0
  45. package/src/components/UiCodeBlock/UiCodeBlock.vue +84 -32
  46. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +65 -21
  47. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
  48. package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
  49. package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
  50. package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
  51. package/src/components/UiFadeMask/index.ts +6 -0
  52. package/src/components/UiFadeMask/types.ts +35 -0
  53. package/src/components/UiFileItem/UiFileItem.vue +17 -4
  54. package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +49 -90
  55. package/src/components/UiFileType/UiFileType.stories.ts +13 -2
  56. package/src/components/UiFileType/UiFileType.vue +8 -0
  57. package/src/components/UiFileType/__tests__/UiFileType.test.ts +10 -0
  58. package/src/components/UiFileType/types.ts +3 -1
  59. package/src/components/UiListbox/UiListbox.stories.ts +121 -0
  60. package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
  61. package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
  62. package/src/components/UiListbox/index.ts +1 -0
  63. package/src/components/UiListbox/types.ts +42 -0
  64. package/src/components/UiSelect/UiSelect.stories.ts +109 -1
  65. package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
  66. package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
  67. package/src/components/UiSelect/index.ts +1 -0
  68. package/src/components/UiSelect/types.ts +38 -0
  69. package/src/components/UiSnackbar/UiSnackbar.stories.ts +4 -5
  70. package/src/components/UiSwitch/UiSwitch.stories.ts +658 -7
  71. package/src/components/UiSwitch/UiSwitch.vue +1 -0
  72. package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +48 -0
  73. package/src/components/UiSwitch/types.ts +13 -0
  74. package/src/components/UiToggleGroup/UiToggleGroup.vue +1 -1
  75. package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
  76. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  77. package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
  78. package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
  79. package/src/components/core/field/FieldLabel.vue +1 -1
  80. package/src/components/core/label/Label.vue +1 -1
  81. package/src/components/core/listbox/ListboxItem.vue +1 -1
  82. package/src/components/core/switch/Switch.vue +23 -17
  83. package/src/components/core/switch/index.ts +36 -0
  84. package/src/components/index.ts +1 -0
  85. package/src/index.ts +3 -0
  86. package/src/lib/scrollbar.ts +295 -0
  87. package/src/lib/useAnchorFloat.ts +0 -2
  88. package/src/lib/useIsTruncated.test.ts +174 -0
  89. package/src/lib/useIsTruncated.ts +75 -0
  90. package/src/patterns/UiFileUpload/UiFileItem.stories.ts +1162 -0
  91. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +552 -1
  92. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +5 -21
  93. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +0 -1
  94. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -6
  95. package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -12
  96. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
  97. package/src/patterns/UiFloatActions/types.ts +2 -2
  98. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1079 -0
  99. package/src/patterns/UiProfileCard/index.ts +7 -0
  100. package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
  101. package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
  102. package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
  103. package/src/patterns/UiTopBar/index.ts +2 -0
  104. package/src/patterns/UiTopBar/types.ts +29 -0
  105. package/src/patterns/index.ts +2 -0
  106. package/src/theme/Background.stories.ts +27 -1
  107. package/src/theme/BorderRadius.stories.ts +5 -0
  108. package/src/theme/Overlay.stories.ts +12 -1
  109. package/src/theme/Scrollbar.stories.ts +260 -0
  110. package/tokens.json +224 -2
  111. package/src/components/UiFileItem/UiFileItem.stories.ts +0 -442
@@ -0,0 +1,35 @@
1
+ export type UiFadeMaskBackground = 'primary' | 'secondary';
2
+
3
+ export type UiFadeMaskPosition = 'top' | 'bottom';
4
+
5
+ /**
6
+ * Wraps content and lays a gradient band over one of its edges, so scrolling or
7
+ * clipped content dissolves into the surface instead of ending on a hard cut.
8
+ * Put a scroll container in the slot and the band stays pinned to the wrapper's
9
+ * top or bottom edge.
10
+ *
11
+ * The band is decorative and lets pointer events through, so the wrapped
12
+ * content stays scrollable and clickable underneath it. Its height defaults to
13
+ * 4rem on mobile and 6rem from the medium breakpoint up, and can be retuned per
14
+ * usage with the `--ui-fade-mask-height` custom property.
15
+ * @category Layout
16
+ * @useCases scroll fade, overflow hint, clipped text fade, scroll edge indicator, sticky header backdrop
17
+ * @keywords fade, mask, gradient, scrim, overlay, scroll, overflow, edge
18
+ * @related UiSeparator, UiSheet
19
+ */
20
+ export interface UiFadeMaskProps {
21
+ /**
22
+ * Surface the gradient fades into. Match it to the background the wrapped
23
+ * content sits on, otherwise the fade ends on a visible edge.
24
+ * @default 'secondary'
25
+ */
26
+ background?: UiFadeMaskBackground;
27
+ /**
28
+ * Edge the band is pinned to. `top` is opaque at the top and fades downwards,
29
+ * `bottom` is opaque at the bottom and fades upwards. The bottom fade ramps
30
+ * across the whole band on desktop and turns opaque near the top edge on
31
+ * mobile, so it reads the same at both band heights.
32
+ * @default 'top'
33
+ */
34
+ position?: UiFadeMaskPosition;
35
+ }
@@ -3,8 +3,10 @@ import { UiButton } from '@/components/UiButton';
3
3
  import { UiFileType } from '@/components/UiFileType';
4
4
  import { UiIcon } from '@/components/UiIcon';
5
5
  import { UiProgress } from '@/components/UiProgress';
6
+ import { UiTooltip } from '@/components/UiTooltip';
6
7
  import { cn } from '@/lib/utils';
7
- import { computed } from 'vue';
8
+ import { useIsTruncated } from '@/lib/useIsTruncated';
9
+ import { computed, useTemplateRef } from 'vue';
8
10
  import type { UiFileItemProps } from './types';
9
11
 
10
12
  defineOptions({
@@ -96,6 +98,11 @@ const titleClass = computed(() =>
96
98
  const progressClass = computed(() =>
97
99
  cn('w-full', isSmall.value ? 'h-1' : 'h-1.5'),
98
100
  );
101
+
102
+ // Long names are clipped to the row width, so the only way to read one in full
103
+ // is a tooltip. Showing it on every row would be noise, hence the measurement.
104
+ const titleRef = useTemplateRef<HTMLElement>('titleRef');
105
+ const isTitleTruncated = useIsTruncated(titleRef, () => displayFilename.value);
99
106
  </script>
100
107
 
101
108
  <template>
@@ -113,9 +120,15 @@ const progressClass = computed(() =>
113
120
  />
114
121
 
115
122
  <div data-slot="file-item-content" :class="contentClass">
116
- <span :class="titleClass" :aria-label="filename">
117
- {{ displayFilename }}
118
- </span>
123
+ <UiTooltip
124
+ :content="filename"
125
+ :disabled="!isTitleTruncated"
126
+ align="start"
127
+ >
128
+ <span ref="titleRef" :class="titleClass" :aria-label="filename">
129
+ {{ displayFilename }}
130
+ </span>
131
+ </UiTooltip>
119
132
 
120
133
  <UiProgress
121
134
  v-if="isWithProgress"
@@ -1,9 +1,25 @@
1
- import { render } from '@testing-library/vue';
1
+ import { render, screen } from '@testing-library/vue';
2
2
  import userEvent from '@testing-library/user-event';
3
- import { describe, expect, test } from 'vitest';
3
+ import { describe, expect, test, vi } from 'vitest';
4
4
  import UiFileItem from '../UiFileItem.vue';
5
5
 
6
+ // jsdom has no layout, so the truncation probe is driven directly: what is
7
+ // under test is that the tooltip follows it, not how the measurement works.
8
+ // Hoisted because `vi.mock`'s factory is lifted above ordinary declarations.
9
+ const { isTruncated } = vi.hoisted(() => ({ isTruncated: { value: false } }));
10
+ vi.mock('@/lib/useIsTruncated', () => ({
11
+ useIsTruncated: () => isTruncated,
12
+ }));
13
+
6
14
  describe('UiFileItem', () => {
15
+ // Interaction, keyboard, and accessibility behavior lives in the play stories
16
+ // in `src/patterns/UiFileUpload/UiFileItem.stories.ts`: the remove event and
17
+ // its disabled guard, the omitted control when `removable` is false, the error
18
+ // alert region, progress and error taking precedence over the type|size meta,
19
+ // and the extension-derived `UiFileType` tone. Those need a real browser for
20
+ // focus order, touch-target size, and accessible-name computation, so they are
21
+ // not duplicated here.
22
+
7
23
  test('renders the basename (without extension) and the type | size meta', () => {
8
24
  const { container, getByText, getByLabelText } = render(UiFileItem, {
9
25
  props: {
@@ -23,108 +39,51 @@ describe('UiFileItem', () => {
23
39
  );
24
40
  });
25
41
 
26
- test('leaves dotfile names without extension segment unchanged', () => {
27
- const { getByText } = render(UiFileItem, {
28
- props: { filename: '.gitignore' },
29
- });
30
- expect(getByText('.gitignore')).toBeInTheDocument();
31
- });
32
-
33
- test('emits remove when remove control is activated', async () => {
42
+ test('keeps the name tooltip closed while the name fits', async () => {
43
+ isTruncated.value = false;
34
44
  const user = userEvent.setup();
35
- const { getByRole, emitted } = render(UiFileItem, {
36
- props: {
37
- filename: 'x.txt',
38
- removeLabel: 'Remove file',
39
- },
40
- });
41
- await user.click(getByRole('button', { name: 'Remove file' }));
42
- expect(emitted('remove')).toHaveLength(1);
43
- });
45
+ render(UiFileItem, { props: { filename: 'doc.pdf' } });
44
46
 
45
- test('does not render the remove control when removable is false', () => {
46
- const { queryByRole } = render(UiFileItem, {
47
- props: {
48
- filename: 'x.txt',
49
- removeLabel: 'Remove file',
50
- removable: false,
51
- },
52
- });
53
- expect(queryByRole('button', { name: 'Remove file' })).toBeNull();
54
- });
47
+ await user.hover(screen.getByText('doc'));
48
+ // Past the tooltip's open delay, so this is a real absence, not a race.
49
+ await new Promise((resolve) => setTimeout(resolve, 800));
55
50
 
56
- test('shows error text in the destructive band when error is set', () => {
57
- const { getByText, getByRole } = render(UiFileItem, {
58
- props: {
59
- filename: 'bad.exe',
60
- error: 'Unsupported file type',
61
- },
62
- });
63
- expect(getByText('Unsupported file type')).toBeInTheDocument();
64
- expect(getByRole('alert')).toHaveTextContent('Unsupported file type');
51
+ // The tooltip portals to the body, so it is searched document-wide.
52
+ expect(screen.queryByRole('tooltip')).toBeNull();
65
53
  });
66
54
 
67
- test('hides type/size meta in the error state even when both are set', () => {
68
- const { queryByText, getByText } = render(UiFileItem, {
69
- props: {
70
- filename: 'bad.exe',
71
- typeLabel: 'EXE',
72
- sizeLabel: '2 MB',
73
- error: 'Unsupported',
74
- },
75
- });
76
- // Error state replaces the meta line.
77
- expect(queryByText('EXE')).toBeNull();
78
- expect(queryByText('2 MB')).toBeNull();
79
- expect(getByText('Unsupported')).toBeInTheDocument();
80
- });
81
-
82
- test('renders a progress bar when progress is between 0 and 100', () => {
83
- const { container } = render(UiFileItem, {
84
- props: {
85
- filename: 'upload.zip',
86
- progress: 35,
87
- },
88
- });
89
- expect(
90
- container.querySelector('[data-slot="progress"]'),
91
- ).toBeInTheDocument();
92
- });
55
+ // The positive case (a clipped name opening the tooltip) needs real layout
56
+ // and pointer handling, which jsdom does not provide: reka never opens. It is
57
+ // covered by the `TruncatedName` story in
58
+ // `src/patterns/UiFileUpload/UiFileItem.stories.ts`.
93
59
 
94
- test('hides type/size meta while progress is in flight', () => {
95
- const { queryByText } = render(UiFileItem, {
96
- props: {
97
- filename: 'upload.zip',
98
- typeLabel: 'ZIP',
99
- sizeLabel: '12 MB',
100
- progress: 35,
101
- },
60
+ test('leaves dotfile names without extension segment unchanged', () => {
61
+ const { getByText } = render(UiFileItem, {
62
+ props: { filename: '.gitignore' },
102
63
  });
103
- // Meta is replaced by the progress bar; only the title and bar remain.
104
- expect(queryByText('ZIP')).toBeNull();
105
- expect(queryByText('12 MB')).toBeNull();
64
+ expect(getByText('.gitignore')).toBeInTheDocument();
106
65
  });
107
66
 
108
- test('does not emit remove when disabled', async () => {
109
- const user = userEvent.setup();
110
- const { getByRole, emitted } = render(UiFileItem, {
67
+ test('small size tightens the row padding and the title scale', () => {
68
+ const { container, getByLabelText } = render(UiFileItem, {
111
69
  props: {
112
- filename: 'x.txt',
113
- removeLabel: 'Remove file',
114
- disabled: true,
70
+ filename: 'doc.pdf',
71
+ size: 'small',
115
72
  },
116
73
  });
117
- const btn = getByRole('button', { name: 'Remove file' });
118
- expect(btn).toBeDisabled();
119
- await user.click(btn);
120
- expect(emitted('remove')).toBeFalsy();
74
+ expect(container.querySelector('[data-slot="file-item"]')).toHaveClass(
75
+ 'p-2',
76
+ );
77
+ expect(getByLabelText('doc.pdf')).toHaveClass('label-12-medium');
121
78
  });
122
79
 
123
- test('renders a UiFileType badge whose tone matches the filename extension', () => {
124
- const { container } = render(UiFileItem, {
125
- props: { filename: 'data.csv' },
80
+ test('default size keeps the roomier padding and title scale', () => {
81
+ const { container, getByLabelText } = render(UiFileItem, {
82
+ props: { filename: 'doc.pdf' },
126
83
  });
127
- const badge = container.querySelector('[data-slot="file-type"]');
128
- expect(badge?.getAttribute('data-tone')).toBe('accent-yellow');
84
+ expect(container.querySelector('[data-slot="file-item"]')).toHaveClass(
85
+ 'p-3',
86
+ );
87
+ expect(getByLabelText('doc.pdf')).toHaveClass('body-14-medium');
129
88
  });
130
89
  });
@@ -27,9 +27,10 @@ const meta: Meta<typeof UiFileType> = {
27
27
  'accent-pink',
28
28
  'accent-soft',
29
29
  'accent-yellow',
30
+ 'accent-orange',
30
31
  ],
31
32
  description:
32
- 'Color tone override. Leave undefined to auto-derive from the filename extension (pdf/docx/txt → pink, html/md → soft, csv/xls/tsv → yellow).',
33
+ 'Color tone override. Leave undefined to auto-derive from the filename extension (pdf/docx/txt → pink, html/md → soft, csv/xls/tsv → yellow, mp4/mov/webm → orange).',
33
34
  },
34
35
  icon: {
35
36
  control: 'text',
@@ -105,6 +106,7 @@ import { UiFileType } from '@aleph-alpha/ui-library'
105
106
  <UiFileType filename="report.pdf" />
106
107
  <UiFileType filename="README.md" />
107
108
  <UiFileType filename="data.csv" />
109
+ <UiFileType filename="trailer.mp4" />
108
110
  <UiFileType filename="archive.zip" />
109
111
  <UiFileType filename="data.csv" :error="true" />
110
112
  </div>
@@ -126,6 +128,7 @@ export const AllTypes: Story = {
126
128
  <UiFileType filename="report.pdf" />
127
129
  <UiFileType filename="README.md" />
128
130
  <UiFileType filename="data.csv" />
131
+ <UiFileType filename="trailer.mp4" />
129
132
  <UiFileType filename="archive.zip" />
130
133
  <UiFileType filename="data.csv" :error="true" />
131
134
  </div>
@@ -155,12 +158,16 @@ import { UiFileType } from '@aleph-alpha/ui-library'
155
158
  <UiFileType tone="accent-yellow" icon="table-2" />
156
159
  <span class="body-14-regular text-content-on-surface-secondary">accent-yellow</span>
157
160
  </div>
161
+ <div class="flex items-center gap-3">
162
+ <UiFileType tone="accent-orange" icon="image-play" />
163
+ <span class="body-14-regular text-content-on-surface-secondary">accent-orange</span>
164
+ </div>
158
165
  </div>
159
166
  </template>`;
160
167
 
161
168
  /**
162
169
  * Explicit tone overrides for checking the token-backed badge colors,
163
- * including the pink and yellow accent tokens.
170
+ * including the pink, yellow, and orange accent tokens.
164
171
  */
165
172
  export const ToneOverrides: Story = {
166
173
  parameters: {
@@ -187,6 +194,10 @@ export const ToneOverrides: Story = {
187
194
  <UiFileType tone="accent-yellow" icon="table-2" />
188
195
  <span class="body-14-regular text-content-on-surface-secondary">accent-yellow</span>
189
196
  </div>
197
+ <div class="flex items-center gap-3">
198
+ <UiFileType tone="accent-orange" icon="image-play" />
199
+ <span class="body-14-regular text-content-on-surface-secondary">accent-orange</span>
200
+ </div>
190
201
  </div>
191
202
  `,
192
203
  }),
@@ -48,6 +48,13 @@ const FILE_TYPE_PRESETS: Record<string, FileTypePreset> = {
48
48
  tsv: { tone: 'accent-yellow', icon: 'table-2' },
49
49
  xls: { tone: 'accent-yellow', icon: 'table-2' },
50
50
  xlsx: { tone: 'accent-yellow', icon: 'table-2' },
51
+ // Type=Media → accent-orange + image-play icon.
52
+ mp4: { tone: 'accent-orange', icon: 'image-play' },
53
+ m4v: { tone: 'accent-orange', icon: 'image-play' },
54
+ mov: { tone: 'accent-orange', icon: 'image-play' },
55
+ webm: { tone: 'accent-orange', icon: 'image-play' },
56
+ mkv: { tone: 'accent-orange', icon: 'image-play' },
57
+ avi: { tone: 'accent-orange', icon: 'image-play' },
51
58
  };
52
59
 
53
60
  const DEFAULT_PRESET: FileTypePreset = { tone: 'default', icon: 'file' };
@@ -85,6 +92,7 @@ const TONE_FILL: Record<UiFileTypeTone, string> = {
85
92
  'accent-pink': 'bg-background-accent-pink',
86
93
  'accent-soft': 'bg-background-accent-soft',
87
94
  'accent-yellow': 'bg-background-accent-yellow',
95
+ 'accent-orange': 'bg-background-accent-orange',
88
96
  };
89
97
 
90
98
  const badgeClass = computed(() =>
@@ -11,6 +11,16 @@ describe('UiFileType', () => {
11
11
  { filename: 'report.pdf', tone: 'accent-pink', icon: 'lucide-file' },
12
12
  { filename: 'README.md', tone: 'accent-soft', icon: 'lucide-code-xml' },
13
13
  { filename: 'data.csv', tone: 'accent-yellow', icon: 'lucide-table-2' },
14
+ {
15
+ filename: 'trailer.mp4',
16
+ tone: 'accent-orange',
17
+ icon: 'lucide-image-play',
18
+ },
19
+ {
20
+ filename: 'clip.MOV',
21
+ tone: 'accent-orange',
22
+ icon: 'lucide-image-play',
23
+ },
14
24
  { filename: 'archive.zip', tone: 'default', icon: 'lucide-file' },
15
25
  { filename: undefined, tone: 'default', icon: 'lucide-file' },
16
26
  ])('$filename → $tone + $icon', ({ filename, tone, icon }) => {
@@ -6,6 +6,7 @@
6
6
  * - `Type=Text` (`pdf` / `doc` / `docx` / `txt` / `rtf`) → `accent-pink` + `file`
7
7
  * - `Type=Markdown` (`html` / `htm` / `md` / `mdx`) → `accent-soft` + `code-xml`
8
8
  * - `Type=Tabular` (`csv` / `tsv` / `xls` / `xlsx`) → `accent-yellow` + `table-2`
9
+ * - `Type=Media` (`mp4` / `mov` / `webm` / `mkv` / …) → `accent-orange` + `image-play`
9
10
  * - everything else → `default` + `file`
10
11
  * @see {@link https://www.figma.com/design/SrZQ19QVN1sQkuAMnMC746/AA26--WIP-?node-id=26438-42144}
11
12
  * @category Data Display
@@ -17,7 +18,8 @@ export type UiFileTypeTone =
17
18
  | 'default'
18
19
  | 'accent-pink'
19
20
  | 'accent-soft'
20
- | 'accent-yellow';
21
+ | 'accent-yellow'
22
+ | 'accent-orange';
21
23
 
22
24
  export interface UiFileTypeProps {
23
25
  /**
@@ -9,6 +9,7 @@ import UiListboxItem from './UiListboxItem.vue';
9
9
  import UiListboxItemIndicator from './UiListboxItemIndicator.vue';
10
10
  import UiListboxGroup from './UiListboxGroup.vue';
11
11
  import UiListboxGroupLabel from './UiListboxGroupLabel.vue';
12
+ import UiListboxVirtualizer from './UiListboxVirtualizer.vue';
12
13
 
13
14
  /**
14
15
  * UiListbox is a scrollable, single- or multi-select option list with optional filtering and grouping.
@@ -528,6 +529,126 @@ export const Scrollable: Story = {
528
529
  },
529
530
  };
530
531
 
532
+ const virtualizedTemplateSource = `<script setup lang="ts">
533
+ import { ref } from 'vue'
534
+ import {
535
+ UiListbox,
536
+ UiListboxContent,
537
+ UiListboxItem,
538
+ UiListboxItemIndicator,
539
+ UiListboxVirtualizer
540
+ } from '@aleph-alpha/ui-library'
541
+
542
+ const selected = ref('Option 1')
543
+ const options = Array.from({ length: 10000 }, (_, index) => 'Option ' + (index + 1))
544
+ </script>
545
+
546
+ <template>
547
+ <UiListbox v-model="selected" class="w-[220px] p-1">
548
+ <UiListboxContent aria-label="Options">
549
+ <UiListboxVirtualizer v-slot="{ option }" :options="options">
550
+ <UiListboxItem :value="option">
551
+ <span>{{ option }}</span>
552
+ <UiListboxItemIndicator />
553
+ </UiListboxItem>
554
+ </UiListboxVirtualizer>
555
+ </UiListboxContent>
556
+ </UiListbox>
557
+ </template>`;
558
+
559
+ /**
560
+ * `UiListboxVirtualizer` mounts only the options that are in view, so a list of
561
+ * thousands stays as fast as a short one. The scrollbar, keyboard navigation
562
+ * and type-ahead still cover the full list. Pass `textContent` when the options
563
+ * are objects, so type-ahead knows what to match on, and `estimateSize` when an
564
+ * option is not the default 28px tall.
565
+ */
566
+ export const Virtualized: Story = {
567
+ render: () => ({
568
+ components: {
569
+ UiListbox,
570
+ UiListboxContent,
571
+ UiListboxItem,
572
+ UiListboxItemIndicator,
573
+ UiListboxVirtualizer,
574
+ },
575
+ setup() {
576
+ const selected = ref('Option 1');
577
+ const options = Array.from(
578
+ { length: 10000 },
579
+ (_, index) => `Option ${index + 1}`,
580
+ );
581
+ return { selected, options };
582
+ },
583
+ template: `
584
+ <UiListbox v-model="selected" class="w-[220px] p-1">
585
+ <UiListboxContent aria-label="Options">
586
+ <UiListboxVirtualizer v-slot="{ option }" :options="options">
587
+ <UiListboxItem :value="option">
588
+ <span>{{ option }}</span>
589
+ <UiListboxItemIndicator />
590
+ </UiListboxItem>
591
+ </UiListboxVirtualizer>
592
+ </UiListboxContent>
593
+ </UiListbox>
594
+ `,
595
+ }),
596
+ parameters: {
597
+ docs: {
598
+ source: {
599
+ code: virtualizedTemplateSource,
600
+ },
601
+ },
602
+ },
603
+ play: async ({ canvasElement, step }) => {
604
+ // Scenario (List content): a 10,000 option list keeps only the visible
605
+ // options in the DOM, and scrolling swaps in the ones further down while
606
+ // every option keeps its place in the full list.
607
+ const canvas = within(canvasElement);
608
+ const list = canvas.getByRole('listbox', { name: 'Options' });
609
+
610
+ await step(
611
+ 'interaction: only the options in view are in the DOM',
612
+ async () => {
613
+ const rendered = canvas.getAllByRole('option');
614
+ await expect(rendered.length).toBeGreaterThan(0);
615
+ await expect(rendered.length).toBeLessThan(100);
616
+ },
617
+ );
618
+
619
+ await step(
620
+ 'screen-reader: an option announces its place in the full list (WCAG 4.1.2)',
621
+ async () => {
622
+ const first = canvas.getByRole('option', { name: 'Option 1' });
623
+ await expect(first).toHaveAttribute('aria-setsize', '10000');
624
+ await expect(first).toHaveAttribute('aria-posinset', '1');
625
+ },
626
+ );
627
+
628
+ await step(
629
+ 'interaction: scrolling mounts the options further down the list',
630
+ async () => {
631
+ list.scrollTop = list.scrollHeight;
632
+ await waitFor(async () => {
633
+ await expect(
634
+ canvas.getByRole('option', { name: 'Option 10000' }),
635
+ ).toBeVisible();
636
+ });
637
+ await expect(canvas.queryByRole('option', { name: 'Option 1' })).toBe(
638
+ null,
639
+ );
640
+ // Restore the resting state so the visual snapshot stays stable.
641
+ list.scrollTop = 0;
642
+ await waitFor(async () => {
643
+ await expect(
644
+ canvas.getByRole('option', { name: 'Option 1' }),
645
+ ).toBeVisible();
646
+ });
647
+ },
648
+ );
649
+ },
650
+ };
651
+
531
652
  const emptyStateTemplateSource = `<script setup lang="ts">
532
653
  import { ref } from 'vue'
533
654
  import { UiListbox, UiListboxContent } from '@aleph-alpha/ui-library'
@@ -0,0 +1,42 @@
1
+ <script setup lang="ts" generic="T extends AcceptableValue">
2
+ import type { AcceptableValue } from 'reka-ui';
3
+ import { ListboxVirtualizer } from 'reka-ui';
4
+ import {
5
+ type UiListboxVirtualizerProps,
6
+ type UiListboxVirtualizerSlotProps,
7
+ } from './types';
8
+
9
+ /**
10
+ * Unlike the other listbox parts, this one wraps reka-ui directly instead of
11
+ * going through `core/listbox`. reka-ui clones the first node of the slot to
12
+ * position the option and label it with its index, and it looks through a
13
+ * single layer of slot forwarding only, so a second wrapper would leave it
14
+ * cloning an empty fragment.
15
+ */
16
+ defineOptions({
17
+ name: 'UiListboxVirtualizer',
18
+ });
19
+
20
+ const props = defineProps<UiListboxVirtualizerProps<T>>();
21
+
22
+ defineSlots<{
23
+ /** A single option, which has to render exactly one `UiListboxItem`. */
24
+ default(props: UiListboxVirtualizerSlotProps<T>): unknown;
25
+ }>();
26
+ </script>
27
+
28
+ <template>
29
+ <!--
30
+ reka-ui positions each option absolutely, which shrinks it to its content,
31
+ so the options are stretched back to the row width to keep hover and
32
+ selection as wide as in a plain list.
33
+ -->
34
+ <ListboxVirtualizer
35
+ v-slot="{ option, virtualItem }"
36
+ data-slot="listbox-virtualizer"
37
+ class="[&>*]:w-full"
38
+ v-bind="props"
39
+ >
40
+ <slot :option="option" :index="virtualItem.index" />
41
+ </ListboxVirtualizer>
42
+ </template>
@@ -0,0 +1,96 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { afterAll, beforeAll, describe, expect, test } from 'vitest';
3
+ import { nextTick } from 'vue';
4
+ import UiListbox from '../UiListbox.vue';
5
+ import UiListboxContent from '../UiListboxContent.vue';
6
+ import UiListboxItem from '../UiListboxItem.vue';
7
+ import UiListboxVirtualizer from '../UiListboxVirtualizer.vue';
8
+
9
+ const OPTION_COUNT = 500;
10
+ const VIEWPORT_HEIGHT = 300;
11
+
12
+ const options = Array.from({ length: OPTION_COUNT }, (_, index) => ({
13
+ value: `option-${index + 1}`,
14
+ label: `Option ${index + 1}`,
15
+ }));
16
+
17
+ // The virtualizer derives its range from the measured height of the scroll
18
+ // container, and jsdom lays nothing out, so every element reports zero height
19
+ // and no option would ever come into range.
20
+ beforeAll(() => {
21
+ Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
22
+ configurable: true,
23
+ get: () => VIEWPORT_HEIGHT,
24
+ });
25
+ });
26
+
27
+ afterAll(() => {
28
+ Reflect.deleteProperty(HTMLElement.prototype, 'offsetHeight');
29
+ });
30
+
31
+ /**
32
+ * Renders a virtualized listbox over a long option list.
33
+ * @returns The testing-library render result.
34
+ */
35
+ async function renderVirtualizedListbox() {
36
+ const result = render({
37
+ components: {
38
+ UiListbox,
39
+ UiListboxContent,
40
+ UiListboxItem,
41
+ UiListboxVirtualizer,
42
+ },
43
+ setup: () => ({ options }),
44
+ template: `
45
+ <UiListbox model-value="option-1">
46
+ <UiListboxContent aria-label="Options">
47
+ <UiListboxVirtualizer
48
+ v-slot="{ option }"
49
+ :options="options"
50
+ :text-content="(option) => option.label"
51
+ >
52
+ <UiListboxItem :value="option">{{ option.label }}</UiListboxItem>
53
+ </UiListboxVirtualizer>
54
+ </UiListboxContent>
55
+ </UiListbox>
56
+ `,
57
+ });
58
+
59
+ // The scroll container is only measurable once mounted, so the first render
60
+ // still comes out empty.
61
+ await nextTick();
62
+
63
+ return result;
64
+ }
65
+
66
+ describe('UiListboxVirtualizer', () => {
67
+ test('mounts only the options in view instead of the whole list', async () => {
68
+ const { getAllByRole } = await renderVirtualizedListbox();
69
+
70
+ const rendered = getAllByRole('option');
71
+ expect(rendered.length).toBeGreaterThan(0);
72
+ expect(rendered.length).toBeLessThan(OPTION_COUNT);
73
+ });
74
+
75
+ // Only a fraction of the options is in the DOM, so each one has to carry its
76
+ // place in the full list for screen readers to announce it correctly.
77
+ test('announces the position of an option within the full list', async () => {
78
+ const { getAllByRole } = await renderVirtualizedListbox();
79
+
80
+ const [first] = getAllByRole('option');
81
+ expect(first).toHaveAttribute('aria-setsize', String(OPTION_COUNT));
82
+ expect(first).toHaveAttribute('aria-posinset', '1');
83
+ });
84
+
85
+ // The virtualizer positions the options it mounts, and finds them again by
86
+ // index for type-ahead and Home/End, both of which it applies to the option
87
+ // element itself rather than to any wrapper around it.
88
+ test('positions every mounted option and keeps it addressable by index', async () => {
89
+ const { getAllByRole } = await renderVirtualizedListbox();
90
+
91
+ for (const [index, option] of getAllByRole('option').entries()) {
92
+ expect(option).toHaveAttribute('data-index', String(index));
93
+ expect(option.style.position).toBe('absolute');
94
+ }
95
+ });
96
+ });
@@ -3,6 +3,7 @@ export { default as UiListboxContent } from './UiListboxContent.vue';
3
3
  export { default as UiListboxFilter } from './UiListboxFilter.vue';
4
4
  export { default as UiListboxItem } from './UiListboxItem.vue';
5
5
  export { default as UiListboxItemIndicator } from './UiListboxItemIndicator.vue';
6
+ export { default as UiListboxVirtualizer } from './UiListboxVirtualizer.vue';
6
7
  export { default as UiListboxGroup } from './UiListboxGroup.vue';
7
8
  export { default as UiListboxGroupLabel } from './UiListboxGroupLabel.vue';
8
9
  export type * from './types';