@aleph-alpha/ui-library 3.0.0 → 3.2.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 (70) hide show
  1. package/README.md +41 -32
  2. package/config.js +9 -10
  3. package/dist/system/components/UiSnackbar/UiSnackbar.vue.d.ts +1 -0
  4. package/dist/system/components/UiSnackbar/UiSnackbarContent.vue.d.ts +29 -0
  5. package/dist/system/components/UiSnackbar/UiSnackbarIcon.vue.d.ts +3 -0
  6. package/dist/system/components/UiSnackbar/index.d.ts +3 -0
  7. package/dist/system/components/UiSnackbar/showSnackbar.d.ts +55 -0
  8. package/dist/system/components/UiSnackbar/types.d.ts +76 -17
  9. package/dist/system/components/core/sidebar/SidebarProvider.vue.d.ts +2 -0
  10. package/dist/system/components/core/sidebar/utils.d.ts +1 -1
  11. package/dist/system/index.d.ts +1 -0
  12. package/dist/system/lib/useDevice.d.ts +59 -0
  13. package/dist/system/lib.js +14655 -14319
  14. package/dist/system/patterns/UiSidebar/UiSidebarProvider.vue.d.ts +10 -1
  15. package/dist/system/patterns/UiSidebar/__tests__/sidebar-test-helpers.d.ts +55 -6
  16. package/dist/system/patterns/UiSidebar/index.d.ts +1 -1
  17. package/dist/system/patterns/UiSidebar/types.d.ts +26 -2
  18. package/package.json +4 -4
  19. package/src/@types/shims-vue.d.ts +5 -0
  20. package/src/components/UiButton/UiButton.stories.ts +4 -20
  21. package/src/components/UiCheckbox/UiCheckbox.stories.ts +4 -20
  22. package/src/components/UiField/UiField.stories.ts +4 -19
  23. package/src/components/UiIcon/UiIcon.stories.ts +2 -0
  24. package/src/components/UiItem/UiItem.stories.ts +4 -19
  25. package/src/components/UiSnackbar/UiSnackbar.stories.ts +281 -255
  26. package/src/components/UiSnackbar/UiSnackbar.vue +71 -241
  27. package/src/components/UiSnackbar/UiSnackbarContent.vue +114 -0
  28. package/src/components/UiSnackbar/UiSnackbarIcon.vue +78 -0
  29. package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +154 -1
  30. package/src/components/UiSnackbar/__tests__/showSnackbar.test.ts +258 -0
  31. package/src/components/UiSnackbar/assets/error.svg +3 -0
  32. package/src/components/UiSnackbar/assets/info.svg +3 -0
  33. package/src/components/UiSnackbar/assets/loading.svg +14 -0
  34. package/src/components/UiSnackbar/assets/success.svg +5 -0
  35. package/src/components/UiSnackbar/assets/warning.svg +3 -0
  36. package/src/components/UiSnackbar/index.ts +3 -0
  37. package/src/components/UiSnackbar/showSnackbar.ts +174 -0
  38. package/src/components/UiSnackbar/types.ts +90 -17
  39. package/src/components/core/sidebar/Sidebar.vue +25 -27
  40. package/src/components/core/sidebar/SidebarInset.vue +13 -1
  41. package/src/components/core/sidebar/SidebarProvider.vue +22 -2
  42. package/src/components/core/sidebar/SidebarTrigger.vue +2 -2
  43. package/src/components/core/sidebar/utils.ts +1 -1
  44. package/src/components/core/sonner/Sonner.vue +3 -20
  45. package/src/directives/vHover.stories.ts +4 -0
  46. package/src/index.ts +1 -0
  47. package/src/lib/useDevice.stories.ts +408 -0
  48. package/src/lib/useDevice.test.ts +129 -0
  49. package/src/lib/useDevice.ts +199 -0
  50. package/src/lib/useDrag.stories.ts +5 -1
  51. package/src/patterns/UiSidebar/UiSidebar.stories.ts +14 -1
  52. package/src/patterns/UiSidebar/UiSidebarProvider.vue +21 -1
  53. package/src/patterns/UiSidebar/UiSidebarTrigger.vue +39 -5
  54. package/src/patterns/UiSidebar/__tests__/UiSidebar.test.ts +66 -1
  55. package/src/patterns/UiSidebar/__tests__/UiSidebarHeader.test.ts +1 -1
  56. package/src/patterns/UiSidebar/__tests__/UiSidebarTrigger.test.ts +1 -1
  57. package/src/patterns/UiSidebar/__tests__/sidebar-test-helpers.ts +21 -0
  58. package/src/patterns/UiSidebar/index.ts +1 -0
  59. package/src/patterns/UiSidebar/types.ts +29 -2
  60. package/src/theme/Background.stories.ts +2 -0
  61. package/src/theme/Border.stories.ts +2 -0
  62. package/src/theme/BorderRadius.stories.ts +2 -0
  63. package/src/theme/Extended.stories.ts +2 -0
  64. package/src/theme/Flex.stories.ts +2 -0
  65. package/src/theme/Grid.stories.ts +2 -0
  66. package/src/theme/HoverLayer.stories.ts +2 -0
  67. package/src/theme/Overlay.stories.ts +2 -0
  68. package/src/theme/Shadow.stories.ts +2 -0
  69. package/src/theme/Theme.stories.ts +2 -0
  70. package/src/theme/Typography.stories.ts +2 -0
@@ -1,13 +1,17 @@
1
+ import type { VNode } from 'vue';
1
2
  import type { ToasterProps } from 'vue-sonner';
2
3
 
3
4
  /**
4
- * Toast notification container (Sonner). Place once near the app root,
5
- * then call `toast()` (or `toast.success()`, `toast.error()`, etc.) from
6
- * anywhere to display a non-blocking notification.
5
+ * Toast notification container. Place once near the app root,
6
+ * then call `showSnackbar()` or `toast()` from anywhere to display
7
+ * a non-blocking notification with a title and optional description.
8
+ *
9
+ * This component is currently experimental. Its API and behavior may still change
10
+ * before it is considered stable.
7
11
  * @category Feedback
8
- * @useCases success confirmation, error notice, undo action, async progress, background updates
9
- * @keywords snackbar, toast, sonner, notification, alert, message, banner, undo
10
- * @related UiAlert, UiAlertDialog
12
+ * @useCases confirmation, undo action, async progress, background updates
13
+ * @keywords snackbar, toast, notification, alert, message, banner, undo, experimental
14
+ * @related UiAlert, UiAlertDialog, UiSnackbarContent
11
15
  */
12
16
  export type UiSnackbarProps = {
13
17
  /**
@@ -22,15 +26,6 @@ export type UiSnackbarProps = {
22
26
  theme?: ToasterProps['theme'];
23
27
  /** Mirror the body color scheme so toasts contrast against it. */
24
28
  invert?: ToasterProps['invert'];
25
- /**
26
- * Apply colored backgrounds for `success`, `error`, `info`, and `warning` toasts.
27
- *
28
- * Accessibility: color must not be the only signal of toast type
29
- * (WCAG 1.4.1 Use of Color). Always pair with a descriptive message
30
- * and/or icon so the meaning is conveyed to users who cannot perceive
31
- * the color difference.
32
- */
33
- richColors?: ToasterProps['richColors'];
34
29
  /** Show all stacked toasts expanded by default instead of collapsed. */
35
30
  expand?: ToasterProps['expand'];
36
31
  /**
@@ -41,6 +36,7 @@ export type UiSnackbarProps = {
41
36
  * reader users can dismiss them on their own terms. The close
42
37
  * button has an accessible name of `'Close toast'` by default;
43
38
  * customise via `toastOptions.closeButtonAriaLabel`.
39
+ * @default true
44
40
  */
45
41
  closeButton?: ToasterProps['closeButton'];
46
42
  /** Position of the close button within each toast. */
@@ -79,8 +75,6 @@ export type UiSnackbarProps = {
79
75
  hotkey?: ToasterProps['hotkey'];
80
76
  /** Directions in which a toast can be dismissed by swipe. */
81
77
  swipeDirections?: ToasterProps['swipeDirections'];
82
- /** Custom icons used for each toast type. */
83
- icons?: ToasterProps['icons'];
84
78
  /** Default options applied to every toast. */
85
79
  toastOptions?: ToasterProps['toastOptions'];
86
80
  /**
@@ -95,3 +89,82 @@ export type UiSnackbarProps = {
95
89
  /** Identifier when rendering more than one Toaster instance. */
96
90
  id?: ToasterProps['id'];
97
91
  };
92
+
93
+ export type UiSnackbarIconMode =
94
+ | 'success'
95
+ | 'info'
96
+ | 'warning'
97
+ | 'error'
98
+ | 'loading';
99
+
100
+ export type UiSnackbarActionMode = 'default' | 'secondary';
101
+
102
+ /**
103
+ * Design-system snackbar status icon.
104
+ * @category Feedback
105
+ * @keywords snackbar, icon, success, info, warning, error, loading
106
+ * @related UiSnackbar, UiSnackbarContent
107
+ */
108
+ export type UiSnackbarIconProps = {
109
+ /** Visual mode for the snackbar status icon. */
110
+ mode: UiSnackbarIconMode;
111
+ /** Accessible label. Defaults to a mode-specific label. */
112
+ ariaLabel?: string;
113
+ };
114
+
115
+ /**
116
+ * Presentational snackbar layout with a title, optional description,
117
+ * leading status icon, and trailing action slot.
118
+ * @category Feedback
119
+ * @useCases static preview, custom toast content, composed notifications
120
+ * @keywords snackbar, toast, notification, title, description, icon, action
121
+ * @related UiSnackbar
122
+ */
123
+ export type UiSnackbarContentProps = {
124
+ /** Primary snackbar message. */
125
+ title: string;
126
+ /** Supporting context shown below the title. */
127
+ description?: string;
128
+ /**
129
+ * Built-in status icon mode.
130
+ */
131
+ iconMode?: UiSnackbarIconMode;
132
+ /** Built-in action label. Ignored when the action slot is provided. */
133
+ actionLabel?: string;
134
+ /**
135
+ * Visual mode for the built-in action button.
136
+ * @default 'default'
137
+ */
138
+ actionMode?: UiSnackbarActionMode;
139
+ /**
140
+ * When true, renders only the inner layout without surface chrome.
141
+ * Used when the snackbar is rendered inside the toast container.
142
+ * @default false
143
+ */
144
+ embedded?: boolean;
145
+ /**
146
+ * Show a close button on the trailing edge. Used for embedded toasts where
147
+ * Sonner does not render its own close control.
148
+ * @default true
149
+ */
150
+ closeButton?: boolean;
151
+ /**
152
+ * Accessible label for the close button.
153
+ * @default 'Close toast'
154
+ */
155
+ closeButtonAriaLabel?: string;
156
+ /** Called by Sonner when the close button is clicked. */
157
+ onCloseToast?: () => void;
158
+ };
159
+
160
+ export type {
161
+ ShowSnackbarOptions,
162
+ ShowSnackbarPromiseMessages,
163
+ } from './showSnackbar';
164
+
165
+ export type UiSnackbarContentSlots = {
166
+ /** Supporting text rendered below the title. Overrides `description` when provided. */
167
+ description?: () => VNode[];
168
+ /** Trailing action content such as a button or link. */
169
+ action?: () => VNode[];
170
+ };
@@ -3,10 +3,6 @@ import type { SidebarProps } from '.';
3
3
  import { defaultWindow } from '@vueuse/core';
4
4
  import { computed, onBeforeUnmount, ref, watch } from 'vue';
5
5
  import { cn } from '@/lib/utils';
6
- import { Sheet, SheetContent } from '@/components/core/sheet';
7
- import SheetDescription from '@/components/core/sheet/SheetDescription.vue';
8
- import SheetHeader from '@/components/core/sheet/SheetHeader.vue';
9
- import SheetTitle from '@/components/core/sheet/SheetTitle.vue';
10
6
  import SidebarResizeHandle from './SidebarResizeHandle.vue';
11
7
  import {
12
8
  SIDEBAR_WIDTH_DEFAULT,
@@ -34,7 +30,7 @@ const props = withDefaults(defineProps<SidebarProps>(), {
34
30
  keyboardResizeBy: 10,
35
31
  });
36
32
 
37
- const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
33
+ const { isMobile, state, openMobile } = useSidebar();
38
34
 
39
35
  const resolvedResizable = computed(
40
36
  () => props.resizeOptions !== undefined || props.resizable,
@@ -227,31 +223,33 @@ onBeforeUnmount(stopResize);
227
223
  />
228
224
  </div>
229
225
 
230
- <Sheet
226
+ <div
231
227
  v-else-if="isMobile"
232
- :open="openMobile"
233
228
  v-bind="$attrs"
234
- @update:open="setOpenMobile"
229
+ :aria-hidden="openMobile ? undefined : 'true'"
230
+ data-sidebar="sidebar"
231
+ data-slot="sidebar"
232
+ data-mobile="true"
233
+ :data-state="openMobile ? 'expanded' : 'collapsed'"
234
+ data-side="left"
235
+ :style="{
236
+ '--sidebar-width': SIDEBAR_WIDTH_MOBILE,
237
+ }"
238
+ :class="
239
+ cn(
240
+ 'bg-sidebar text-sidebar-foreground fixed inset-y-0 left-0 z-30 flex h-svh w-(--sidebar-width) flex-col transition-[opacity,transform] duration-(--sidebar-mobile-transition-duration) ease-out will-change-[opacity,transform]',
241
+ openMobile
242
+ ? 'translate-x-0 opacity-100'
243
+ : 'pointer-events-none opacity-0',
244
+ 'data-[state=collapsed]:-translate-x-full',
245
+ $attrs.class ?? '',
246
+ )
247
+ "
235
248
  >
236
- <SheetContent
237
- data-sidebar="sidebar"
238
- data-slot="sidebar"
239
- data-mobile="true"
240
- :side="side"
241
- class="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
242
- :style="{
243
- '--sidebar-width': SIDEBAR_WIDTH_MOBILE,
244
- }"
245
- >
246
- <SheetHeader class="sr-only">
247
- <SheetTitle>Sidebar</SheetTitle>
248
- <SheetDescription>Displays the mobile sidebar.</SheetDescription>
249
- </SheetHeader>
250
- <div class="flex h-full w-full flex-col">
251
- <slot />
252
- </div>
253
- </SheetContent>
254
- </Sheet>
249
+ <div class="flex h-full w-full flex-col">
250
+ <slot />
251
+ </div>
252
+ </div>
255
253
 
256
254
  <div
257
255
  v-else
@@ -10,7 +10,7 @@ defineOptions({ inheritAttrs: false });
10
10
  data-slot="sidebar-inset"
11
11
  :class="
12
12
  cn(
13
- 'bg-background relative flex w-full flex-1 flex-col',
13
+ 'bg-background relative flex w-full flex-1 flex-col transition-[border-radius,box-shadow,opacity,transform] duration-(--sidebar-mobile-transition-duration) ease-out will-change-[opacity,transform]',
14
14
  'md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2',
15
15
  $attrs.class ?? '',
16
16
  )
@@ -19,3 +19,15 @@ defineOptions({ inheritAttrs: false });
19
19
  <slot />
20
20
  </main>
21
21
  </template>
22
+
23
+ <style scoped>
24
+ :global(
25
+ [data-slot='sidebar'][data-mobile='true'][data-state='expanded'][data-side='left']
26
+ ~ [data-slot='sidebar-inset']
27
+ ) {
28
+ border-radius: 12px 0 0 12px;
29
+ box-shadow: 0 4px 16px rgb(0 0 0 / 8%);
30
+ opacity: 0.32;
31
+ transform: translateX(calc(var(--sidebar-width-mobile) + 12px));
32
+ }
33
+ </style>
@@ -7,7 +7,7 @@ import {
7
7
  useVModel,
8
8
  } from '@vueuse/core';
9
9
  import { TooltipProvider } from 'reka-ui';
10
- import { computed, ref } from 'vue';
10
+ import { computed, ref, watch } from 'vue';
11
11
  import { cn } from '@/lib/utils';
12
12
  import {
13
13
  provideSidebarContext,
@@ -16,6 +16,7 @@ import {
16
16
  SIDEBAR_KEYBOARD_SHORTCUT,
17
17
  SIDEBAR_WIDTH,
18
18
  SIDEBAR_WIDTH_ICON,
19
+ SIDEBAR_WIDTH_MOBILE,
19
20
  } from './utils';
20
21
 
21
22
  defineOptions({ inheritAttrs: false });
@@ -23,12 +24,14 @@ defineOptions({ inheritAttrs: false });
23
24
  const props = withDefaults(
24
25
  defineProps<{
25
26
  defaultOpen?: boolean;
27
+ mobileTransitionDuration?: string;
26
28
  open?: boolean;
27
29
  }>(),
28
30
  {
29
31
  defaultOpen: !defaultDocument?.cookie.includes(
30
32
  `${SIDEBAR_COOKIE_NAME}=false`,
31
33
  ),
34
+ mobileTransitionDuration: '20ms',
32
35
  open: undefined,
33
36
  },
34
37
  );
@@ -58,6 +61,9 @@ function setOpen(value: boolean) {
58
61
 
59
62
  function setOpenMobile(value: boolean) {
60
63
  openMobile.value = value;
64
+ if (props.open !== undefined) {
65
+ emits('update:open', value);
66
+ }
61
67
  }
62
68
 
63
69
  // Helper to toggle the sidebar.
@@ -67,6 +73,16 @@ function toggleSidebar() {
67
73
  : setOpen(!open.value);
68
74
  }
69
75
 
76
+ watch(
77
+ [isMobile, () => props.open],
78
+ ([mobile, controlledOpen]) => {
79
+ if (mobile && controlledOpen !== undefined) {
80
+ openMobile.value = controlledOpen;
81
+ }
82
+ },
83
+ { immediate: true },
84
+ );
85
+
70
86
  useEventListener('keydown', (event: KeyboardEvent) => {
71
87
  if (
72
88
  event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
@@ -97,13 +113,17 @@ provideSidebarContext({
97
113
  <div
98
114
  v-bind="$attrs"
99
115
  data-slot="sidebar-wrapper"
116
+ :data-mobile="isMobile ? 'true' : undefined"
117
+ :data-mobile-open="isMobile ? String(openMobile) : undefined"
100
118
  :style="{
101
119
  '--sidebar-width': SIDEBAR_WIDTH,
102
120
  '--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
121
+ '--sidebar-width-mobile': SIDEBAR_WIDTH_MOBILE,
122
+ '--sidebar-mobile-transition-duration': props.mobileTransitionDuration,
103
123
  }"
104
124
  :class="
105
125
  cn(
106
- 'group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full',
126
+ 'group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full overflow-hidden bg-background',
107
127
  $attrs.class ?? '',
108
128
  )
109
129
  "
@@ -11,13 +11,13 @@ const { toggleSidebar } = useSidebar();
11
11
 
12
12
  <template>
13
13
  <Button
14
- v-bind="$attrs"
15
14
  data-sidebar="trigger"
16
15
  data-slot="sidebar-trigger"
17
16
  variant="ghost"
18
17
  size="icon-sm"
19
18
  aria-label="Toggle Sidebar"
20
- :class="cn('h-8 w-8', $attrs.class ?? '')"
19
+ v-bind="$attrs"
20
+ :class="cn('hidden h-8 w-8 md:inline-flex', $attrs.class ?? '')"
21
21
  @click="toggleSidebar"
22
22
  >
23
23
  <UiIcon name="panel-left" />
@@ -7,7 +7,7 @@ export const SIDEBAR_WIDTH = '16rem';
7
7
  export const SIDEBAR_WIDTH_DEFAULT = 256;
8
8
  export const SIDEBAR_WIDTH_MIN = 240;
9
9
  export const SIDEBAR_WIDTH_MAX = 480;
10
- export const SIDEBAR_WIDTH_MOBILE = '18rem';
10
+ export const SIDEBAR_WIDTH_MOBILE = '16rem';
11
11
  export const SIDEBAR_WIDTH_ICON = '3rem';
12
12
  export const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
13
13
  export const SIDEBAR_WIDTH_STORAGE_KEY = 'sidebar_width';
@@ -12,30 +12,13 @@ const props = defineProps<ToasterProps>();
12
12
  v-bind="props"
13
13
  :class="cn('toaster group', props.class)"
14
14
  :style="{
15
- '--normal-bg': 'oklch(var(--background-surface-inverse))',
16
- '--normal-text': 'oklch(var(--content-on-surface-inverse))',
17
- '--normal-border': 'transparent',
15
+ '--normal-bg': 'oklch(var(--background-surface-floating))',
16
+ '--normal-text': 'oklch(var(--content-on-surface-primary))',
17
+ '--normal-border': 'oklch(var(--border-surface-default))',
18
18
  '--border-radius': 'var(--radius)',
19
19
  ...((typeof props.style === 'object' && props.style) || {}),
20
20
  }"
21
21
  >
22
- <template #success-icon>
23
- <UiIcon name="circle-check" size="s" />
24
- </template>
25
- <template #info-icon>
26
- <UiIcon name="info" size="s" />
27
- </template>
28
- <template #warning-icon>
29
- <UiIcon name="triangle-alert" size="s" />
30
- </template>
31
- <template #error-icon>
32
- <UiIcon name="octagon-x" size="s" />
33
- </template>
34
- <template #loading-icon>
35
- <div>
36
- <UiIcon name="loader-2" size="s" class="animate-spin" />
37
- </div>
38
- </template>
39
22
  <template #close-icon>
40
23
  <UiIcon name="x" size="s" />
41
24
  </template>
@@ -109,6 +109,10 @@ const meta: Meta<typeof VHoverDemo> = {
109
109
  component: VHoverDemo,
110
110
  tags: ['autodocs'],
111
111
  parameters: {
112
+ a11y: { test: 'off' },
113
+ chromatic: {
114
+ disableSnapshot: true,
115
+ },
112
116
  layout: 'fullscreen',
113
117
  docs: {
114
118
  description: {
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import type { PrimitiveProps as RekaPrimitiveProps } from 'reka-ui';
7
7
  export * from './components';
8
8
  export * from './patterns';
9
9
  export * from './templates';
10
+ export * from './lib/useDevice';
10
11
  export * from './directives';
11
12
  export { Primitive } from 'reka-ui';
12
13
  export type PrimitiveProps = RekaPrimitiveProps;