@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.
- package/README.md +41 -32
- package/config.js +9 -10
- package/dist/system/components/UiSnackbar/UiSnackbar.vue.d.ts +1 -0
- package/dist/system/components/UiSnackbar/UiSnackbarContent.vue.d.ts +29 -0
- package/dist/system/components/UiSnackbar/UiSnackbarIcon.vue.d.ts +3 -0
- package/dist/system/components/UiSnackbar/index.d.ts +3 -0
- package/dist/system/components/UiSnackbar/showSnackbar.d.ts +55 -0
- package/dist/system/components/UiSnackbar/types.d.ts +76 -17
- package/dist/system/components/core/sidebar/SidebarProvider.vue.d.ts +2 -0
- package/dist/system/components/core/sidebar/utils.d.ts +1 -1
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/useDevice.d.ts +59 -0
- package/dist/system/lib.js +14655 -14319
- package/dist/system/patterns/UiSidebar/UiSidebarProvider.vue.d.ts +10 -1
- package/dist/system/patterns/UiSidebar/__tests__/sidebar-test-helpers.d.ts +55 -6
- package/dist/system/patterns/UiSidebar/index.d.ts +1 -1
- package/dist/system/patterns/UiSidebar/types.d.ts +26 -2
- package/package.json +4 -4
- package/src/@types/shims-vue.d.ts +5 -0
- package/src/components/UiButton/UiButton.stories.ts +4 -20
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +4 -20
- package/src/components/UiField/UiField.stories.ts +4 -19
- package/src/components/UiIcon/UiIcon.stories.ts +2 -0
- package/src/components/UiItem/UiItem.stories.ts +4 -19
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +281 -255
- package/src/components/UiSnackbar/UiSnackbar.vue +71 -241
- package/src/components/UiSnackbar/UiSnackbarContent.vue +114 -0
- package/src/components/UiSnackbar/UiSnackbarIcon.vue +78 -0
- package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +154 -1
- package/src/components/UiSnackbar/__tests__/showSnackbar.test.ts +258 -0
- package/src/components/UiSnackbar/assets/error.svg +3 -0
- package/src/components/UiSnackbar/assets/info.svg +3 -0
- package/src/components/UiSnackbar/assets/loading.svg +14 -0
- package/src/components/UiSnackbar/assets/success.svg +5 -0
- package/src/components/UiSnackbar/assets/warning.svg +3 -0
- package/src/components/UiSnackbar/index.ts +3 -0
- package/src/components/UiSnackbar/showSnackbar.ts +174 -0
- package/src/components/UiSnackbar/types.ts +90 -17
- package/src/components/core/sidebar/Sidebar.vue +25 -27
- package/src/components/core/sidebar/SidebarInset.vue +13 -1
- package/src/components/core/sidebar/SidebarProvider.vue +22 -2
- package/src/components/core/sidebar/SidebarTrigger.vue +2 -2
- package/src/components/core/sidebar/utils.ts +1 -1
- package/src/components/core/sonner/Sonner.vue +3 -20
- package/src/directives/vHover.stories.ts +4 -0
- package/src/index.ts +1 -0
- package/src/lib/useDevice.stories.ts +408 -0
- package/src/lib/useDevice.test.ts +129 -0
- package/src/lib/useDevice.ts +199 -0
- package/src/lib/useDrag.stories.ts +5 -1
- package/src/patterns/UiSidebar/UiSidebar.stories.ts +14 -1
- package/src/patterns/UiSidebar/UiSidebarProvider.vue +21 -1
- package/src/patterns/UiSidebar/UiSidebarTrigger.vue +39 -5
- package/src/patterns/UiSidebar/__tests__/UiSidebar.test.ts +66 -1
- package/src/patterns/UiSidebar/__tests__/UiSidebarHeader.test.ts +1 -1
- package/src/patterns/UiSidebar/__tests__/UiSidebarTrigger.test.ts +1 -1
- package/src/patterns/UiSidebar/__tests__/sidebar-test-helpers.ts +21 -0
- package/src/patterns/UiSidebar/index.ts +1 -0
- package/src/patterns/UiSidebar/types.ts +29 -2
- package/src/theme/Background.stories.ts +2 -0
- package/src/theme/Border.stories.ts +2 -0
- package/src/theme/BorderRadius.stories.ts +2 -0
- package/src/theme/Extended.stories.ts +2 -0
- package/src/theme/Flex.stories.ts +2 -0
- package/src/theme/Grid.stories.ts +2 -0
- package/src/theme/HoverLayer.stories.ts +2 -0
- package/src/theme/Overlay.stories.ts +2 -0
- package/src/theme/Shadow.stories.ts +2 -0
- package/src/theme/Theme.stories.ts +2 -0
- package/src/theme/Typography.stories.ts +2 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import 'vue-sonner/style.css';
|
|
3
|
+
import { computed } from 'vue';
|
|
3
4
|
import { Toaster as ShadcnSonner } from '@/components/core/sonner';
|
|
4
5
|
import type { UiSnackbarProps } from './types';
|
|
5
6
|
|
|
@@ -9,278 +10,107 @@ defineOptions({
|
|
|
9
10
|
|
|
10
11
|
const props = withDefaults(defineProps<UiSnackbarProps>(), {
|
|
11
12
|
containerAriaLabel: 'Notifications',
|
|
13
|
+
closeButton: true,
|
|
12
14
|
});
|
|
15
|
+
|
|
16
|
+
const toasterProps = computed(() => ({
|
|
17
|
+
...props,
|
|
18
|
+
richColors: false as const,
|
|
19
|
+
toastOptions: {
|
|
20
|
+
...props.toastOptions,
|
|
21
|
+
classes: {
|
|
22
|
+
title: 'body-14-medium text-content-on-surface-primary',
|
|
23
|
+
description: 'body-14-regular text-content-on-surface-muted',
|
|
24
|
+
...props.toastOptions?.classes,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
13
28
|
</script>
|
|
14
29
|
|
|
15
30
|
<template>
|
|
16
|
-
<ShadcnSonner v-bind="
|
|
31
|
+
<ShadcnSonner v-bind="toasterProps" />
|
|
17
32
|
</template>
|
|
18
33
|
|
|
19
34
|
<style scoped>
|
|
20
35
|
/*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* action-button and close-button state rules below have to be selector-based.
|
|
33
|
-
*
|
|
34
|
-
* Hierarchy mapping:
|
|
35
|
-
* - "High" -> `richColors: true` (vivid background)
|
|
36
|
-
* - "Low" -> `richColors: false` (muted/soft background)
|
|
37
|
-
*
|
|
38
|
-
* State mapping (per Figma "Default / Hover / Focused"):
|
|
39
|
-
* - Default -> no pseudo-class
|
|
40
|
-
* - Hover -> :hover
|
|
41
|
-
* - Focused -> :focus-visible
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/* Container shape (all variants) — Figma: padding L L L XL, gap M, banner-and-snackbars shadow */
|
|
45
|
-
:global([data-sonner-toaster] [data-sonner-toast][data-styled='true']) {
|
|
36
|
+
* Snackbar styling per Figma "Spark Design System / Snackbar".
|
|
37
|
+
* Single neutral surface — no success/error/info/warning variants.
|
|
38
|
+
*
|
|
39
|
+
* `:global()` is required because the toast list is portalled outside
|
|
40
|
+
* the component's scope.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
:global([data-sonner-toaster] [data-sonner-toast]) {
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: row;
|
|
46
|
+
align-items: flex-start;
|
|
46
47
|
padding: var(--spacing-l) var(--spacing-l) var(--spacing-l) var(--spacing-xl);
|
|
47
|
-
gap: var(--spacing-
|
|
48
|
-
|
|
49
|
-
border
|
|
48
|
+
gap: var(--spacing-xs);
|
|
49
|
+
border-radius: var(--radius);
|
|
50
|
+
border: 1px solid oklch(var(--border-surface-default));
|
|
51
|
+
background: oklch(var(--background-surface-floating));
|
|
52
|
+
color: oklch(var(--content-on-surface-primary));
|
|
50
53
|
box-shadow: var(--shadow-banner-and-snackbars);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
* Each cell mounts a real `<UiSnackbar />` and dispatches one toast on
|
|
57
|
-
* mount. The toast list anchors `<ol>` with `position: fixed` (default
|
|
58
|
-
* bottom-right) and individual toasts with `position: absolute`. Inside
|
|
59
|
-
* `.snackbar-matrix` we want them inline within the grid cell, so reset
|
|
60
|
-
* the layout to normal flow.
|
|
61
|
-
*/
|
|
62
|
-
:global(.snackbar-matrix [data-sonner-toaster]) {
|
|
63
|
-
position: relative !important;
|
|
64
|
-
inset: auto !important;
|
|
65
|
-
width: 100%;
|
|
66
|
-
transform: none !important;
|
|
67
|
-
}
|
|
68
|
-
:global(.snackbar-matrix [data-sonner-toast]) {
|
|
69
|
-
position: relative !important;
|
|
70
|
-
transform: none !important;
|
|
56
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-icon]:empty) {
|
|
57
|
+
display: none;
|
|
71
58
|
}
|
|
72
59
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
corner via `position: absolute` + transform. Override to inline. */
|
|
76
|
-
:global(
|
|
77
|
-
[data-sonner-toaster]
|
|
78
|
-
[data-sonner-toast][data-styled='true']
|
|
79
|
-
[data-close-button]
|
|
80
|
-
) {
|
|
81
|
-
position: static;
|
|
82
|
-
order: 999;
|
|
83
|
-
width: var(--spacing-xxl);
|
|
84
|
-
height: var(--spacing-xxl);
|
|
85
|
-
padding: 0;
|
|
86
|
-
border: none;
|
|
87
|
-
/* Figma: 4px (no exact Spark token; --radius-sm is 2px in this preset) */
|
|
88
|
-
border-radius: 4px;
|
|
89
|
-
background: transparent;
|
|
90
|
-
color: inherit;
|
|
91
|
-
transform: none;
|
|
92
|
-
}
|
|
93
|
-
:global(
|
|
94
|
-
[data-sonner-toaster]
|
|
95
|
-
[data-sonner-toast][data-styled='true']
|
|
96
|
-
[data-close-button]:hover
|
|
97
|
-
) {
|
|
98
|
-
/* No DS token for this hover overlay — keep literal */
|
|
99
|
-
background: rgba(255, 255, 255, 0.1);
|
|
100
|
-
}
|
|
101
|
-
:global(
|
|
102
|
-
[data-sonner-toaster]
|
|
103
|
-
[data-sonner-toast][data-styled='true']
|
|
104
|
-
[data-close-button]:focus-visible
|
|
105
|
-
) {
|
|
106
|
-
outline: 2px solid var(--core-border-focus);
|
|
107
|
-
outline-offset: 2px;
|
|
108
|
-
box-shadow: none;
|
|
60
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-icon]) {
|
|
61
|
+
color: oklch(var(--content-on-surface-primary));
|
|
109
62
|
}
|
|
110
63
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
:
|
|
114
|
-
[data-sonner-toaster]
|
|
115
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='error']
|
|
116
|
-
) {
|
|
117
|
-
background: var(--semantic-bg-error);
|
|
118
|
-
border: 1px solid var(--semantic-border-error);
|
|
119
|
-
color: var(--semantic-content-error);
|
|
120
|
-
}
|
|
121
|
-
:global(
|
|
122
|
-
[data-sonner-toaster]
|
|
123
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='error']
|
|
124
|
-
[data-button]
|
|
125
|
-
) {
|
|
126
|
-
background: var(--semantic-bg-error-action);
|
|
127
|
-
color: var(--semantic-content-error);
|
|
128
|
-
}
|
|
129
|
-
:global(
|
|
130
|
-
[data-sonner-toaster]
|
|
131
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='error']
|
|
132
|
-
[data-button]:hover
|
|
133
|
-
) {
|
|
134
|
-
background: var(--semantic-bg-error-action-hover);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/* Info High */
|
|
138
|
-
:global(
|
|
139
|
-
[data-sonner-toaster]
|
|
140
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='info']
|
|
141
|
-
) {
|
|
142
|
-
background: var(--semantic-bg-info);
|
|
143
|
-
border: 1px solid var(--semantic-border-info);
|
|
144
|
-
color: var(--semantic-content-info);
|
|
145
|
-
}
|
|
146
|
-
:global(
|
|
147
|
-
[data-sonner-toaster]
|
|
148
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='info']
|
|
149
|
-
[data-button]
|
|
150
|
-
) {
|
|
151
|
-
background: var(--semantic-bg-info-action);
|
|
152
|
-
color: var(--semantic-content-info);
|
|
64
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-content]) {
|
|
65
|
+
flex: 1;
|
|
66
|
+
min-width: 0;
|
|
153
67
|
}
|
|
154
68
|
|
|
155
|
-
|
|
156
|
-
:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
)
|
|
160
|
-
background: var(--
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
:global(
|
|
165
|
-
[data-sonner-toaster]
|
|
166
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='warning']
|
|
167
|
-
[data-button]
|
|
168
|
-
) {
|
|
169
|
-
background: var(--semantic-bg-warning-action);
|
|
170
|
-
color: var(--semantic-content-warning);
|
|
69
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-button]) {
|
|
70
|
+
order: 8;
|
|
71
|
+
align-self: center;
|
|
72
|
+
border-radius: var(--radius-sm);
|
|
73
|
+
border: 1px solid oklch(var(--border-surface-default));
|
|
74
|
+
background: oklch(var(--background-surface-muted));
|
|
75
|
+
color: oklch(var(--content-on-surface-primary));
|
|
76
|
+
padding: var(--spacing-xs) var(--spacing-m);
|
|
77
|
+
font-weight: 500;
|
|
171
78
|
}
|
|
172
79
|
|
|
173
|
-
|
|
174
|
-
:
|
|
175
|
-
[data-sonner-toaster]
|
|
176
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='success']
|
|
177
|
-
) {
|
|
178
|
-
background: var(--semantic-bg-success);
|
|
179
|
-
border: 1px solid var(--semantic-border-success);
|
|
180
|
-
color: var(--semantic-content-success);
|
|
181
|
-
}
|
|
182
|
-
:global(
|
|
183
|
-
[data-sonner-toaster]
|
|
184
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='success']
|
|
185
|
-
[data-button]
|
|
186
|
-
) {
|
|
187
|
-
background: var(--semantic-bg-success-action);
|
|
188
|
-
color: var(--semantic-content-success);
|
|
189
|
-
}
|
|
190
|
-
:global(
|
|
191
|
-
[data-sonner-toaster]
|
|
192
|
-
[data-sonner-toast][data-rich-colors='true'][data-type='success']
|
|
193
|
-
[data-button]:hover
|
|
194
|
-
) {
|
|
195
|
-
background: var(--semantic-bg-success-action-hover);
|
|
80
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-button]:hover) {
|
|
81
|
+
background: oklch(var(--overlay-hover-default));
|
|
196
82
|
}
|
|
197
83
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
:
|
|
201
|
-
|
|
202
|
-
[data-sonner-toast]:not([data-rich-colors='true'])[data-type='error']
|
|
203
|
-
) {
|
|
204
|
-
background: var(--semantic-bg-error-soft);
|
|
205
|
-
border: 1px solid var(--semantic-border-error-soft);
|
|
206
|
-
color: var(--semantic-content-error-soft);
|
|
207
|
-
}
|
|
208
|
-
:global(
|
|
209
|
-
[data-sonner-toaster]
|
|
210
|
-
[data-sonner-toast]:not([data-rich-colors='true'])[data-type='error']
|
|
211
|
-
[data-button]
|
|
212
|
-
) {
|
|
213
|
-
background: var(--semantic-bg-error-soft-action);
|
|
214
|
-
color: var(--semantic-content-error-soft);
|
|
84
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-button]:focus-visible) {
|
|
85
|
+
outline: 2px solid oklch(var(--border-surface-focus-ring));
|
|
86
|
+
outline-offset: 2px;
|
|
87
|
+
box-shadow: none;
|
|
215
88
|
}
|
|
216
89
|
|
|
217
|
-
|
|
218
|
-
:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
) {
|
|
231
|
-
background: var(--semantic-bg-info-soft-action);
|
|
232
|
-
color: var(--semantic-content-info-soft);
|
|
90
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-close-button]) {
|
|
91
|
+
position: static;
|
|
92
|
+
order: 9;
|
|
93
|
+
flex-shrink: 0;
|
|
94
|
+
align-self: center;
|
|
95
|
+
width: 20px;
|
|
96
|
+
height: 20px;
|
|
97
|
+
padding: 0;
|
|
98
|
+
border: none;
|
|
99
|
+
border-radius: var(--radius-sm);
|
|
100
|
+
background: transparent;
|
|
101
|
+
color: inherit;
|
|
102
|
+
transform: none;
|
|
233
103
|
}
|
|
234
104
|
|
|
235
|
-
|
|
236
|
-
:
|
|
237
|
-
[data-sonner-toaster]
|
|
238
|
-
[data-sonner-toast]:not([data-rich-colors='true'])[data-type='warning']
|
|
239
|
-
) {
|
|
240
|
-
background: var(--semantic-bg-warning-soft);
|
|
241
|
-
border: 1px solid var(--semantic-border-warning-soft);
|
|
242
|
-
color: var(--semantic-content-warning-soft);
|
|
243
|
-
}
|
|
244
|
-
:global(
|
|
245
|
-
[data-sonner-toaster]
|
|
246
|
-
[data-sonner-toast]:not([data-rich-colors='true'])[data-type='warning']
|
|
247
|
-
[data-button]
|
|
248
|
-
) {
|
|
249
|
-
background: var(--semantic-bg-warning-soft-action);
|
|
250
|
-
color: var(--semantic-content-warning-soft);
|
|
105
|
+
:global([data-sonner-toaster] [data-sonner-toast] [data-close-button]:hover) {
|
|
106
|
+
background: oklch(var(--overlay-hover-subtle));
|
|
251
107
|
}
|
|
252
108
|
|
|
253
|
-
/* Success Low */
|
|
254
109
|
:global(
|
|
255
|
-
[data-sonner-toaster]
|
|
256
|
-
[data-sonner-toast]:not([data-rich-colors='true'])[data-type='success']
|
|
110
|
+
[data-sonner-toaster] [data-sonner-toast] [data-close-button]:focus-visible
|
|
257
111
|
) {
|
|
258
|
-
|
|
259
|
-
border: 1px solid var(--semantic-border-success-soft);
|
|
260
|
-
color: var(--semantic-content-success-soft);
|
|
261
|
-
}
|
|
262
|
-
:global(
|
|
263
|
-
[data-sonner-toaster]
|
|
264
|
-
[data-sonner-toast]:not([data-rich-colors='true'])[data-type='success']
|
|
265
|
-
[data-button]
|
|
266
|
-
) {
|
|
267
|
-
background: var(--semantic-bg-success-soft-action);
|
|
268
|
-
color: var(--semantic-content-success-soft);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/* Focus state on action button (Figma "Focused") */
|
|
272
|
-
:global([data-sonner-toaster] [data-sonner-toast] [data-button]:focus-visible) {
|
|
273
|
-
outline: 2px solid var(--core-border-focus);
|
|
112
|
+
outline: 2px solid oklch(var(--border-surface-focus-ring));
|
|
274
113
|
outline-offset: 2px;
|
|
275
114
|
box-shadow: none;
|
|
276
115
|
}
|
|
277
|
-
|
|
278
|
-
/* Hover state for Low hierarchy action button (Figma shows ~80% opacity) */
|
|
279
|
-
:global(
|
|
280
|
-
[data-sonner-toaster]
|
|
281
|
-
[data-sonner-toast]:not([data-rich-colors='true'])
|
|
282
|
-
[data-button]:hover
|
|
283
|
-
) {
|
|
284
|
-
opacity: 0.8;
|
|
285
|
-
}
|
|
286
116
|
</style>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useSlots } from 'vue';
|
|
3
|
+
import { UiButton } from '@/components/UiButton';
|
|
4
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
5
|
+
import { cn } from '@/lib/utils';
|
|
6
|
+
import UiSnackbarIcon from './UiSnackbarIcon.vue';
|
|
7
|
+
import type { UiSnackbarContentProps, UiSnackbarContentSlots } from './types';
|
|
8
|
+
|
|
9
|
+
defineOptions({
|
|
10
|
+
name: 'UiSnackbarContent',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
defineSlots<UiSnackbarContentSlots>();
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(defineProps<UiSnackbarContentProps>(), {
|
|
16
|
+
description: undefined,
|
|
17
|
+
iconMode: undefined,
|
|
18
|
+
actionLabel: undefined,
|
|
19
|
+
actionMode: 'default',
|
|
20
|
+
embedded: false,
|
|
21
|
+
closeButton: true,
|
|
22
|
+
closeButtonAriaLabel: 'Close toast',
|
|
23
|
+
onCloseToast: undefined,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{
|
|
27
|
+
/** Emitted when the built-in action button is clicked. */
|
|
28
|
+
action: [];
|
|
29
|
+
}>();
|
|
30
|
+
|
|
31
|
+
const slots = useSlots();
|
|
32
|
+
|
|
33
|
+
const actionButtonVariant = computed(() =>
|
|
34
|
+
props.actionMode === 'secondary' ? 'secondary' : 'default',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const hasAction = computed(
|
|
38
|
+
() => Boolean(props.actionLabel) || Boolean(slots.action),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const showCloseButton = computed(
|
|
42
|
+
() => props.embedded && props.closeButton && Boolean(props.onCloseToast),
|
|
43
|
+
);
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<div
|
|
48
|
+
:class="
|
|
49
|
+
cn(
|
|
50
|
+
'flex min-w-0 items-center gap-xs',
|
|
51
|
+
props.embedded ? 'flex-1' : 'w-full',
|
|
52
|
+
!props.embedded &&
|
|
53
|
+
'rounded border border-border-surface-default bg-background-surface-floating p-l pl-xl shadow-banner-and-snackbars',
|
|
54
|
+
)
|
|
55
|
+
"
|
|
56
|
+
data-slot="snackbar-content"
|
|
57
|
+
data-testid="snackbar-content"
|
|
58
|
+
>
|
|
59
|
+
<div
|
|
60
|
+
v-if="props.iconMode"
|
|
61
|
+
class="flex size-4 shrink-0 items-center justify-center"
|
|
62
|
+
data-slot="snackbar-icon"
|
|
63
|
+
>
|
|
64
|
+
<UiSnackbarIcon :mode="props.iconMode" />
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<div class="flex min-w-0 flex-1 flex-col gap-[var(--spacing-3xs)]">
|
|
68
|
+
<p
|
|
69
|
+
class="body-14-medium text-content-on-surface-primary"
|
|
70
|
+
data-slot="snackbar-title"
|
|
71
|
+
>
|
|
72
|
+
{{ props.title }}
|
|
73
|
+
</p>
|
|
74
|
+
<p
|
|
75
|
+
v-if="props.description || $slots.description"
|
|
76
|
+
class="body-14-regular text-content-on-surface-muted"
|
|
77
|
+
data-slot="snackbar-description"
|
|
78
|
+
>
|
|
79
|
+
<slot name="description">{{ props.description }}</slot>
|
|
80
|
+
</p>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div
|
|
84
|
+
v-if="hasAction || showCloseButton"
|
|
85
|
+
class="ml-auto flex shrink-0 items-center gap-xs self-center"
|
|
86
|
+
data-slot="snackbar-trailing-actions"
|
|
87
|
+
>
|
|
88
|
+
<div v-if="hasAction" class="shrink-0" data-slot="snackbar-action">
|
|
89
|
+
<slot name="action">
|
|
90
|
+
<UiButton
|
|
91
|
+
v-if="props.actionLabel"
|
|
92
|
+
:variant="actionButtonVariant"
|
|
93
|
+
size="sm"
|
|
94
|
+
data-slot="snackbar-action-button"
|
|
95
|
+
@click="emit('action')"
|
|
96
|
+
>
|
|
97
|
+
{{ props.actionLabel }}
|
|
98
|
+
</UiButton>
|
|
99
|
+
</slot>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<button
|
|
103
|
+
v-if="showCloseButton"
|
|
104
|
+
type="button"
|
|
105
|
+
data-slot="snackbar-close-button"
|
|
106
|
+
class="inline-flex size-5 shrink-0 items-center justify-center rounded-sm border-none bg-transparent p-0 text-inherit hover:bg-overlay-hover-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-border-surface-focus-ring"
|
|
107
|
+
:aria-label="props.closeButtonAriaLabel"
|
|
108
|
+
@click="props.onCloseToast"
|
|
109
|
+
>
|
|
110
|
+
<UiIcon name="x" size="s" />
|
|
111
|
+
</button>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { cn } from '@/lib/utils';
|
|
4
|
+
import type { UiSnackbarIconMode, UiSnackbarIconProps } from './types';
|
|
5
|
+
import errorIcon from './assets/error.svg?raw';
|
|
6
|
+
import infoIcon from './assets/info.svg?raw';
|
|
7
|
+
import loadingIcon from './assets/loading.svg?raw';
|
|
8
|
+
import successIcon from './assets/success.svg?raw';
|
|
9
|
+
import warningIcon from './assets/warning.svg?raw';
|
|
10
|
+
|
|
11
|
+
defineOptions({
|
|
12
|
+
name: 'UiSnackbarIcon',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const props = defineProps<UiSnackbarIconProps>();
|
|
16
|
+
|
|
17
|
+
const ICONS: Record<UiSnackbarIconMode, string> = {
|
|
18
|
+
success: successIcon,
|
|
19
|
+
info: infoIcon,
|
|
20
|
+
warning: warningIcon,
|
|
21
|
+
error: errorIcon,
|
|
22
|
+
loading: loadingIcon,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const DEFAULT_LABELS: Record<UiSnackbarIconMode, string> = {
|
|
26
|
+
success: 'Success',
|
|
27
|
+
info: 'Information',
|
|
28
|
+
warning: 'Warning',
|
|
29
|
+
error: 'Error',
|
|
30
|
+
loading: 'Loading',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Status icon colors on the neutral snackbar surface.
|
|
35
|
+
* `content-on-status-success|warning|error` are light foreground tokens for
|
|
36
|
+
* status backgrounds (white on light mode), so icon tints use the matching
|
|
37
|
+
* `background-status-*` / `content-on-status-info|neutral` tokens instead.
|
|
38
|
+
*/
|
|
39
|
+
const STATUS_COLOR_VARS: Record<UiSnackbarIconMode, string> = {
|
|
40
|
+
success: '--background-status-success',
|
|
41
|
+
info: '--content-on-status-info',
|
|
42
|
+
warning: '--background-status-warning',
|
|
43
|
+
error: '--background-status-error',
|
|
44
|
+
loading: '--content-on-status-neutral',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const svgMarkup = computed(() => ICONS[props.mode]);
|
|
48
|
+
|
|
49
|
+
const ariaLabel = computed(() => props.ariaLabel ?? DEFAULT_LABELS[props.mode]);
|
|
50
|
+
|
|
51
|
+
const iconColorStyle = computed(() => ({
|
|
52
|
+
color: `oklch(var(${STATUS_COLOR_VARS[props.mode]}))`,
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const isLoading = computed(() => props.mode === 'loading');
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<span
|
|
60
|
+
data-slot="snackbar-mode-icon"
|
|
61
|
+
:data-mode="props.mode"
|
|
62
|
+
:style="iconColorStyle"
|
|
63
|
+
:class="
|
|
64
|
+
cn(
|
|
65
|
+
'inline-flex size-4 shrink-0 items-center justify-center',
|
|
66
|
+
isLoading && 'animate-spin motion-reduce:animate-none',
|
|
67
|
+
)
|
|
68
|
+
"
|
|
69
|
+
:role="isLoading ? 'status' : 'img'"
|
|
70
|
+
:aria-label="ariaLabel"
|
|
71
|
+
>
|
|
72
|
+
<span
|
|
73
|
+
class="block size-4 text-inherit [&>svg]:block [&>svg]:size-4"
|
|
74
|
+
aria-hidden="true"
|
|
75
|
+
v-html="svgMarkup"
|
|
76
|
+
/>
|
|
77
|
+
</span>
|
|
78
|
+
</template>
|