@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,6 +1,10 @@
1
1
  import { render } from '@testing-library/vue';
2
- import { describe, expect, test } from 'vitest';
2
+ import { describe, expect, test, vi } from 'vitest';
3
+ import { h } from 'vue';
3
4
  import UiSnackbar from '../UiSnackbar.vue';
5
+ import UiSnackbarContent from '../UiSnackbarContent.vue';
6
+ import UiSnackbarIcon from '../UiSnackbarIcon.vue';
7
+ import { UiButton } from '../../UiButton';
4
8
 
5
9
  describe('UiSnackbar', () => {
6
10
  test('applies the wrapper default containerAriaLabel', () => {
@@ -15,3 +19,152 @@ describe('UiSnackbar', () => {
15
19
  expect(getByLabelText(/App messages/i)).toBeInTheDocument();
16
20
  });
17
21
  });
22
+
23
+ describe('UiSnackbarContent', () => {
24
+ test('renders title and description', () => {
25
+ const { getByText } = render(UiSnackbarContent, {
26
+ props: {
27
+ title: 'Event has been created',
28
+ description: 'Sunday, December 03, 2023 at 9:00 AM',
29
+ },
30
+ });
31
+
32
+ expect(getByText('Event has been created')).toBeInTheDocument();
33
+ expect(
34
+ getByText('Sunday, December 03, 2023 at 9:00 AM'),
35
+ ).toBeInTheDocument();
36
+ });
37
+
38
+ test('renders built-in action modes', () => {
39
+ const { getByRole } = render(UiSnackbarContent, {
40
+ props: {
41
+ title: 'Event has been created',
42
+ actionLabel: 'Undo',
43
+ actionMode: 'secondary',
44
+ },
45
+ });
46
+
47
+ expect(getByRole('button', { name: 'Undo' })).toHaveClass(
48
+ 'bg-background-button-secondary-button',
49
+ );
50
+ });
51
+
52
+ test('emits action when built-in action is clicked', async () => {
53
+ const { getByRole, emitted } = render(UiSnackbarContent, {
54
+ props: {
55
+ title: 'Event has been created',
56
+ actionLabel: 'Undo',
57
+ },
58
+ });
59
+
60
+ await getByRole('button', { name: 'Undo' }).click();
61
+ expect(emitted().action).toHaveLength(1);
62
+ });
63
+
64
+ test('renders icon mode and custom action slot', () => {
65
+ const { getByTestId, getByRole, getByLabelText } = render(
66
+ UiSnackbarContent,
67
+ {
68
+ props: {
69
+ title: 'Event has been created',
70
+ iconMode: 'success',
71
+ },
72
+ slots: {
73
+ action: () => h(UiButton, { size: 'sm' }, () => 'Undo'),
74
+ },
75
+ },
76
+ );
77
+
78
+ expect(getByTestId('snackbar-content')).toBeInTheDocument();
79
+ expect(getByLabelText('Success')).toHaveAttribute('data-mode', 'success');
80
+ expect(getByRole('button', { name: 'Undo' })).toBeInTheDocument();
81
+ });
82
+
83
+ test('renders close button in embedded mode alongside action', async () => {
84
+ const onCloseToast = vi.fn();
85
+ const { getByRole } = render(UiSnackbarContent, {
86
+ props: {
87
+ title: 'Event has been created',
88
+ actionLabel: 'Undo',
89
+ embedded: true,
90
+ onCloseToast,
91
+ },
92
+ });
93
+
94
+ const closeButton = getByRole('button', { name: 'Close toast' });
95
+ expect(getByRole('button', { name: 'Undo' })).toBeInTheDocument();
96
+ expect(closeButton).toHaveClass('size-5');
97
+ await closeButton.click();
98
+ expect(onCloseToast).toHaveBeenCalledTimes(1);
99
+ });
100
+
101
+ test('hides close button when closeButton is false', () => {
102
+ const { queryByRole } = render(UiSnackbarContent, {
103
+ props: {
104
+ title: 'Event has been created',
105
+ actionLabel: 'Undo',
106
+ embedded: true,
107
+ closeButton: false,
108
+ onCloseToast: vi.fn(),
109
+ },
110
+ });
111
+
112
+ expect(
113
+ queryByRole('button', { name: 'Close toast' }),
114
+ ).not.toBeInTheDocument();
115
+ });
116
+ });
117
+
118
+ describe('UiSnackbarIcon', () => {
119
+ test.each([
120
+ ['success', 'Success', '--background-status-success'],
121
+ ['info', 'Information', '--content-on-status-info'],
122
+ ['warning', 'Warning', '--background-status-warning'],
123
+ ['error', 'Error', '--background-status-error'],
124
+ ['loading', 'Loading', '--content-on-status-neutral'],
125
+ ] as const)(
126
+ 'renders %s mode with accessible label and status color',
127
+ (mode, label, statusColorVar) => {
128
+ const { getByLabelText } = render(UiSnackbarIcon, {
129
+ props: { mode },
130
+ });
131
+
132
+ const icon = getByLabelText(label);
133
+ expect(icon).toBeInTheDocument();
134
+ expect(icon).toHaveStyle({
135
+ color: `oklch(var(${statusColorVar}))`,
136
+ });
137
+ },
138
+ );
139
+
140
+ test.each([
141
+ ['success', 'Success'],
142
+ ['info', 'Information'],
143
+ ['warning', 'Warning'],
144
+ ['error', 'Error'],
145
+ ['loading', 'Loading'],
146
+ ] as const)('renders %s icon at 16x16 pixels', (mode, label) => {
147
+ const { getByLabelText } = render(UiSnackbarIcon, {
148
+ props: { mode },
149
+ });
150
+
151
+ const icon = getByLabelText(label);
152
+ expect(icon).toHaveClass('size-4');
153
+
154
+ const svg = icon.querySelector('svg');
155
+ expect(svg).not.toBeNull();
156
+ expect(svg).toHaveAttribute('width', '16');
157
+ expect(svg).toHaveAttribute('height', '16');
158
+ });
159
+
160
+ test('disables loading spin animation when reduced motion is requested', () => {
161
+ const { getByLabelText } = render(UiSnackbarIcon, {
162
+ props: { mode: 'loading' },
163
+ });
164
+
165
+ expect(getByLabelText('Loading')).toHaveClass(
166
+ 'animate-spin',
167
+ 'motion-reduce:animate-none',
168
+ );
169
+ });
170
+ });
@@ -0,0 +1,258 @@
1
+ import { beforeEach, describe, expect, test, vi } from 'vitest';
2
+ import { h, type VNode } from 'vue';
3
+ import UiSnackbarContent from '../UiSnackbarContent.vue';
4
+ import { showSnackbar, showSnackbarPromise } from '../showSnackbar';
5
+
6
+ const toast = vi.fn();
7
+ const toastCustom = vi.fn();
8
+
9
+ vi.mock('vue-sonner', () => ({
10
+ toast: Object.assign((...args: unknown[]) => toast(...args), {
11
+ custom: (...args: unknown[]) => toastCustom(...args),
12
+ }),
13
+ }));
14
+
15
+ /**
16
+ * Returns the VNode from the latest custom toast render function.
17
+ * @param onCloseToast Optional close handler passed into the custom toast renderer.
18
+ */
19
+ function getCustomToastVNode(onCloseToast = vi.fn()): VNode {
20
+ const renderFn = toastCustom.mock.calls.at(-1)?.[0] as (props: {
21
+ onCloseToast?: () => void;
22
+ }) => VNode;
23
+ return renderFn({ onCloseToast });
24
+ }
25
+
26
+ describe('showSnackbar', () => {
27
+ beforeEach(() => {
28
+ vi.clearAllMocks();
29
+ });
30
+
31
+ describe('default toast path', () => {
32
+ test('uses toast() for title-only messages', () => {
33
+ showSnackbar({ title: 'Saved' });
34
+
35
+ expect(toast).toHaveBeenCalledWith('Saved', { closeButton: true });
36
+ expect(toastCustom).not.toHaveBeenCalled();
37
+ });
38
+
39
+ test('forwards description through the default toast API', () => {
40
+ showSnackbar({
41
+ title: 'Saved',
42
+ description: 'Your changes were stored.',
43
+ });
44
+
45
+ expect(toast).toHaveBeenCalledWith('Saved', {
46
+ description: 'Your changes were stored.',
47
+ closeButton: true,
48
+ });
49
+ expect(toastCustom).not.toHaveBeenCalled();
50
+ });
51
+
52
+ test('does not switch to custom content when only onAction is provided', () => {
53
+ const onAction = vi.fn();
54
+
55
+ showSnackbar({ title: 'Saved', onAction });
56
+
57
+ expect(toast).toHaveBeenCalledWith('Saved', { closeButton: true });
58
+ expect(toastCustom).not.toHaveBeenCalled();
59
+ });
60
+
61
+ test('forwards toast options to toast()', () => {
62
+ showSnackbar({
63
+ title: 'Saved',
64
+ duration: 5000,
65
+ toasterId: 'app-toasts',
66
+ });
67
+
68
+ expect(toast).toHaveBeenCalledWith('Saved', {
69
+ duration: 5000,
70
+ toasterId: 'app-toasts',
71
+ closeButton: true,
72
+ });
73
+ });
74
+ });
75
+
76
+ describe('custom toast path', () => {
77
+ test.each([
78
+ ['iconMode', { iconMode: 'success' as const }],
79
+ ['actionLabel', { actionLabel: 'Undo', onAction: vi.fn() }],
80
+ ['custom action', { action: h('button', {}, 'Undo') }],
81
+ ])('uses toast.custom() when %s is provided', (_label, options) => {
82
+ showSnackbar({ title: 'Saved', ...options });
83
+
84
+ expect(toastCustom).toHaveBeenCalledTimes(1);
85
+ expect(toast).not.toHaveBeenCalled();
86
+ });
87
+
88
+ test('renders embedded UiSnackbarContent with iconMode', () => {
89
+ showSnackbar({
90
+ title: 'Saved',
91
+ description: 'Just now',
92
+ iconMode: 'warning',
93
+ actionMode: 'secondary',
94
+ });
95
+
96
+ const vnode = getCustomToastVNode();
97
+
98
+ expect(vnode.type).toBe(UiSnackbarContent);
99
+ expect(vnode.props).toMatchObject({
100
+ title: 'Saved',
101
+ description: 'Just now',
102
+ iconMode: 'warning',
103
+ actionMode: 'secondary',
104
+ embedded: true,
105
+ closeButton: true,
106
+ });
107
+ expect(vnode.props).not.toHaveProperty('onAction');
108
+ });
109
+
110
+ test('prefers a custom action slot over actionLabel', () => {
111
+ const customAction = h('button', {}, 'Undo');
112
+
113
+ showSnackbar({
114
+ title: 'Saved',
115
+ actionLabel: 'Dismiss',
116
+ action: customAction,
117
+ onAction: vi.fn(),
118
+ });
119
+
120
+ const vnode = getCustomToastVNode();
121
+
122
+ expect(vnode.props?.actionLabel).toBeUndefined();
123
+ expect(vnode.props).not.toHaveProperty('onAction');
124
+
125
+ const slots = vnode.children as Record<string, () => VNode[]>;
126
+ expect(slots.action()).toEqual([customAction]);
127
+ });
128
+
129
+ test('passes onAction only when built-in action UI is rendered', () => {
130
+ const onAction = vi.fn();
131
+
132
+ showSnackbar({
133
+ title: 'Saved',
134
+ actionLabel: 'Undo',
135
+ onAction,
136
+ });
137
+
138
+ const vnode = getCustomToastVNode();
139
+
140
+ expect(vnode.props?.onAction).toBe(onAction);
141
+ });
142
+
143
+ test('forwards toast options to toast.custom()', () => {
144
+ showSnackbar({
145
+ title: 'Saved',
146
+ iconMode: 'info',
147
+ duration: 8000,
148
+ toasterId: 'app-toasts',
149
+ });
150
+
151
+ expect(toastCustom).toHaveBeenCalledWith(expect.any(Function), {
152
+ duration: 8000,
153
+ toasterId: 'app-toasts',
154
+ closeButton: true,
155
+ });
156
+ });
157
+
158
+ test('forwards onCloseToast to embedded content', () => {
159
+ const onCloseToast = vi.fn();
160
+
161
+ showSnackbar({
162
+ title: 'Saved',
163
+ actionLabel: 'Undo',
164
+ });
165
+
166
+ const vnode = getCustomToastVNode(onCloseToast);
167
+
168
+ expect(vnode.props?.onCloseToast).toBe(onCloseToast);
169
+ });
170
+
171
+ test('disables close button when closeButton is false', () => {
172
+ showSnackbar({
173
+ title: 'Saved',
174
+ iconMode: 'success',
175
+ closeButton: false,
176
+ });
177
+
178
+ const vnode = getCustomToastVNode();
179
+
180
+ expect(vnode.props?.closeButton).toBe(false);
181
+ expect(toastCustom).toHaveBeenCalledWith(expect.any(Function), {
182
+ closeButton: false,
183
+ });
184
+ });
185
+ });
186
+ });
187
+
188
+ describe('showSnackbarPromise', () => {
189
+ beforeEach(() => {
190
+ vi.clearAllMocks();
191
+ });
192
+
193
+ test('shows loading then success snackbars with icon modes', async () => {
194
+ showSnackbarPromise(Promise.resolve({ name: 'Event' }), {
195
+ loading: 'Saving event...',
196
+ success: (data) => `${data.name} has been created`,
197
+ error: 'Something went wrong',
198
+ });
199
+
200
+ expect(toastCustom).toHaveBeenCalledTimes(1);
201
+ expect(getCustomToastVNode().props).toMatchObject({
202
+ title: 'Saving event...',
203
+ iconMode: 'loading',
204
+ });
205
+
206
+ await vi.waitFor(() => expect(toastCustom).toHaveBeenCalledTimes(2));
207
+
208
+ expect(getCustomToastVNode().props).toMatchObject({
209
+ title: 'Event has been created',
210
+ iconMode: 'success',
211
+ });
212
+ expect(toastCustom.mock.calls.at(-1)?.[1]).toMatchObject({
213
+ duration: 5000,
214
+ });
215
+ });
216
+
217
+ test('shows loading then error snackbars with icon modes', async () => {
218
+ showSnackbarPromise(Promise.reject(new Error('Failed')), {
219
+ loading: 'Saving event...',
220
+ success: (data: { name: string }) => `${data.name} has been created`,
221
+ error: 'Something went wrong',
222
+ });
223
+
224
+ await vi.waitFor(() => expect(toastCustom).toHaveBeenCalledTimes(2));
225
+
226
+ expect(getCustomToastVNode().props).toMatchObject({
227
+ title: 'Something went wrong',
228
+ iconMode: 'error',
229
+ });
230
+ });
231
+
232
+ test('forwards shared toast options to each phase', async () => {
233
+ showSnackbarPromise(
234
+ Promise.resolve({ name: 'Event' }),
235
+ {
236
+ loading: 'Saving event...',
237
+ success: 'Event has been created',
238
+ error: 'Something went wrong',
239
+ },
240
+ {
241
+ toasterId: 'app-toasts',
242
+ duration: 8000,
243
+ },
244
+ );
245
+
246
+ expect(toastCustom.mock.calls.at(0)?.[1]).toMatchObject({
247
+ toasterId: 'app-toasts',
248
+ duration: Infinity,
249
+ });
250
+
251
+ await vi.waitFor(() => expect(toastCustom).toHaveBeenCalledTimes(2));
252
+
253
+ expect(toastCustom.mock.calls.at(-1)?.[1]).toMatchObject({
254
+ toasterId: 'app-toasts',
255
+ duration: 8000,
256
+ });
257
+ });
258
+ });
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="16" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M18 10C18 12.1217 17.1571 14.1566 15.6569 15.6569C14.1566 17.1571 12.1217 18 10 18C7.87827 18 5.84344 17.1571 4.34315 15.6569C2.84285 14.1566 2 12.1217 2 10C2 7.87827 2.84285 5.84344 4.34315 4.34315C5.84344 2.84285 7.87827 2 10 2C12.1217 2 14.1566 2.84285 15.6569 4.34315C17.1571 5.84344 18 7.87827 18 10ZM10 5C10.1989 5 10.3897 5.07902 10.5303 5.21967C10.671 5.36032 10.75 5.55109 10.75 5.75V10.25C10.75 10.4489 10.671 10.6397 10.5303 10.7803C10.3897 10.921 10.1989 11 10 11C9.80109 11 9.61032 10.921 9.46967 10.7803C9.32902 10.6397 9.25 10.4489 9.25 10.25V5.75C9.25 5.55109 9.32902 5.36032 9.46967 5.21967C9.61032 5.07902 9.80109 5 10 5ZM10 15C10.2652 15 10.5196 14.8946 10.7071 14.7071C10.8946 14.5196 11 14.2652 11 14C11 13.7348 10.8946 13.4804 10.7071 13.2929C10.5196 13.1054 10.2652 13 10 13C9.73478 13 9.48043 13.1054 9.29289 13.2929C9.10536 13.4804 9 13.7348 9 14C9 14.2652 9.10536 14.5196 9.29289 14.7071C9.48043 14.8946 9.73478 15 10 15Z" fill="currentColor"/>
3
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="16" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M18 10C18 12.1217 17.1571 14.1566 15.6569 15.6569C14.1566 17.1571 12.1217 18 10 18C7.87827 18 5.84344 17.1571 4.34315 15.6569C2.84285 14.1566 2 12.1217 2 10C2 7.87827 2.84285 5.84344 4.34315 4.34315C5.84344 2.84285 7.87827 2 10 2C12.1217 2 14.1566 2.84285 15.6569 4.34315C17.1571 5.84344 18 7.87827 18 10ZM11 6C11 6.26522 10.8946 6.51957 10.7071 6.70711C10.5196 6.89464 10.2652 7 10 7C9.73478 7 9.48043 6.89464 9.29289 6.70711C9.10536 6.51957 9 6.26522 9 6C9 5.73478 9.10536 5.48043 9.29289 5.29289C9.48043 5.10536 9.73478 5 10 5C10.2652 5 10.5196 5.10536 10.7071 5.29289C10.8946 5.48043 11 5.73478 11 6ZM9 9C8.80109 9 8.61032 9.07902 8.46967 9.21967C8.32902 9.36032 8.25 9.55109 8.25 9.75C8.25 9.94891 8.32902 10.1397 8.46967 10.2803C8.61032 10.421 8.80109 10.5 9 10.5H9.253C9.29041 10.5 9.32734 10.5084 9.36106 10.5246C9.39479 10.5408 9.42445 10.5643 9.44787 10.5935C9.47128 10.6227 9.48785 10.6567 9.49636 10.6932C9.50486 10.7296 9.50508 10.7675 9.497 10.804L9.038 12.87C8.98108 13.1259 8.98237 13.3913 9.04179 13.6466C9.10121 13.902 9.21723 14.1407 9.38129 14.3452C9.54535 14.5496 9.75325 14.7146 9.98963 14.828C10.226 14.9413 10.4848 15.0001 10.747 15H11C11.1989 15 11.3897 14.921 11.5303 14.7803C11.671 14.6397 11.75 14.4489 11.75 14.25C11.75 14.0511 11.671 13.8603 11.5303 13.7197C11.3897 13.579 11.1989 13.5 11 13.5H10.747C10.7096 13.5 10.6727 13.4916 10.6389 13.4754C10.6052 13.4592 10.5755 13.4357 10.5521 13.4065C10.5287 13.3773 10.5121 13.3433 10.5036 13.3068C10.4951 13.2704 10.4949 13.2325 10.503 13.196L10.962 11.13C11.0189 10.8741 11.0176 10.6087 10.9582 10.3534C10.8988 10.098 10.7828 9.8593 10.6187 9.65483C10.4547 9.45036 10.2468 9.28536 10.0104 9.17201C9.77398 9.05867 9.51515 8.99989 9.253 9H9Z" fill="currentColor"/>
3
+ </svg>
@@ -0,0 +1,14 @@
1
+ <svg width="16" height="16" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path opacity="0.1" d="M10 2.5V5" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
3
+ <path opacity="0.2" d="M6.25 3.505L7.5 5.67" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path opacity="0.3" d="M3.505 6.25L5.67 7.5" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <path opacity="0.4" d="M2.5 10H5" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
6
+ <path opacity="0.5" d="M3.505 13.75L5.67 12.5" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
7
+ <path opacity="0.55" d="M6.25 16.495L7.5 14.33" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
8
+ <path opacity="0.6" d="M10 17.5V15" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
9
+ <path opacity="0.65" d="M13.75 16.495L12.5 14.33" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
10
+ <path opacity="0.7" d="M16.495 13.75L14.33 12.5" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
11
+ <path opacity="0.8" d="M17.5 10H15" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
12
+ <path opacity="0.9" d="M16.4951 6.25018L14.3301 7.50013" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
13
+ <path d="M13.75 3.50482L12.5 5.66989" stroke="currentColor" stroke-width="1.33" stroke-linecap="round" stroke-linejoin="round"/>
14
+ </svg>
@@ -0,0 +1,5 @@
1
+ <svg width="16" height="16" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g transform="translate(2 2)">
3
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M8 16C10.1217 16 12.1566 15.1571 13.6569 13.6569C15.1571 12.1566 16 10.1217 16 8C16 5.87827 15.1571 3.84344 13.6569 2.34315C12.1566 0.842855 10.1217 0 8 0C5.87827 0 3.84344 0.842855 2.34315 2.34315C0.842855 3.84344 0 5.87827 0 8C0 10.1217 0.842855 12.1566 2.34315 13.6569C3.84344 15.1571 5.87827 16 8 16ZM11.857 6.191C11.9149 6.11129 11.9566 6.02095 11.9796 5.92514C12.0026 5.82933 12.0065 5.72994 11.991 5.63262C11.9756 5.5353 11.9412 5.44198 11.8897 5.35797C11.8382 5.27396 11.7707 5.20091 11.691 5.143C11.6113 5.08509 11.5209 5.04344 11.4251 5.02044C11.3293 4.99744 11.2299 4.99354 11.1326 5.00895C11.0353 5.02437 10.942 5.0588 10.858 5.11028C10.774 5.16176 10.7009 5.22929 10.643 5.309L7.16 10.099L5.28 8.219C5.21078 8.1474 5.128 8.0903 5.03647 8.05104C4.94495 8.01178 4.84653 7.99114 4.74694 7.99032C4.64736 7.9895 4.54861 8.00852 4.45646 8.04628C4.3643 8.08403 4.28059 8.13976 4.2102 8.21021C4.13982 8.28066 4.08417 8.36443 4.0465 8.45662C4.00883 8.54881 3.9899 8.64758 3.99081 8.74716C3.99173 8.84674 4.01246 8.94515 4.05181 9.03663C4.09116 9.12812 4.14834 9.21085 4.22 9.28L6.72 11.78C6.79663 11.8567 6.88896 11.9158 6.99065 11.9534C7.09233 11.9909 7.20094 12.006 7.30901 11.9975C7.41708 11.9891 7.52203 11.9573 7.61663 11.9044C7.71123 11.8515 7.79324 11.7787 7.857 11.691L11.857 6.191Z" fill="currentColor"/>
4
+ </g>
5
+ </svg>
@@ -0,0 +1,3 @@
1
+ <svg width="16" height="16" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M7.83417 2.5025C8.79667 0.835836 11.2033 0.835836 12.165 2.5025L18.2942 13.1258C19.2558 14.7925 18.0525 16.8758 16.1283 16.8758H3.87083C1.94667 16.8758 0.744168 14.7925 1.70583 13.1258L7.83333 2.5025H7.83417ZM10 6.875C10.1658 6.875 10.3247 6.94085 10.4419 7.05806C10.5592 7.17527 10.625 7.33424 10.625 7.5V10.625C10.625 10.7908 10.5592 10.9497 10.4419 11.0669C10.3247 11.1842 10.1658 11.25 10 11.25C9.83424 11.25 9.67527 11.1842 9.55806 11.0669C9.44085 10.9497 9.375 10.7908 9.375 10.625V7.5C9.375 7.33424 9.44085 7.17527 9.55806 7.05806C9.67527 6.94085 9.83424 6.875 10 6.875ZM10 13.75C10.1658 13.75 10.3247 13.6842 10.4419 13.5669C10.5592 13.4497 10.625 13.2908 10.625 13.125C10.625 12.9592 10.5592 12.8003 10.4419 12.6831C10.3247 12.5659 10.1658 12.5 10 12.5C9.83424 12.5 9.67527 12.5659 9.55806 12.6831C9.44085 12.8003 9.375 12.9592 9.375 13.125C9.375 13.2908 9.44085 13.4497 9.55806 13.5669C9.67527 13.6842 9.83424 13.75 10 13.75Z" fill="currentColor"/>
3
+ </svg>
@@ -1,4 +1,7 @@
1
1
  export { default as UiSnackbar } from './UiSnackbar.vue';
2
+ export { default as UiSnackbarContent } from './UiSnackbarContent.vue';
3
+ export { default as UiSnackbarIcon } from './UiSnackbarIcon.vue';
4
+ export { showSnackbar, showSnackbarPromise } from './showSnackbar';
2
5
  export { toast } from 'vue-sonner';
3
6
 
4
7
  export type * from './types';
@@ -0,0 +1,174 @@
1
+ import { h, type VNode } from 'vue';
2
+ import type { ExternalToast } from 'vue-sonner';
3
+ import { toast } from 'vue-sonner';
4
+ import UiSnackbarContent from './UiSnackbarContent.vue';
5
+ import type { UiSnackbarActionMode, UiSnackbarIconMode } from './types';
6
+
7
+ export type ShowSnackbarOptions = Omit<
8
+ ExternalToast,
9
+ 'description' | 'action' | 'icon'
10
+ > & {
11
+ /** Primary snackbar message. */
12
+ title: string;
13
+ /** Supporting context shown below the title. */
14
+ description?: string;
15
+ /** Built-in status icon mode. */
16
+ iconMode?: UiSnackbarIconMode;
17
+ /** Built-in action label. Ignored when `action` is provided. */
18
+ actionLabel?: string;
19
+ /**
20
+ * Visual mode for the built-in action button.
21
+ * @default 'default'
22
+ */
23
+ actionMode?: UiSnackbarActionMode;
24
+ /** Called when the built-in action button is clicked. */
25
+ onAction?: () => void;
26
+ /** Optional custom trailing action rendered through the action slot. */
27
+ action?: VNode;
28
+ /**
29
+ * Accessible label for the close button.
30
+ * @default 'Close toast'
31
+ */
32
+ closeButtonAriaLabel?: string;
33
+ };
34
+
35
+ /** Props passed by Sonner into custom toast renderers. */
36
+ type SnackbarToastProps = {
37
+ /** Dismiss handler wired to the embedded close button. */
38
+ onCloseToast?: () => void;
39
+ };
40
+
41
+ /**
42
+ * Display a snackbar with title, optional description, icon, and action content.
43
+ * Mount `<UiSnackbar />` once near the app root before calling this helper.
44
+ *
45
+ * Uses the default Sonner toast API for text-only messages. Switches to
46
+ * `toast.custom()` with embedded `UiSnackbarContent` when icon or action UI
47
+ * is provided.
48
+ * @param options Snackbar content and Sonner toast options.
49
+ */
50
+ export function showSnackbar(options: ShowSnackbarOptions) {
51
+ const {
52
+ title,
53
+ description,
54
+ iconMode,
55
+ actionLabel,
56
+ actionMode = 'default',
57
+ onAction,
58
+ action,
59
+ closeButton,
60
+ closeButtonAriaLabel,
61
+ ...toastOptions
62
+ } = options;
63
+ const needsCustomContent = Boolean(iconMode || actionLabel || action);
64
+ const showCloseButton = closeButton !== false;
65
+
66
+ if (needsCustomContent) {
67
+ return toast.custom(
68
+ (toastProps: SnackbarToastProps) =>
69
+ h(
70
+ UiSnackbarContent,
71
+ {
72
+ title,
73
+ description,
74
+ iconMode,
75
+ actionLabel: action ? undefined : actionLabel,
76
+ actionMode,
77
+ embedded: true,
78
+ closeButton: showCloseButton,
79
+ closeButtonAriaLabel,
80
+ onCloseToast: toastProps.onCloseToast,
81
+ ...(actionLabel && !action ? { onAction } : {}),
82
+ },
83
+ {
84
+ ...(action ? { action: () => [action] } : {}),
85
+ },
86
+ ),
87
+ {
88
+ ...toastOptions,
89
+ closeButton: showCloseButton,
90
+ },
91
+ );
92
+ }
93
+
94
+ return toast(title, {
95
+ ...toastOptions,
96
+ closeButton: showCloseButton,
97
+ ...(description ? { description } : {}),
98
+ });
99
+ }
100
+
101
+ type SnackbarMessageContent =
102
+ | string
103
+ | Pick<ShowSnackbarOptions, 'title' | 'description'>;
104
+
105
+ export type ShowSnackbarPromiseMessages<T> = {
106
+ /** Snackbar content shown while the promise is pending. */
107
+ loading: SnackbarMessageContent;
108
+ /** Snackbar content shown when the promise resolves. */
109
+ success: SnackbarMessageContent | ((data: T) => SnackbarMessageContent);
110
+ /** Snackbar content shown when the promise rejects. */
111
+ error: SnackbarMessageContent | ((error: unknown) => SnackbarMessageContent);
112
+ };
113
+
114
+ function toSnackbarContent(
115
+ message: SnackbarMessageContent,
116
+ ): Pick<ShowSnackbarOptions, 'title' | 'description'> {
117
+ return typeof message === 'string' ? { title: message } : message;
118
+ }
119
+
120
+ /**
121
+ * Track an async operation with loading, success, and error snackbars that use
122
+ * built-in status icon modes.
123
+ * @param promise Async work to monitor.
124
+ * @param messages Titles for each phase of the promise lifecycle.
125
+ * @param options Shared Sonner toast options applied to every phase.
126
+ */
127
+ export function showSnackbarPromise<T>(
128
+ promise: Promise<T> | (() => Promise<T>),
129
+ messages: ShowSnackbarPromiseMessages<T>,
130
+ options?: Omit<ShowSnackbarOptions, 'title' | 'description' | 'iconMode'>,
131
+ ) {
132
+ const toastId = showSnackbar({
133
+ ...options,
134
+ ...toSnackbarContent(messages.loading),
135
+ iconMode: 'loading',
136
+ duration: Infinity,
137
+ });
138
+
139
+ const resolvedPromise = Promise.resolve(
140
+ typeof promise === 'function' ? promise() : promise,
141
+ );
142
+
143
+ resolvedPromise
144
+ .then((data) => {
145
+ const successMessage =
146
+ typeof messages.success === 'function'
147
+ ? messages.success(data)
148
+ : messages.success;
149
+
150
+ showSnackbar({
151
+ ...options,
152
+ ...toSnackbarContent(successMessage),
153
+ id: toastId,
154
+ iconMode: 'success',
155
+ duration: options?.duration ?? 5000,
156
+ });
157
+ })
158
+ .catch((error) => {
159
+ const errorMessage =
160
+ typeof messages.error === 'function'
161
+ ? messages.error(error)
162
+ : messages.error;
163
+
164
+ showSnackbar({
165
+ ...options,
166
+ ...toSnackbarContent(errorMessage),
167
+ id: toastId,
168
+ iconMode: 'error',
169
+ duration: options?.duration ?? 5000,
170
+ });
171
+ });
172
+
173
+ return toastId;
174
+ }