@aleph-alpha/ui-library 6.3.4 → 6.4.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 (61) hide show
  1. package/config.js +2 -1
  2. package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
  3. package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
  4. package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
  5. package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
  6. package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
  7. package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
  8. package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
  9. package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
  10. package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
  11. package/dist/system/components/UiToggle/types.d.ts +10 -2
  12. package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
  13. package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
  14. package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
  15. package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
  16. package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
  17. package/dist/system/components/core/toggle/index.d.ts +47 -2
  18. package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
  19. package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
  20. package/dist/system/components/core/toggle-group/context.d.ts +1 -0
  21. package/dist/system/components/core/toggle-group/index.d.ts +10 -2
  22. package/dist/system/lib.js +12660 -12479
  23. package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
  24. package/dist/system/patterns/UiLayout/layout-shell.d.ts +171 -12
  25. package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
  26. package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +9 -4
  27. package/package.json +2 -2
  28. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
  29. package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
  30. package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
  31. package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
  32. package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
  33. package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
  34. package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
  35. package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
  36. package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
  37. package/src/components/UiDropdownMenu/types.ts +3 -0
  38. package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
  39. package/src/components/UiSnackbar/UiSnackbar.stories.ts +104 -32
  40. package/src/components/UiToggle/UiToggle.stories.ts +386 -261
  41. package/src/components/UiToggle/UiToggle.vue +2 -0
  42. package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
  43. package/src/components/UiToggle/types.ts +10 -2
  44. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
  45. package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
  46. package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
  47. package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
  48. package/src/components/UiToggleGroup/types.ts +12 -2
  49. package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
  50. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  51. package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
  52. package/src/components/core/toggle/Toggle.vue +12 -5
  53. package/src/components/core/toggle/index.ts +47 -19
  54. package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
  55. package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
  56. package/src/components/core/toggle-group/context.ts +1 -0
  57. package/src/components/core/toggle-group/index.ts +10 -24
  58. package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
  59. package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
  60. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
  61. package/src/patterns/UiTopBar/accessory-dropdown.ts +5 -3
@@ -0,0 +1,163 @@
1
+ import { onBeforeUnmount, onMounted } from 'vue';
2
+ import {
3
+ DROPDOWN_MENU_MOBILE_MEDIA,
4
+ DROPDOWN_MENU_SUBMENU_GAP_PX,
5
+ } from './menu-metrics';
6
+ import { placeMobileSubmenu } from './placeMobileSubmenu';
7
+
8
+ /**
9
+ * The row that opened the submenu, which labels the submenu panel.
10
+ * @param content The submenu panel.
11
+ * @returns The trigger row, or null when the panel is not labelled.
12
+ */
13
+ function submenuTrigger(content: HTMLElement) {
14
+ const labelId = content.getAttribute('aria-labelledby');
15
+ return labelId ? document.getElementById(labelId) : null;
16
+ }
17
+
18
+ /** Caps the submenu's scroll area so the panel ends at the viewport edge. */
19
+ const SCROLL_MAX_HEIGHT_VAR = '--ui-dropdown-submenu-scroll-max-height';
20
+
21
+ /**
22
+ * The panel's vertical padding and borders: the part of its height that stays
23
+ * when the scroll area inside has to shrink.
24
+ * @param content The submenu panel.
25
+ */
26
+ function verticalChrome(content: HTMLElement) {
27
+ const style = getComputedStyle(content);
28
+ return (
29
+ (Number.parseFloat(style.paddingTop) || 0) +
30
+ (Number.parseFloat(style.paddingBottom) || 0) +
31
+ (Number.parseFloat(style.borderTopWidth) || 0) +
32
+ (Number.parseFloat(style.borderBottomWidth) || 0)
33
+ );
34
+ }
35
+
36
+ /**
37
+ * Measures where an open submenu goes on a narrow screen and hands the result
38
+ * to the stylesheet.
39
+ *
40
+ * The panel gets `--ui-dropdown-submenu-top|left|width` and `data-mobile-side`
41
+ * (plus `--ui-dropdown-submenu-scroll-max-height` and `data-mobile-clamped`
42
+ * when the chosen side is too short for the whole panel), and the trigger row
43
+ * gets `data-mobile-submenu-side`; the CSS in
44
+ * `UiDropdownMenuSubContent` turns those into a fixed position and neutralises
45
+ * the side placement reka-ui writes to its wrapper. Keeping the override in
46
+ * the stylesheet means nothing here has to be reapplied when reka-ui
47
+ * repositions.
48
+ * @param getContent The open submenu panel, once it is in the document.
49
+ */
50
+ export function useMobileSubmenuPlacement(
51
+ getContent: () => HTMLElement | null,
52
+ ) {
53
+ let placedTrigger: HTMLElement | null = null;
54
+
55
+ /**
56
+ * Drops the side marker from the row that last opened the submenu.
57
+ */
58
+ function clear() {
59
+ if (placedTrigger) {
60
+ delete placedTrigger.dataset.mobileSubmenuSide;
61
+ placedTrigger.style.removeProperty('--ui-dropdown-submenu-gap');
62
+ }
63
+ placedTrigger = null;
64
+ }
65
+
66
+ /**
67
+ * Measures the trigger row and parent panel, and writes the placement.
68
+ */
69
+ function apply() {
70
+ const content = getContent();
71
+ if (!content?.isConnected) {
72
+ return;
73
+ }
74
+ if (!window.matchMedia?.(DROPDOWN_MENU_MOBILE_MEDIA).matches) {
75
+ return;
76
+ }
77
+
78
+ const trigger = submenuTrigger(content);
79
+ const parent = trigger?.closest<HTMLElement>('[role="menu"]');
80
+ if (!trigger || !parent) {
81
+ return;
82
+ }
83
+
84
+ const triggerRect = trigger.getBoundingClientRect();
85
+ const parentRect = parent.getBoundingClientRect();
86
+ // Measure the panel at its natural height, so a cap written on an earlier
87
+ // pass does not stick once there is room again. Layout height, not the
88
+ // bounding box: the panel is scaled while it animates in.
89
+ content.style.removeProperty(SCROLL_MAX_HEIGHT_VAR);
90
+ delete content.dataset.mobileClamped;
91
+ const submenuHeight =
92
+ content.offsetHeight || content.getBoundingClientRect().height;
93
+ if (parentRect.width === 0 || submenuHeight === 0) {
94
+ return;
95
+ }
96
+
97
+ const placement = placeMobileSubmenu({
98
+ trigger: triggerRect,
99
+ parent: parentRect,
100
+ submenuHeight,
101
+ chrome: verticalChrome(content),
102
+ viewportHeight: window.innerHeight,
103
+ });
104
+
105
+ if (placement.scrollMaxHeight !== null) {
106
+ content.style.setProperty(
107
+ SCROLL_MAX_HEIGHT_VAR,
108
+ `${placement.scrollMaxHeight}px`,
109
+ );
110
+ content.dataset.mobileClamped = '';
111
+ }
112
+ content.style.setProperty(
113
+ '--ui-dropdown-submenu-top',
114
+ `${placement.top}px`,
115
+ );
116
+ content.style.setProperty(
117
+ '--ui-dropdown-submenu-left',
118
+ `${placement.left}px`,
119
+ );
120
+ content.style.setProperty(
121
+ '--ui-dropdown-submenu-width',
122
+ `${placement.width}px`,
123
+ );
124
+ content.dataset.mobileSide = placement.side;
125
+
126
+ // The row carries the side and gap too, so its hit area can be extended
127
+ // across the gap toward the submenu.
128
+ if (placedTrigger !== trigger) {
129
+ clear();
130
+ placedTrigger = trigger;
131
+ }
132
+ trigger.dataset.mobileSubmenuSide = placement.side;
133
+ trigger.style.setProperty(
134
+ '--ui-dropdown-submenu-gap',
135
+ `${DROPDOWN_MENU_SUBMENU_GAP_PX}px`,
136
+ );
137
+ }
138
+
139
+ let media: MediaQueryList | undefined;
140
+
141
+ onMounted(() => {
142
+ media = window.matchMedia?.(DROPDOWN_MENU_MOBILE_MEDIA);
143
+ media?.addEventListener('change', apply);
144
+ window.addEventListener('resize', apply);
145
+ // The trigger row moves when the parent list scrolls, and settles once
146
+ // the parent panel has finished animating open.
147
+ document.addEventListener('scroll', apply, {
148
+ capture: true,
149
+ passive: true,
150
+ });
151
+ document.addEventListener('animationend', apply, { capture: true });
152
+ });
153
+
154
+ onBeforeUnmount(() => {
155
+ media?.removeEventListener('change', apply);
156
+ window.removeEventListener('resize', apply);
157
+ document.removeEventListener('scroll', apply, { capture: true });
158
+ document.removeEventListener('animationend', apply, { capture: true });
159
+ clear();
160
+ });
161
+
162
+ return { apply, clear };
163
+ }
@@ -345,30 +345,6 @@ export const IconModes: Story = {
345
345
 
346
346
  type ShowSnackbarStoryOptions = Parameters<typeof showSnackbar>[0];
347
347
 
348
- /**
349
- * Builds the docs source for an individual state story: one trigger opening a
350
- * single snackbar with the given options.
351
- * @param optionsSource Extra `showSnackbar` option lines after the title.
352
- * @param toasterAttrs Extra attributes rendered on the `UiSnackbar` toaster.
353
- */
354
- function stateTemplateSource(optionsSource = '', toasterAttrs = ''): string {
355
- const optionBlock = optionsSource ? `\n ${optionsSource}` : '';
356
- return `<script setup lang="ts">
357
- import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
358
- </script>
359
-
360
- <template>
361
- <UiButton
362
- @click="showSnackbar({
363
- title: 'Event has been created',${optionBlock}
364
- })"
365
- >
366
- Show snackbar
367
- </UiButton>
368
- <UiSnackbar${toasterAttrs} />
369
- </template>`;
370
- }
371
-
372
348
  /**
373
349
  * Render factory for the individual state stories: one trigger that opens a
374
350
  * single snackbar with the given options. The play leaves the toast mounted
@@ -412,6 +388,22 @@ async function openStateSnackbar(canvas: ReturnType<typeof within>) {
412
388
  });
413
389
  }
414
390
 
391
+ const successTemplateSource = `<script setup lang="ts">
392
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
393
+ </script>
394
+
395
+ <template>
396
+ <UiButton
397
+ @click="showSnackbar({
398
+ title: '${SNACKBAR_ACTION_TITLE}',
399
+ iconMode: 'success',
400
+ })"
401
+ >
402
+ Show snackbar
403
+ </UiButton>
404
+ <UiSnackbar />
405
+ </template>`;
406
+
415
407
  /**
416
408
  * Success state with its status icon, rendered mounted so visual and
417
409
  * accessibility checks exercise it independently of the grouped `IconModes`
@@ -424,7 +416,7 @@ export const Success: Story = {
424
416
  }),
425
417
  parameters: {
426
418
  docs: {
427
- source: { code: stateTemplateSource(`iconMode: 'success',`) },
419
+ source: { code: successTemplateSource },
428
420
  },
429
421
  },
430
422
  play: async ({ canvasElement, step }) => {
@@ -441,6 +433,22 @@ export const Success: Story = {
441
433
  },
442
434
  };
443
435
 
436
+ const warningTemplateSource = `<script setup lang="ts">
437
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
438
+ </script>
439
+
440
+ <template>
441
+ <UiButton
442
+ @click="showSnackbar({
443
+ title: '${SNACKBAR_ACTION_TITLE}',
444
+ iconMode: 'warning',
445
+ })"
446
+ >
447
+ Show snackbar
448
+ </UiButton>
449
+ <UiSnackbar />
450
+ </template>`;
451
+
444
452
  /**
445
453
  * Warning state with its status icon, rendered mounted so visual and
446
454
  * accessibility checks exercise it independently of the grouped `IconModes`
@@ -453,7 +461,7 @@ export const Warning: Story = {
453
461
  }),
454
462
  parameters: {
455
463
  docs: {
456
- source: { code: stateTemplateSource(`iconMode: 'warning',`) },
464
+ source: { code: warningTemplateSource },
457
465
  },
458
466
  },
459
467
  play: async ({ canvasElement, step }) => {
@@ -470,6 +478,22 @@ export const Warning: Story = {
470
478
  },
471
479
  };
472
480
 
481
+ const errorTemplateSource = `<script setup lang="ts">
482
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
483
+ </script>
484
+
485
+ <template>
486
+ <UiButton
487
+ @click="showSnackbar({
488
+ title: '${SNACKBAR_ACTION_TITLE}',
489
+ iconMode: 'error',
490
+ })"
491
+ >
492
+ Show snackbar
493
+ </UiButton>
494
+ <UiSnackbar />
495
+ </template>`;
496
+
473
497
  /**
474
498
  * Error state with its status icon, rendered mounted so visual and
475
499
  * accessibility checks exercise it independently of the grouped `IconModes`
@@ -483,7 +507,7 @@ export const ErrorState: Story = {
483
507
  }),
484
508
  parameters: {
485
509
  docs: {
486
- source: { code: stateTemplateSource(`iconMode: 'error',`) },
510
+ source: { code: errorTemplateSource },
487
511
  },
488
512
  },
489
513
  play: async ({ canvasElement, step }) => {
@@ -500,6 +524,22 @@ export const ErrorState: Story = {
500
524
  },
501
525
  };
502
526
 
527
+ const loadingTemplateSource = `<script setup lang="ts">
528
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
529
+ </script>
530
+
531
+ <template>
532
+ <UiButton
533
+ @click="showSnackbar({
534
+ title: '${SNACKBAR_ACTION_TITLE}',
535
+ iconMode: 'loading',
536
+ })"
537
+ >
538
+ Show snackbar
539
+ </UiButton>
540
+ <UiSnackbar />
541
+ </template>`;
542
+
503
543
  /**
504
544
  * Loading state with its spinner, rendered mounted so visual and
505
545
  * accessibility checks exercise it independently of the grouped `IconModes`
@@ -513,7 +553,7 @@ export const Loading: Story = {
513
553
  }),
514
554
  parameters: {
515
555
  docs: {
516
- source: { code: stateTemplateSource(`iconMode: 'loading',`) },
556
+ source: { code: loadingTemplateSource },
517
557
  },
518
558
  },
519
559
  play: async ({ canvasElement, step }) => {
@@ -602,6 +642,24 @@ export const ActionModes: Story = {
602
642
  },
603
643
  };
604
644
 
645
+ const secondaryActionTemplateSource = `<script setup lang="ts">
646
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
647
+ </script>
648
+
649
+ <template>
650
+ <UiButton
651
+ @click="showSnackbar({
652
+ title: '${SNACKBAR_ACTION_TITLE}',
653
+ actionLabel: '${SNACKBAR_ACTION_LABEL}',
654
+ actionMode: 'secondary',
655
+ onAction: () => {},
656
+ })"
657
+ >
658
+ Show snackbar
659
+ </UiButton>
660
+ <UiSnackbar />
661
+ </template>`;
662
+
605
663
  /**
606
664
  * Secondary action button mode, rendered mounted so visual and accessibility
607
665
  * checks exercise it independently of the grouped `ActionModes` demo. For the
@@ -617,9 +675,7 @@ export const SecondaryAction: Story = {
617
675
  parameters: {
618
676
  docs: {
619
677
  source: {
620
- code: stateTemplateSource(
621
- `actionLabel: 'Undo',\n actionMode: 'secondary',\n onAction: () => {},`,
622
- ),
678
+ code: secondaryActionTemplateSource,
623
679
  },
624
680
  },
625
681
  },
@@ -748,6 +804,22 @@ export const WithAction: Story = {
748
804
  },
749
805
  };
750
806
 
807
+ const withoutCloseButtonTemplateSource = `<script setup lang="ts">
808
+ import { UiSnackbar, showSnackbar, UiButton } from '@aleph-alpha/ui-library'
809
+ </script>
810
+
811
+ <template>
812
+ <UiButton
813
+ @click="showSnackbar({
814
+ title: '${SNACKBAR_ACTION_TITLE}',
815
+ closeButton: false,
816
+ })"
817
+ >
818
+ Show snackbar
819
+ </UiButton>
820
+ <UiSnackbar />
821
+ </template>`;
822
+
751
823
  /**
752
824
  * Snackbar without a dismiss control (`closeButton: false`), rendered mounted
753
825
  * so visual and accessibility checks exercise it independently. Reserve this
@@ -762,7 +834,7 @@ export const WithoutCloseButton: Story = {
762
834
  parameters: {
763
835
  docs: {
764
836
  source: {
765
- code: stateTemplateSource(`closeButton: false,`),
837
+ code: withoutCloseButtonTemplateSource,
766
838
  },
767
839
  },
768
840
  },