@aleph-alpha/ui-library 5.8.0 → 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +8 -7
  2. package/dist/system/__tests__/test-utils.d.ts +24 -0
  3. package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
  4. package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
  5. package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
  6. package/dist/system/components/UiFadeMask/index.d.ts +2 -0
  7. package/dist/system/components/UiFadeMask/types.d.ts +33 -0
  8. package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
  9. package/dist/system/components/UiListbox/index.d.ts +1 -0
  10. package/dist/system/components/UiListbox/types.d.ts +36 -0
  11. package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
  12. package/dist/system/components/UiSelect/index.d.ts +1 -0
  13. package/dist/system/components/UiSelect/types.d.ts +36 -0
  14. package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
  15. package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
  16. package/dist/system/components/index.d.ts +1 -0
  17. package/dist/system/lib.js +22249 -21090
  18. package/dist/system/mobile-device-frame.png +0 -0
  19. package/dist/system/patterns/UiFloatActions/types.d.ts +2 -1
  20. package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
  21. package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
  22. package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
  23. package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
  24. package/dist/system/patterns/index.d.ts +2 -0
  25. package/dist/system/story-sidebar-icons.json +4 -1
  26. package/package.json +2 -1
  27. package/src/__tests__/test-utils.ts +74 -0
  28. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
  29. package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
  30. package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
  31. package/src/components/UiAutocomplete/types.ts +11 -0
  32. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
  33. package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
  34. package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
  35. package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
  36. package/src/components/UiFadeMask/index.ts +6 -0
  37. package/src/components/UiFadeMask/types.ts +35 -0
  38. package/src/components/UiListbox/UiListbox.stories.ts +121 -0
  39. package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
  40. package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
  41. package/src/components/UiListbox/index.ts +1 -0
  42. package/src/components/UiListbox/types.ts +42 -0
  43. package/src/components/UiSelect/UiSelect.stories.ts +109 -1
  44. package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
  45. package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
  46. package/src/components/UiSelect/index.ts +1 -0
  47. package/src/components/UiSelect/types.ts +38 -0
  48. package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
  49. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  50. package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
  51. package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
  52. package/src/components/core/listbox/ListboxItem.vue +1 -1
  53. package/src/components/index.ts +1 -0
  54. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -5
  55. package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -11
  56. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
  57. package/src/patterns/UiFloatActions/types.ts +2 -1
  58. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1064 -0
  59. package/src/patterns/UiProfileCard/index.ts +7 -0
  60. package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
  61. package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
  62. package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
  63. package/src/patterns/UiTopBar/index.ts +2 -0
  64. package/src/patterns/UiTopBar/types.ts +29 -0
  65. package/src/patterns/index.ts +2 -0
@@ -0,0 +1,166 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * UiTopBar is the application top bar shell.
4
+ *
5
+ * It owns layout only — the padded bar, its regions, and the mobile/desktop
6
+ * mode — and never the controls inside it. Pass the logo, sidebar toggle,
7
+ * actions, and profile in as slots, so the bar stays reusable across products
8
+ * that use different controls. The bar belongs to the app's base layer, so it
9
+ * renders on `background.surface.primary` — the same elevation as
10
+ * {@link UiSidebar}.
11
+ *
12
+ * Three regions render by default: a fixed-width leading gutter (`logo` +
13
+ * `sidebar-toggle`) that lines up with the sidebar, and a trailing region
14
+ * (`layout-actions` + `profile`) pinned to the far end. The default slot wraps
15
+ * all of them rather than sitting beside them, so it can replace the layout
16
+ * entirely.
17
+ *
18
+ * Below the `md` breakpoint the bar switches to mobile mode: it drops the fixed
19
+ * gutter width, sets `data-mode="mobile"`, and prefers each slot's `mobile-`
20
+ * counterpart, falling back to the desktop slot when one isn't provided.
21
+ * @component UiTopBar
22
+ * @property {number | string} [leadingWidth=238] -
23
+ * Width of the leading gutter on desktop. Numbers are pixels, strings are raw
24
+ * CSS lengths. Ignored in mobile mode, where the gutter sizes to its content.
25
+ * @property {string} [ariaLabel='Top bar'] -
26
+ * Accessible name for the `banner` landmark.
27
+ * @slot default
28
+ * Wraps the entire bar. Empty by default, which renders the three regions
29
+ * below. Exposes `isMobile` so custom content can branch per mode.
30
+ * @slot logo
31
+ * Product logo or wordmark, at the start of the leading gutter.
32
+ * @slot sidebar-toggle
33
+ * Sidebar toggle, at the end of the leading gutter. Pass `UiSidebarTrigger` when
34
+ * the bar sits inside a `UiSidebarProvider` — it injects that context — or any
35
+ * icon button of your own when it doesn't.
36
+ * @slot layout-actions
37
+ * Trailing controls, before the profile — a `UiFloatActionItems` pill toolbar
38
+ * in the reference design.
39
+ * @slot profile
40
+ * User profile control, at the very end.
41
+ * @slot mobile-logo
42
+ * Replaces `logo` in mobile mode.
43
+ * @slot mobile-sidebar-toggle
44
+ * Replaces `sidebar-toggle` in mobile mode.
45
+ * @slot mobile-layout-actions
46
+ * Replaces `layout-actions` in mobile mode.
47
+ * @slot mobile-profile
48
+ * Replaces `profile` in mobile mode.
49
+ * @example Desktop and mobile controls side by side
50
+ * ```vue
51
+ * <UiTopBar>
52
+ * <template #logo><AppWordmark /></template>
53
+ * <template #sidebar-toggle><UiSidebarTrigger /></template>
54
+ * <template #layout-actions><LayoutSwitch v-model="layout" /></template>
55
+ * <template #profile><UiAvatar :size="8" /></template>
56
+ *
57
+ * <!-- mobile mode swaps in a brand pill and a menu button -->
58
+ * <template #mobile-logo><BrandPill @click="openWorkspaces" /></template>
59
+ * <template #mobile-layout-actions><MenuButton v-model:open="menuOpen" /></template>
60
+ * </UiTopBar>
61
+ * ```
62
+ * @example Composing the bar through the default slot
63
+ * ```vue
64
+ * <UiTopBar v-slot="{ isMobile }">
65
+ * <AppWordmark />
66
+ * <UiBreadcrumb v-if="!isMobile">…</UiBreadcrumb>
67
+ * <UiButton class="ml-auto" variant="ghost">Publish</UiButton>
68
+ * </UiTopBar>
69
+ * ```
70
+ */
71
+ import { useMediaQuery } from '@vueuse/core';
72
+ import { computed, useAttrs, useSlots } from 'vue';
73
+ import { cn, omitClass } from '@/lib/utils';
74
+ import type { UiTopBarProps } from './types';
75
+
76
+ defineOptions({
77
+ name: 'UiTopBar',
78
+ inheritAttrs: false,
79
+ });
80
+
81
+ const props = withDefaults(defineProps<UiTopBarProps>(), {
82
+ leadingWidth: 238,
83
+ ariaLabel: 'Top bar',
84
+ });
85
+
86
+ const attrs = useAttrs();
87
+ const slots = useSlots();
88
+
89
+ // Same query the sidebar uses for its own mobile mode, so the bar and the
90
+ // sidebar beneath it switch modes together.
91
+ const isMobile = useMediaQuery('(max-width: 768px)');
92
+
93
+ /**
94
+ * Resolves the slot to render for a region, preferring the `mobile-` variant in
95
+ * mobile mode and falling back to the desktop slot when it isn't provided.
96
+ * @param name Desktop slot name.
97
+ * @returns Slot name to render.
98
+ */
99
+ function slotName(name: string): string {
100
+ const mobileName = `mobile-${name}`;
101
+ return isMobile.value && slots[mobileName] ? mobileName : name;
102
+ }
103
+
104
+ const logoSlot = computed(() => slotName('logo'));
105
+ const sidebarToggleSlot = computed(() => slotName('sidebar-toggle'));
106
+ const layoutActionsSlot = computed(() => slotName('layout-actions'));
107
+ const profileSlot = computed(() => slotName('profile'));
108
+
109
+ /** `py-2.5` / `px-4` are the scale steps for the specified 10px / 16px padding. */
110
+ const rootClass = computed(() =>
111
+ cn(
112
+ 'flex w-full items-center gap-4 px-4 py-2.5',
113
+ 'bg-background-surface-primary text-content-on-surface-primary',
114
+ attrs.class ?? '',
115
+ ),
116
+ );
117
+
118
+ // The gutter is a fixed width on desktop so the logo lines up with the sidebar
119
+ // beneath it. In mobile mode it sizes to its content instead, since the sidebar
120
+ // is off-canvas and a 238px gutter would push the trailing actions outside a
121
+ // 320px viewport.
122
+ const leadingClass = computed(() =>
123
+ cn(
124
+ 'flex shrink-0 items-center justify-between gap-2',
125
+ !isMobile.value && 'w-[var(--ui-top-bar-leading-width)]',
126
+ ),
127
+ );
128
+
129
+ const leadingStyle = computed(() => ({
130
+ '--ui-top-bar-leading-width':
131
+ typeof props.leadingWidth === 'number'
132
+ ? `${props.leadingWidth}px`
133
+ : props.leadingWidth,
134
+ }));
135
+ </script>
136
+
137
+ <template>
138
+ <header
139
+ data-slot="top-bar"
140
+ :data-mode="isMobile ? 'mobile' : 'desktop'"
141
+ :aria-label="props.ariaLabel"
142
+ :class="rootClass"
143
+ v-bind="omitClass(attrs)"
144
+ >
145
+ <!-- The default slot wraps the whole bar; its fallback is the region
146
+ layout, all of it filled by the consumer. -->
147
+ <slot :is-mobile="isMobile">
148
+ <div
149
+ data-slot="top-bar-leading"
150
+ :class="leadingClass"
151
+ :style="leadingStyle"
152
+ >
153
+ <slot :name="logoSlot" />
154
+ <slot :name="sidebarToggleSlot" />
155
+ </div>
156
+
157
+ <div
158
+ data-slot="top-bar-trailing"
159
+ class="ml-auto flex shrink-0 items-center gap-4"
160
+ >
161
+ <slot :name="layoutActionsSlot" />
162
+ <slot :name="profileSlot" />
163
+ </div>
164
+ </slot>
165
+ </header>
166
+ </template>
@@ -0,0 +1,245 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
3
+ import {
4
+ mockMatchMediaDesktop,
5
+ mockMatchMediaMobile,
6
+ } from '../../UiSidebar/__tests__/sidebar-test-helpers';
7
+ import UiTopBar from '../UiTopBar.vue';
8
+
9
+ const LEADING_WIDTH_CLASS = 'w-[var(--ui-top-bar-leading-width)]';
10
+
11
+ /**
12
+ * Reads a bar region, or `null` when the bar doesn't render it.
13
+ * @param container
14
+ * @param region
15
+ */
16
+ function queryRegion(container: Element, region: string): HTMLElement | null {
17
+ return container.querySelector<HTMLElement>(
18
+ `[data-slot="top-bar-${region}"]`,
19
+ );
20
+ }
21
+
22
+ /**
23
+ * Reads a bar region, failing when it is absent.
24
+ * @param container
25
+ * @param region
26
+ */
27
+ function getRegion(container: Element, region: string): HTMLElement {
28
+ const element = queryRegion(container, region);
29
+ if (!element) throw new Error(`${region} region not rendered`);
30
+ return element;
31
+ }
32
+
33
+ describe('UiTopBar', () => {
34
+ beforeEach(() => {
35
+ mockMatchMediaDesktop();
36
+ });
37
+
38
+ afterEach(() => {
39
+ vi.restoreAllMocks();
40
+ });
41
+
42
+ test('renders a named banner landmark with the tokenized 10px/16px padding', () => {
43
+ const { getByRole } = render(UiTopBar);
44
+
45
+ const banner = getByRole('banner', { name: 'Top bar' });
46
+ expect(banner.tagName).toBe('HEADER');
47
+ expect(banner).toHaveClass('px-4', 'py-2.5');
48
+ expect(banner).toHaveAttribute('data-mode', 'desktop');
49
+ });
50
+
51
+ test('uses a custom landmark name', () => {
52
+ const { getByRole } = render(UiTopBar, {
53
+ props: { ariaLabel: 'Workspace bar' },
54
+ });
55
+
56
+ expect(getByRole('banner', { name: 'Workspace bar' })).toBeInTheDocument();
57
+ });
58
+
59
+ test('ships no controls of its own', () => {
60
+ const { container } = render(UiTopBar);
61
+
62
+ expect(getRegion(container, 'leading').textContent?.trim()).toBe('');
63
+ expect(getRegion(container, 'trailing').textContent?.trim()).toBe('');
64
+ expect(container.querySelectorAll('button')).toHaveLength(0);
65
+ expect(container.querySelectorAll('svg')).toHaveLength(0);
66
+ });
67
+
68
+ test('places the logo and sidebar toggle in the leading region', () => {
69
+ const { container } = render(UiTopBar, {
70
+ slots: {
71
+ logo: '<span>Phoenix</span>',
72
+ 'sidebar-toggle': '<button type="button">Toggle</button>',
73
+ },
74
+ });
75
+
76
+ const leading = getRegion(container, 'leading');
77
+ expect(leading).toHaveTextContent('Phoenix');
78
+ expect(leading.querySelector('button')).toHaveTextContent('Toggle');
79
+ });
80
+
81
+ test('places the layout actions and profile in the trailing region', () => {
82
+ const { container } = render(UiTopBar, {
83
+ slots: {
84
+ 'layout-actions': '<button type="button">Layout</button>',
85
+ profile: '<span>CN</span>',
86
+ },
87
+ });
88
+
89
+ const trailing = getRegion(container, 'trailing');
90
+ expect(trailing.querySelector('button')).toHaveTextContent('Layout');
91
+ expect(trailing).toHaveTextContent('CN');
92
+ });
93
+
94
+ test('treats class as an attribute and forwards other attrs to the root', () => {
95
+ const { getByRole } = render(UiTopBar, {
96
+ attrs: { class: 'border-b', 'data-testid': 'bar', id: 'app-top-bar' },
97
+ });
98
+
99
+ const banner = getByRole('banner');
100
+ expect(banner).toHaveClass('border-b', 'px-4');
101
+ expect(banner).toHaveAttribute('data-testid', 'bar');
102
+ expect(banner).toHaveAttribute('id', 'app-top-bar');
103
+ });
104
+
105
+ describe('default slot', () => {
106
+ test('wraps the bar and replaces both regions', () => {
107
+ const { container, getByText } = render(UiTopBar, {
108
+ slots: { default: '<span>Composed by hand</span>' },
109
+ });
110
+
111
+ expect(getByText('Composed by hand')).toBeInTheDocument();
112
+ expect(queryRegion(container, 'leading')).toBeNull();
113
+ expect(queryRegion(container, 'trailing')).toBeNull();
114
+ });
115
+
116
+ test('keeps the padded banner shell around custom content', () => {
117
+ const { getByRole } = render(UiTopBar, {
118
+ slots: { default: '<span>Composed by hand</span>' },
119
+ });
120
+
121
+ expect(getByRole('banner', { name: 'Top bar' })).toHaveClass(
122
+ 'px-4',
123
+ 'py-2.5',
124
+ );
125
+ });
126
+
127
+ test('exposes the current mode to custom content', () => {
128
+ const { getByTestId } = render({
129
+ components: { UiTopBar },
130
+ template: `
131
+ <UiTopBar v-slot="{ isMobile }">
132
+ <span data-testid="mode">{{ isMobile ? 'mobile' : 'desktop' }}</span>
133
+ </UiTopBar>
134
+ `,
135
+ });
136
+
137
+ expect(getByTestId('mode')).toHaveTextContent('desktop');
138
+ });
139
+ });
140
+
141
+ describe('leading gutter', () => {
142
+ test('defaults to 238px and accepts a number or CSS length', () => {
143
+ const { container: byDefault } = render(UiTopBar);
144
+ expect(
145
+ getRegion(byDefault, 'leading').style.getPropertyValue(
146
+ '--ui-top-bar-leading-width',
147
+ ),
148
+ ).toBe('238px');
149
+
150
+ const { container: byNumber } = render(UiTopBar, {
151
+ props: { leadingWidth: 160 },
152
+ });
153
+ expect(
154
+ getRegion(byNumber, 'leading').style.getPropertyValue(
155
+ '--ui-top-bar-leading-width',
156
+ ),
157
+ ).toBe('160px');
158
+
159
+ const { container: byLength } = render(UiTopBar, {
160
+ props: { leadingWidth: 'var(--sidebar-width)' },
161
+ });
162
+ expect(
163
+ getRegion(byLength, 'leading').style.getPropertyValue(
164
+ '--ui-top-bar-leading-width',
165
+ ),
166
+ ).toBe('var(--sidebar-width)');
167
+ });
168
+
169
+ test('applies the fixed width in desktop mode', () => {
170
+ const { container } = render(UiTopBar);
171
+
172
+ expect(getRegion(container, 'leading')).toHaveClass(LEADING_WIDTH_CLASS);
173
+ });
174
+ });
175
+
176
+ describe('mobile mode', () => {
177
+ beforeEach(() => {
178
+ mockMatchMediaMobile();
179
+ });
180
+
181
+ test('marks the bar as mobile and drops the fixed gutter width', () => {
182
+ const { container, getByRole } = render(UiTopBar);
183
+
184
+ expect(getByRole('banner')).toHaveAttribute('data-mode', 'mobile');
185
+ expect(getRegion(container, 'leading')).not.toHaveClass(
186
+ LEADING_WIDTH_CLASS,
187
+ );
188
+ });
189
+
190
+ test('prefers each mobile slot variant over its desktop counterpart', () => {
191
+ const { getByText, queryByText } = render(UiTopBar, {
192
+ slots: {
193
+ logo: '<span>Phoenix</span>',
194
+ 'mobile-logo': '<span>Phoenix 1.2</span>',
195
+ 'layout-actions': '<span>Layout switch</span>',
196
+ 'mobile-layout-actions': '<span>Menu</span>',
197
+ },
198
+ });
199
+
200
+ expect(getByText('Phoenix 1.2')).toBeInTheDocument();
201
+ expect(getByText('Menu')).toBeInTheDocument();
202
+ expect(queryByText('Phoenix')).not.toBeInTheDocument();
203
+ expect(queryByText('Layout switch')).not.toBeInTheDocument();
204
+ });
205
+
206
+ test('falls back to the desktop slot when no mobile variant is given', () => {
207
+ const { getByText } = render(UiTopBar, {
208
+ slots: {
209
+ logo: '<span>Phoenix</span>',
210
+ profile: '<span>CN</span>',
211
+ },
212
+ });
213
+
214
+ expect(getByText('Phoenix')).toBeInTheDocument();
215
+ expect(getByText('CN')).toBeInTheDocument();
216
+ });
217
+
218
+ test('supports mobile variants for the toggle and profile regions', () => {
219
+ const { container } = render(UiTopBar, {
220
+ slots: {
221
+ 'mobile-sidebar-toggle': '<button type="button">Nav</button>',
222
+ 'mobile-profile': '<span>Me</span>',
223
+ },
224
+ });
225
+
226
+ expect(
227
+ getRegion(container, 'leading').querySelector('button'),
228
+ ).toHaveTextContent('Nav');
229
+ expect(getRegion(container, 'trailing')).toHaveTextContent('Me');
230
+ });
231
+
232
+ test('exposes mobile mode to default slot content', () => {
233
+ const { getByTestId } = render({
234
+ components: { UiTopBar },
235
+ template: `
236
+ <UiTopBar v-slot="{ isMobile }">
237
+ <span data-testid="mode">{{ isMobile ? 'mobile' : 'desktop' }}</span>
238
+ </UiTopBar>
239
+ `,
240
+ });
241
+
242
+ expect(getByTestId('mode')).toHaveTextContent('mobile');
243
+ });
244
+ });
245
+ });
@@ -0,0 +1,2 @@
1
+ export { default as UiTopBar } from './UiTopBar.vue';
2
+ export * from './types';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Application top bar shell. Owns the padded bar, its leading gutter and
3
+ * trailing region, and the mobile/desktop mode — the controls themselves are
4
+ * passed in as slots, each with a `mobile-` counterpart. The default slot wraps
5
+ * the whole layout so it can be replaced outright.
6
+ * @category Patterns
7
+ * @useCases app shell header, dashboard top bar, workspace chrome, banner landmark
8
+ * @keywords topbar, top bar, header, banner, app shell, chrome, layout, responsive
9
+ * @related UiSidebar, UiSidebarTrigger, UiFloatActionItems, UiAvatar
10
+ */
11
+ export interface UiTopBarProps {
12
+ /**
13
+ * Width of the leading gutter that holds the `logo` and `sidebar-toggle`
14
+ * slots. Numbers are pixels; strings pass through as a raw CSS length, so the
15
+ * gutter can track a resizable sidebar (for example `'var(--sidebar-width)'`).
16
+ *
17
+ * Desktop mode only. In mobile mode the gutter sizes to its content, since
18
+ * the sidebar is off-canvas and a fixed gutter would push the trailing
19
+ * actions outside a 320px viewport.
20
+ * @default 238
21
+ */
22
+ leadingWidth?: number | string;
23
+
24
+ /**
25
+ * Accessible name for the top bar's `banner` landmark.
26
+ * @default 'Top bar'
27
+ */
28
+ ariaLabel?: string;
29
+ }
@@ -7,4 +7,6 @@ export * from './UiDatePicker';
7
7
  export * from './UiFileUpload';
8
8
  export * from './UiFloatActions';
9
9
  export * from './UiPlaceholder';
10
+ export * from './UiProfileCard';
10
11
  export * from './UiSidebar';
12
+ export * from './UiTopBar';