@aleph-alpha/ui-library 5.3.1 → 5.5.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 (109) hide show
  1. package/config.d.ts +38 -3
  2. package/config.js +103 -6
  3. package/dist/system/lib.js +8926 -8768
  4. package/dist/system/patterns/UiDataTable/UiDataTableFilterMenu.vue.d.ts +24 -0
  5. package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
  6. package/dist/system/patterns/UiDataTable/index.d.ts +1 -0
  7. package/dist/system/patterns/UiDataTable/types.d.ts +23 -1
  8. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
  9. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
  10. package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
  11. package/dist/system/story-sidebar-icons.json +5 -1
  12. package/docs/public-docs/getting-started-designers.md +3 -1
  13. package/package.json +5 -3
  14. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +2 -1
  15. package/src/components/UiAutocomplete/UiAutocomplete.vue +5 -5
  16. package/src/components/UiButton/UiButton.stories.ts +14 -14
  17. package/src/components/UiCheckbox/UiCheckbox.stories.ts +260 -9
  18. package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
  19. package/src/components/UiChip/UiChip.vue +1 -1
  20. package/src/components/UiDrawer/UiDrawer.stories.ts +2 -2
  21. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +4 -4
  22. package/src/components/UiEmpty/UiEmpty.vue +2 -2
  23. package/src/components/UiField/UiField.stories.ts +610 -3
  24. package/src/components/UiField/UiFieldDescription.vue +7 -2
  25. package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
  26. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +2 -2
  27. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +2 -2
  28. package/src/components/UiInput/UiInput.stories.ts +336 -2
  29. package/src/components/UiInput/UiInput.vue +3 -3
  30. package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
  31. package/src/components/UiItem/UiItem.stories.ts +236 -1
  32. package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
  33. package/src/components/UiKbd/UiKbd.stories.ts +14 -14
  34. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +42 -42
  35. package/src/components/UiPopover/UiPopover.stories.ts +6 -6
  36. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +2 -2
  37. package/src/components/UiResizable/UiResizable.stories.ts +6 -5
  38. package/src/components/UiSeparator/UiSeparator.stories.ts +6 -6
  39. package/src/components/UiSheet/UiSheet.stories.ts +2 -2
  40. package/src/components/UiSlider/UiSlider.stories.ts +8 -8
  41. package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
  42. package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
  43. package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
  44. package/src/components/UiSpinner/UiSpinner.stories.ts +8 -8
  45. package/src/components/UiSwitch/UiSwitch.stories.ts +2 -2
  46. package/src/components/UiTabs/UiTabs.stories.ts +30 -30
  47. package/src/components/UiToggle/__tests__/UiToggle.test.ts +5 -3
  48. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +9 -9
  49. package/src/components/UiTooltip/UiTooltip.stories.ts +3 -3
  50. package/src/components/core/accordion/AccordionTrigger.vue +2 -2
  51. package/src/components/core/alert/AlertDescription.vue +1 -1
  52. package/src/components/core/badge/index.ts +1 -1
  53. package/src/components/core/button/index.ts +2 -2
  54. package/src/components/core/calendar/CalendarCellTrigger.vue +2 -2
  55. package/src/components/core/calendar/CalendarHeadCell.vue +1 -1
  56. package/src/components/core/card/CardDescription.vue +1 -1
  57. package/src/components/core/checkbox/Checkbox.vue +1 -2
  58. package/src/components/core/drawer/DrawerDescription.vue +1 -1
  59. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  60. package/src/components/core/dropdown-menu/DropdownMenuShortcut.vue +1 -1
  61. package/src/components/core/field/FieldDescription.vue +1 -1
  62. package/src/components/core/field/FieldLabel.vue +1 -1
  63. package/src/components/core/field/FieldSeparator.vue +1 -1
  64. package/src/components/core/input/Input.vue +2 -2
  65. package/src/components/core/item/index.ts +1 -1
  66. package/src/components/core/kbd/Kbd.vue +1 -1
  67. package/src/components/core/listbox/ListboxFilter.vue +1 -1
  68. package/src/components/core/listbox/ListboxGroupLabel.vue +4 -1
  69. package/src/components/core/listbox/ListboxItem.vue +1 -1
  70. package/src/components/core/native-select/NativeSelect.vue +3 -3
  71. package/src/components/core/navigation-menu/NavigationMenuLink.vue +1 -1
  72. package/src/components/core/navigation-menu/index.ts +1 -1
  73. package/src/components/core/radio-group/RadioGroupItem.vue +1 -1
  74. package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +2 -2
  75. package/src/components/core/range-calendar/RangeCalendarHeadCell.vue +1 -1
  76. package/src/components/core/select/SelectItem.vue +1 -1
  77. package/src/components/core/select/SelectLabel.vue +4 -1
  78. package/src/components/core/select/SelectTrigger.vue +1 -1
  79. package/src/components/core/sheet/SheetDescription.vue +3 -1
  80. package/src/components/core/switch/Switch.vue +1 -1
  81. package/src/components/core/table/TableCaption.vue +3 -1
  82. package/src/components/core/tabs/TabsList.vue +1 -1
  83. package/src/components/core/tabs/TabsTrigger.vue +1 -1
  84. package/src/components/core/tags-input/TagsInput.vue +1 -1
  85. package/src/components/core/tags-input/TagsInputInput.vue +1 -1
  86. package/src/components/core/tags-input/TagsInputItemDelete.vue +1 -1
  87. package/src/components/core/textarea/Textarea.vue +1 -1
  88. package/src/components/core/toggle/index.ts +3 -3
  89. package/src/components/core/toggle-group/index.ts +2 -2
  90. package/src/lib/useDrag.stories.ts +8 -8
  91. package/src/patterns/UiDataTable/UiDataTable.stories.ts +913 -16
  92. package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
  93. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +91 -0
  94. package/src/patterns/UiDataTable/UiDataTablePagination.vue +1 -1
  95. package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
  96. package/src/patterns/UiDataTable/constants.ts +12 -0
  97. package/src/patterns/UiDataTable/index.ts +1 -0
  98. package/src/patterns/UiDataTable/types.ts +24 -0
  99. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +4 -4
  100. package/src/patterns/UiDatePicker/UiDatePicker.vue +1 -1
  101. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +140 -12
  102. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +1231 -438
  103. package/src/patterns/UiFloatActions/UiFloatActions.vue +1 -1
  104. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
  105. package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
  106. package/src/patterns/UiFloatActions/types.ts +28 -1
  107. package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +2 -2
  108. package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
  109. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
@@ -45,7 +45,9 @@ import { cn, omitClass } from '@/lib/utils';
45
45
  import {
46
46
  computed,
47
47
  inject,
48
+ nextTick,
48
49
  onBeforeUnmount,
50
+ onMounted,
49
51
  provide,
50
52
  ref,
51
53
  useAttrs,
@@ -55,8 +57,10 @@ import {
55
57
  FLOAT_ACTION_ITEM_SELECTOR,
56
58
  FLOAT_ACTION_ITEM_CONTEXT,
57
59
  type FloatActionItemContext,
60
+ type FloatActionItemRegistration,
58
61
  } from './floatActionItemContext';
59
62
  import type { UiFloatActionItemsEmits, UiFloatActionItemsProps } from './types';
63
+ import UiInput from '@/components/UiInput/UiInput.vue';
60
64
 
61
65
  defineOptions({
62
66
  name: 'UiFloatActionItems',
@@ -69,6 +73,8 @@ const props = withDefaults(defineProps<UiFloatActionItemsProps>(), {
69
73
  orientation: 'horizontal',
70
74
  ariaLabel: undefined,
71
75
  placeholder: undefined,
76
+ modelValue: undefined,
77
+ value: undefined,
72
78
  });
73
79
 
74
80
  const emit = defineEmits<UiFloatActionItemsEmits>();
@@ -91,13 +97,25 @@ const isGroup = computed(() => props.type === 'group');
91
97
  const isSeparator = computed(() => props.type === 'separator');
92
98
 
93
99
  const activeIndex = ref(0);
94
- const registeredItems = ref<Array<{ id: symbol }>>([]);
100
+ type RegisteredItem = FloatActionItemRegistration & {
101
+ /** Unique id used for roving-tabindex bookkeeping. */
102
+ id: symbol;
103
+ };
104
+ const registeredItems = ref<RegisteredItem[]>([]);
95
105
 
96
106
  const toolbarOrientation = computed(() => props.orientation ?? 'horizontal');
97
107
 
108
+ // A toolbar becomes a single-select control when `v-model` is bound. We can't
109
+ // distinguish an unbound prop from an explicit `undefined`, so presence of a
110
+ // non-undefined `modelValue` opts into the indicator behaviour.
111
+ const hasModel = computed(
112
+ () => isToolbar.value && props.modelValue !== undefined,
113
+ );
114
+ const modelValueRef = computed(() => props.modelValue);
115
+
98
116
  const toolbarContext: FloatActionItemContext = {
99
- registerItem(id) {
100
- registeredItems.value.push({ id });
117
+ registerItem(id, registration) {
118
+ registeredItems.value.push({ id, ...registration });
101
119
  },
102
120
  unregisterItem(id) {
103
121
  registeredItems.value = registeredItems.value.filter(
@@ -114,18 +132,96 @@ const toolbarContext: FloatActionItemContext = {
114
132
  return index === activeIndex.value ? 0 : -1;
115
133
  },
116
134
  orientation: toolbarOrientation,
135
+ hasModel,
136
+ modelValue: modelValueRef,
137
+ select(value) {
138
+ emit('update:modelValue', value);
139
+ },
117
140
  };
118
141
 
142
+ const inputName = computed(
143
+ () => (attrs.name as string) ?? `float-action-input-${itemId.toString()}`,
144
+ );
145
+
119
146
  if (isToolbar.value) {
120
147
  provide(FLOAT_ACTION_ITEM_CONTEXT, toolbarContext);
121
148
  }
122
149
 
150
+ // Sliding background indicator: an absolutely-positioned layer inside the
151
+ // toolbar that tracks the active (selected) item's box so it appears to move
152
+ // between items as the selection changes.
153
+ const indicatorStyle = ref<Record<string, string>>({ opacity: '0' });
154
+ const indicatorReady = ref(false);
155
+ let resizeObserver: ResizeObserver | null = null;
156
+
157
+ function updateIndicator() {
158
+ if (!isToolbar.value || !hasModel.value) {
159
+ indicatorStyle.value = { opacity: '0' };
160
+ return;
161
+ }
162
+
163
+ const root = itemRef.value;
164
+ const activeEl = registeredItems.value
165
+ .find(
166
+ (item) => item.value() !== undefined && item.value() === props.modelValue,
167
+ )
168
+ ?.el();
169
+
170
+ if (!root || !activeEl) {
171
+ indicatorStyle.value = { opacity: '0' };
172
+ return;
173
+ }
174
+
175
+ indicatorStyle.value = {
176
+ opacity: '1',
177
+ width: `${activeEl.offsetWidth}px`,
178
+ height: `${activeEl.offsetHeight}px`,
179
+ transform: `translate(${activeEl.offsetLeft}px, ${activeEl.offsetTop}px)`,
180
+ };
181
+
182
+ if (!indicatorReady.value && typeof requestAnimationFrame === 'function') {
183
+ // Position once without a transition, then enable animation so future
184
+ // selections slide instead of jumping in from the top-left corner.
185
+ requestAnimationFrame(() => {
186
+ indicatorReady.value = true;
187
+ });
188
+ }
189
+ }
190
+
191
+ function scheduleIndicatorUpdate() {
192
+ void nextTick(updateIndicator);
193
+ }
194
+
195
+ if (isToolbar.value) {
196
+ watch(
197
+ [() => props.modelValue, hasModel, registeredItems],
198
+ scheduleIndicatorUpdate,
199
+ { deep: true },
200
+ );
201
+
202
+ onMounted(() => {
203
+ scheduleIndicatorUpdate();
204
+ if (typeof ResizeObserver !== 'undefined' && itemRef.value) {
205
+ resizeObserver = new ResizeObserver(() => updateIndicator());
206
+ resizeObserver.observe(itemRef.value);
207
+ }
208
+ });
209
+
210
+ onBeforeUnmount(() => {
211
+ resizeObserver?.disconnect();
212
+ resizeObserver = null;
213
+ });
214
+ }
215
+
123
216
  watch(
124
217
  itemRef,
125
218
  (element) => {
126
219
  if (!parentContext || (!isButton.value && !isInput.value)) return;
127
220
  if (element) {
128
- parentContext.registerItem(itemId);
221
+ parentContext.registerItem(itemId, {
222
+ el: () => itemRef.value,
223
+ value: () => props.value,
224
+ });
129
225
  return;
130
226
  }
131
227
  parentContext.unregisterItem(itemId);
@@ -133,6 +229,17 @@ watch(
133
229
  { immediate: true },
134
230
  );
135
231
 
232
+ // Selectable buttons opt in by declaring a `value` inside a `v-model` toolbar.
233
+ const isSelectable = computed(
234
+ () =>
235
+ isButton.value &&
236
+ parentContext?.hasModel.value === true &&
237
+ props.value !== undefined,
238
+ );
239
+ const isActive = computed(
240
+ () => isSelectable.value && parentContext?.modelValue.value === props.value,
241
+ );
242
+
136
243
  onBeforeUnmount(() => {
137
244
  parentContext?.unregisterItem(itemId);
138
245
  });
@@ -208,6 +315,9 @@ function onButtonClick(event: MouseEvent) {
208
315
  event.preventDefault();
209
316
  return;
210
317
  }
318
+ if (isSelectable.value && props.value !== undefined) {
319
+ parentContext?.select(props.value);
320
+ }
211
321
  emit('click', event);
212
322
  }
213
323
 
@@ -222,28 +332,37 @@ const forwardedAttrs = computed(() => omitClass(attrs));
222
332
 
223
333
  const toolbarClass = computed(() =>
224
334
  cn(
225
- 'inline-flex items-center gap-0.5 rounded-full border border-border-surface-default bg-background-surface-floating p-1 shadow-xs',
335
+ 'relative inline-flex items-center gap-0.5 rounded-xl-2xl border border-border-surface-default bg-background-surface-floating p-1 shadow-xs',
336
+ props.orientation === 'vertical' && 'flex-col',
226
337
  attrs.class ?? '',
227
338
  ),
228
339
  );
229
340
 
230
- const buttonClass = computed(() =>
341
+ // The active indicator sits behind the items (first child, no z-index) and
342
+ // slides between them; `bg-background-surface-muted` mirrors the previous hover
343
+ // surface so the selected item reads as highlighted.
344
+ const indicatorClass = computed(() =>
231
345
  cn(
232
- 'inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent text-content-on-surface-primary transition-colors hover:bg-background-surface-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-surface-focus-ring disabled:cursor-not-allowed disabled:opacity-50',
233
- attrs.class ?? '',
346
+ 'pointer-events-none absolute left-0 top-0 rounded-full bg-background-surface-muted',
347
+ indicatorReady.value &&
348
+ 'transition-[transform,width,height] duration-200 ease-out motion-reduce:transition-none',
234
349
  ),
235
350
  );
236
351
 
237
- const inputClass = computed(() =>
352
+ const buttonClass = computed(() =>
238
353
  cn(
239
- 'h-8 min-w-16 rounded-full border-0 bg-background-input-default px-3 label-14-regular text-content-on-surface-primary outline-none focus-visible:ring-2 focus-visible:ring-border-surface-focus-ring',
354
+ 'ui-focus-ring relative inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full border border-transparent bg-transparent text-content-on-surface-muted focus-visible:text-content-on-surface-primary hover:text-content-on-surface-primary transition-colors disabled:cursor-not-allowed disabled:opacity-50 aria-pressed:text-content-on-surface-primary',
240
355
  attrs.class ?? '',
241
356
  ),
242
357
  );
243
358
 
359
+ const inputClass = computed(() =>
360
+ cn('h-8 min-w-16 label-14-regular', attrs.class ?? ''),
361
+ );
362
+
244
363
  const textClass = computed(() =>
245
364
  cn(
246
- 'inline-flex h-8 min-w-8 items-center justify-center px-1 label-14-regular text-content-on-surface-primary',
365
+ 'inline-flex h-8 min-w-8 items-center justify-center px-1 label-14-regular text-content-on-surface-muted focus:text-content-on-surface-primary hover:text-content-on-surface-primary',
247
366
  attrs.class ?? '',
248
367
  ),
249
368
  );
@@ -272,6 +391,13 @@ const separatorClass = computed(() =>
272
391
  :class="toolbarClass"
273
392
  @keydown="onToolbarKeydown"
274
393
  >
394
+ <span
395
+ v-if="hasModel"
396
+ aria-hidden="true"
397
+ data-slot="float-item-indicator"
398
+ :class="indicatorClass"
399
+ :style="indicatorStyle"
400
+ />
275
401
  <slot />
276
402
  </div>
277
403
 
@@ -282,6 +408,7 @@ const separatorClass = computed(() =>
282
408
  type="button"
283
409
  data-slot="float-item-action"
284
410
  :aria-label="props.ariaLabel"
411
+ :aria-pressed="isSelectable ? isActive : undefined"
285
412
  :disabled="props.disabled"
286
413
  :tabindex="tabIndex"
287
414
  :class="buttonClass"
@@ -291,7 +418,7 @@ const separatorClass = computed(() =>
291
418
  <slot />
292
419
  </button>
293
420
 
294
- <input
421
+ <UiInput
295
422
  v-else-if="isInput"
296
423
  ref="itemRef"
297
424
  data-slot="float-item-action"
@@ -301,6 +428,7 @@ const separatorClass = computed(() =>
301
428
  :disabled="props.disabled"
302
429
  :tabindex="tabIndex"
303
430
  :class="inputClass"
431
+ :name="inputName"
304
432
  @focus="onItemFocus"
305
433
  />
306
434