@aleph-alpha/ui-library 2.0.0 → 2.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/config.d.ts +0 -19
- package/config.js +65 -81
- package/dist/system/components/UiSnackbar/UiSnackbar.vue.d.ts +5 -0
- package/dist/system/components/UiSnackbar/index.d.ts +3 -0
- package/dist/system/components/UiSnackbar/types.d.ts +96 -0
- package/dist/system/components/core/sonner/Sonner.vue.d.ts +3 -0
- package/dist/system/components/core/sonner/index.d.ts +1 -0
- package/dist/system/components/index.d.ts +1 -1
- package/dist/system/index.d.ts +3 -4
- package/dist/system/lib.js +20658 -19240
- package/dist/system/patterns/UiSidebar/UiSidebarGroupLabel.vue.d.ts +6 -6
- package/dist/system/patterns/UiSidebar/activeIndicator.d.ts +1 -2
- package/dist/system/patterns/UiSidebar/index.d.ts +1 -3
- package/dist/system/patterns/UiSidebar/types.d.ts +1 -95
- package/docs/public-docs/foundations.md +48 -38
- package/hover-mix.d.ts +8 -11
- package/hover-mix.js +7 -15
- package/package.json +6 -4
- package/src/components/UiAccordion/UiAccordion.stories.ts +2 -2
- package/src/components/UiAlert/UiAlert.stories.ts +4 -4
- package/src/components/UiAvatar/UiAvatar.stories.ts +2 -2
- package/src/components/UiButton/UiButton.stories.ts +1 -1
- package/src/components/UiCalendar/UiCalendar.stories.ts +1 -24
- package/src/components/UiCalendar/UiCalendar.vue +16 -0
- package/src/components/UiCard/UiCard.stories.ts +4 -4
- package/src/components/UiChip/UiChip.vue +1 -1
- package/src/components/UiDrawer/UiDrawer.stories.ts +6 -6
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +4 -4
- package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +70 -3
- package/src/components/UiEmpty/UiEmpty.stories.ts +1 -0
- package/src/components/UiFileItem/UiFileItem.vue +1 -1
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +4 -1
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +2 -2
- package/src/components/UiIcon/UiIcon.stories.ts +90 -18
- package/src/components/UiInput/UiInput.stories.ts +2 -2
- package/src/components/UiKbd/UiKbd.stories.ts +10 -10
- package/src/components/UiLabel/UiLabel.stories.ts +2 -2
- package/src/components/UiListbox/UiListbox.stories.ts +14 -14
- package/src/components/UiListbox/UiListbox.vue +16 -0
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +24 -13
- package/src/components/UiPopover/UiPopover.stories.ts +6 -6
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +22 -22
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +11 -22
- package/src/components/UiRangeCalendar/UiRangeCalendar.vue +16 -0
- package/src/components/UiSelect/UiSelectItem.vue +1 -1
- package/src/components/UiSeparator/UiSeparator.stories.ts +8 -8
- package/src/components/UiSheet/UiSheet.stories.ts +12 -12
- package/src/components/UiSkeleton/UiSkeleton.stories.ts +20 -20
- package/src/components/UiSlider/UiSlider.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +508 -0
- package/src/components/UiSnackbar/UiSnackbar.vue +286 -0
- package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +17 -0
- package/src/components/UiSnackbar/index.ts +4 -0
- package/src/components/UiSnackbar/types.ts +97 -0
- package/src/components/UiSwitch/UiSwitch.stories.ts +4 -4
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +9 -2
- package/src/components/UiTable/__tests__/UiTableRow.test.ts +10 -0
- package/src/components/UiTabs/UiTabs.stories.ts +2 -2
- package/src/components/UiTabs/__tests__/UiTabs.test.ts +25 -0
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +2 -0
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +9 -0
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +18 -0
- package/src/components/UiTooltip/UiTooltip.stories.ts +7 -7
- package/src/components/core/alert/index.ts +3 -2
- package/src/components/core/button/index.ts +5 -6
- package/src/components/core/calendar/CalendarGrid.vue +1 -1
- package/src/components/core/card/Card.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +14 -13
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +23 -13
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/popover/PopoverContent.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendarGrid.vue +1 -1
- package/src/components/core/select/SelectItem.vue +1 -1
- package/src/components/core/sidebar/SidebarGroupAction.vue +1 -1
- package/src/components/core/sidebar/SidebarMenuAction.vue +1 -1
- package/src/components/core/sidebar/SidebarMenuSubButton.vue +2 -2
- package/src/components/core/sidebar/SidebarTrigger.vue +4 -4
- package/src/components/core/sidebar/index.ts +4 -3
- package/src/components/core/sonner/Sonner.vue +43 -0
- package/src/components/core/sonner/index.ts +1 -0
- package/src/components/core/switch/Switch.vue +2 -2
- package/src/components/core/table/TableRow.vue +1 -1
- package/src/components/core/tabs/TabsList.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/core/toggle/index.ts +1 -1
- package/src/components/core/toggle-group/index.ts +1 -1
- package/src/components/index.ts +1 -1
- package/src/directives/vHover.stories.ts +1 -1
- package/src/index.ts +3 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +15 -15
- package/src/patterns/UiDataTable/UiDataTableColumnHeader.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTablePagination.vue +3 -3
- package/src/patterns/UiDataTable/UiDataTableToolbar.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +14 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +4 -4
- package/src/patterns/UiDatePicker/UiDatePicker.vue +2 -0
- package/src/patterns/UiSidebar/UiSidebar.stories.ts +27 -258
- package/src/patterns/UiSidebar/UiSidebarGroup.stories.ts +6 -8
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +15 -10
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.vue +20 -7
- package/src/patterns/UiSidebar/UiSidebarHeader.vue +0 -1
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +29 -40
- package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +9 -6
- package/src/patterns/UiSidebar/UiSidebarMenuItem.stories.ts +11 -13
- package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +8 -5
- package/src/patterns/UiSidebar/UiSidebarPopoverMenu.stories.ts +6 -8
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.stories.ts +6 -7
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +9 -7
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.stories.ts +3 -3
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +11 -12
- package/src/patterns/UiSidebar/UiSidebarTrigger.vue +1 -1
- package/src/patterns/UiSidebar/activeIndicator.ts +1 -2
- package/src/patterns/UiSidebar/index.ts +0 -5
- package/src/patterns/UiSidebar/types.ts +1 -111
- package/src/theme/Background.stories.ts +5 -5
- package/src/theme/Border.stories.ts +3 -3
- package/src/theme/Extended.stories.ts +6 -6
- package/src/theme/Flex.stories.ts +10 -10
- package/src/theme/Grid.stories.ts +10 -10
- package/src/theme/HoverLayer.stories.ts +215 -0
- package/src/theme/Overlay.stories.ts +2 -2
- package/src/theme/Shadow.stories.ts +1 -1
- package/src/theme/Theme.stories.ts +4 -4
- package/src/theme/Typography.stories.ts +21 -21
- package/tokens.json +4835 -1369
- package/dist/system/components/UiIconButton/UiIconButton.vue.d.ts +0 -25
- package/dist/system/components/UiIconButton/index.d.ts +0 -7
- package/dist/system/components/UiIconButton/types.d.ts +0 -67
- package/dist/system/patterns/UiSidebar/UiSidebarChatHistory.vue.d.ts +0 -20
- package/dist/system/patterns/UiSidebar/UiSidebarChatHistoryItem.vue.d.ts +0 -34
- package/src/components/UiIconButton/UiIconButton.stories.ts +0 -470
- package/src/components/UiIconButton/UiIconButton.vue +0 -76
- package/src/components/UiIconButton/__tests__/UiIconButton.test.ts +0 -105
- package/src/components/UiIconButton/index.ts +0 -13
- package/src/components/UiIconButton/types.ts +0 -87
- package/src/patterns/UiSidebar/UiSidebarChatHistory.stories.ts +0 -104
- package/src/patterns/UiSidebar/UiSidebarChatHistory.vue +0 -43
- package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.stories.ts +0 -204
- package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.vue +0 -269
- package/src/patterns/UiSidebar/__tests__/UiSidebarChatHistory.test.ts +0 -35
- package/src/patterns/UiSidebar/__tests__/UiSidebarChatHistoryItem.test.ts +0 -49
- package/src/theme/BackgroundHover.stories.ts +0 -182
- package/src/theme/ContentHover.stories.ts +0 -171
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { onMounted, ref } from 'vue';
|
|
3
|
+
import { toast, UiSnackbar } from './index';
|
|
4
|
+
import { UiButton } from '../UiButton';
|
|
5
|
+
import { UiDialog, UiDialogContent, UiDialogTrigger } from '../UiDialog';
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof UiSnackbar> = {
|
|
8
|
+
title: 'Components/UiSnackbar',
|
|
9
|
+
component: UiSnackbar,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
argTypes: {
|
|
12
|
+
position: {
|
|
13
|
+
control: 'select',
|
|
14
|
+
options: [
|
|
15
|
+
'top-left',
|
|
16
|
+
'top-right',
|
|
17
|
+
'bottom-left',
|
|
18
|
+
'bottom-right',
|
|
19
|
+
'top-center',
|
|
20
|
+
'bottom-center',
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
theme: {
|
|
24
|
+
control: 'select',
|
|
25
|
+
options: ['light', 'dark', 'system'],
|
|
26
|
+
},
|
|
27
|
+
richColors: {
|
|
28
|
+
control: 'boolean',
|
|
29
|
+
description:
|
|
30
|
+
'High hierarchy (vivid background) when true, Low/Soft hierarchy when false.',
|
|
31
|
+
},
|
|
32
|
+
expand: { control: 'boolean' },
|
|
33
|
+
closeButton: { control: 'boolean' },
|
|
34
|
+
duration: { control: 'number' },
|
|
35
|
+
visibleToasts: { control: 'number' },
|
|
36
|
+
containerAriaLabel: { control: 'text' },
|
|
37
|
+
},
|
|
38
|
+
args: {
|
|
39
|
+
position: 'bottom-right',
|
|
40
|
+
theme: 'light',
|
|
41
|
+
richColors: true,
|
|
42
|
+
expand: false,
|
|
43
|
+
closeButton: true,
|
|
44
|
+
visibleToasts: 3,
|
|
45
|
+
containerAriaLabel: 'Notifications',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default meta;
|
|
50
|
+
type Story = StoryObj<typeof UiSnackbar>;
|
|
51
|
+
|
|
52
|
+
const FIGMA_MESSAGE = 'You have a new notification.';
|
|
53
|
+
const FIGMA_ACTION_LABEL = 'Action';
|
|
54
|
+
|
|
55
|
+
const noopAction = {
|
|
56
|
+
label: FIGMA_ACTION_LABEL,
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
onClick: () => console.log('Action clicked'),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type TypedSnackbar = 'success' | 'info' | 'warning' | 'error';
|
|
62
|
+
|
|
63
|
+
function showTypedSnackbar(
|
|
64
|
+
type: TypedSnackbar,
|
|
65
|
+
toasterId: string,
|
|
66
|
+
richColors: boolean,
|
|
67
|
+
) {
|
|
68
|
+
return toast[type](FIGMA_MESSAGE, {
|
|
69
|
+
toasterId,
|
|
70
|
+
richColors,
|
|
71
|
+
action: noopAction,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function makeTypedStory(
|
|
76
|
+
type: TypedSnackbar,
|
|
77
|
+
hierarchy: 'high' | 'low',
|
|
78
|
+
storyName: string,
|
|
79
|
+
): Story {
|
|
80
|
+
const richColors = hierarchy === 'high';
|
|
81
|
+
const toasterId = `story-${type}-${hierarchy}`;
|
|
82
|
+
const buttonLabel = `${type[0].toUpperCase()}${type.slice(1)} ${
|
|
83
|
+
hierarchy === 'high' ? 'High' : 'Low'
|
|
84
|
+
}`;
|
|
85
|
+
const sourceCode = `<script setup lang="ts">
|
|
86
|
+
import { UiSnackbar, toast, UiButton } from '@aleph-alpha/ui-library'
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<UiButton
|
|
91
|
+
@click="toast.${type}('${FIGMA_MESSAGE}', {
|
|
92
|
+
richColors: ${richColors},
|
|
93
|
+
action: { label: '${FIGMA_ACTION_LABEL}', onClick: () => {} },
|
|
94
|
+
})"
|
|
95
|
+
>
|
|
96
|
+
${buttonLabel}
|
|
97
|
+
</UiButton>
|
|
98
|
+
<UiSnackbar close-button${richColors ? ' rich-colors' : ''} />
|
|
99
|
+
</template>`;
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
name: storyName,
|
|
103
|
+
args: { richColors, closeButton: true },
|
|
104
|
+
render: (args) => ({
|
|
105
|
+
components: { UiSnackbar, UiButton },
|
|
106
|
+
setup() {
|
|
107
|
+
const show = () => showTypedSnackbar(type, toasterId, args.richColors);
|
|
108
|
+
return { args, show, toasterId, buttonLabel };
|
|
109
|
+
},
|
|
110
|
+
template: `
|
|
111
|
+
<div>
|
|
112
|
+
<UiButton @click="show">{{ buttonLabel }}</UiButton>
|
|
113
|
+
<UiSnackbar v-bind="args" :id="toasterId" />
|
|
114
|
+
</div>
|
|
115
|
+
`,
|
|
116
|
+
}),
|
|
117
|
+
parameters: {
|
|
118
|
+
docs: {
|
|
119
|
+
source: { code: sourceCode },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Confirm that an operation succeeded - use as the primary success signal
|
|
127
|
+
* (saved, sent, completed). High hierarchy: vivid green for emphasis.
|
|
128
|
+
*/
|
|
129
|
+
export const SuccessHigh: Story = makeTypedStory(
|
|
130
|
+
'success',
|
|
131
|
+
'high',
|
|
132
|
+
'Success High',
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Confirm a non-critical success in a quieter tone - background-task
|
|
137
|
+
* acknowledgements, autosave, sync complete.
|
|
138
|
+
*/
|
|
139
|
+
export const SuccessLow: Story = makeTypedStory(
|
|
140
|
+
'success',
|
|
141
|
+
'low',
|
|
142
|
+
'Success Low',
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Surface neutral information that needs immediate attention - reminders,
|
|
147
|
+
* tips, system announcements.
|
|
148
|
+
*/
|
|
149
|
+
export const InfoHigh: Story = makeTypedStory('info', 'high', 'Info High');
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Surface neutral information that doesn't compete with primary content -
|
|
153
|
+
* inline help, contextual hints.
|
|
154
|
+
*/
|
|
155
|
+
export const InfoLow: Story = makeTypedStory('info', 'low', 'Info Low');
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Warn the user about a non-blocking caution - quota nearing limit, an action
|
|
159
|
+
* has consequences. Use when the user can still proceed.
|
|
160
|
+
*/
|
|
161
|
+
export const WarningHigh: Story = makeTypedStory(
|
|
162
|
+
'warning',
|
|
163
|
+
'high',
|
|
164
|
+
'Warning High',
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Quieter warning for informational caution that doesn't require immediate
|
|
169
|
+
* action.
|
|
170
|
+
*/
|
|
171
|
+
export const WarningLow: Story = makeTypedStory(
|
|
172
|
+
'warning',
|
|
173
|
+
'low',
|
|
174
|
+
'Warning Low',
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Report a failure or rejected action - upload failed, request errored, save
|
|
179
|
+
* blocked. High hierarchy: vivid red for unmistakable signal.
|
|
180
|
+
*/
|
|
181
|
+
export const ErrorHigh: Story = makeTypedStory('error', 'high', 'Error High');
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Report a recoverable error in a less alarming tone - retry suggestions,
|
|
185
|
+
* non-critical failures.
|
|
186
|
+
*/
|
|
187
|
+
export const ErrorLow: Story = makeTypedStory('error', 'low', 'Error Low');
|
|
188
|
+
|
|
189
|
+
const allVariantsTemplateSource = `<script setup lang="ts">
|
|
190
|
+
import { UiSnackbar, toast } from '@aleph-alpha/ui-library'
|
|
191
|
+
|
|
192
|
+
// Show one snackbar per type x hierarchy via toast.<type>(msg, { richColors })
|
|
193
|
+
toast.error('You have a new notification.', { richColors: true, action: { label: 'Action', onClick: () => {} } })
|
|
194
|
+
toast.info('You have a new notification.', { richColors: true, action: { label: 'Action', onClick: () => {} } })
|
|
195
|
+
// ... and so on for warning, success, plus richColors: false versions
|
|
196
|
+
</script>
|
|
197
|
+
|
|
198
|
+
<template>
|
|
199
|
+
<UiSnackbar close-button rich-colors />
|
|
200
|
+
</template>`;
|
|
201
|
+
|
|
202
|
+
type MatrixCell = {
|
|
203
|
+
type: TypedSnackbar;
|
|
204
|
+
hierarchy: 'high' | 'low';
|
|
205
|
+
id: string;
|
|
206
|
+
label: string;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const ALL_CELLS: MatrixCell[] = (
|
|
210
|
+
['error', 'info', 'warning', 'success'] as const
|
|
211
|
+
).flatMap((type) =>
|
|
212
|
+
(['low', 'high'] as const).map((hierarchy) => ({
|
|
213
|
+
type,
|
|
214
|
+
hierarchy,
|
|
215
|
+
id: `matrix-${type}-${hierarchy}`,
|
|
216
|
+
label: `${type[0].toUpperCase()}${type.slice(1)} ${
|
|
217
|
+
hierarchy === 'high' ? 'High' : 'Low'
|
|
218
|
+
}`,
|
|
219
|
+
})),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Side-by-side overview of every type x hierarchy combination from the Figma
|
|
224
|
+
* matrix. Each cell mounts a real `<UiSnackbar />` and dispatches one toast
|
|
225
|
+
* with `duration: Infinity` on mount, so what you see is the actual component,
|
|
226
|
+
* not a static mock.
|
|
227
|
+
*/
|
|
228
|
+
export const AllVariants: Story = {
|
|
229
|
+
name: 'AllVariants',
|
|
230
|
+
parameters: {
|
|
231
|
+
docs: {
|
|
232
|
+
source: { code: allVariantsTemplateSource },
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
render: () => ({
|
|
236
|
+
components: { UiSnackbar },
|
|
237
|
+
setup() {
|
|
238
|
+
onMounted(() => {
|
|
239
|
+
ALL_CELLS.forEach((cell) => {
|
|
240
|
+
toast[cell.type](FIGMA_MESSAGE, {
|
|
241
|
+
toasterId: cell.id,
|
|
242
|
+
richColors: cell.hierarchy === 'high',
|
|
243
|
+
duration: Infinity,
|
|
244
|
+
action: noopAction,
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
return { cells: ALL_CELLS };
|
|
249
|
+
},
|
|
250
|
+
template: `
|
|
251
|
+
<div class="snackbar-matrix grid grid-cols-1 md:grid-cols-2 gap-4 p-4">
|
|
252
|
+
<div
|
|
253
|
+
v-for="cell in cells"
|
|
254
|
+
:key="cell.id"
|
|
255
|
+
class="flex flex-col gap-2"
|
|
256
|
+
>
|
|
257
|
+
<span class="text-content-on-surface-secondary text-xs">
|
|
258
|
+
{{ cell.label }}
|
|
259
|
+
</span>
|
|
260
|
+
<UiSnackbar
|
|
261
|
+
:id="cell.id"
|
|
262
|
+
:rich-colors="cell.hierarchy === 'high'"
|
|
263
|
+
close-button
|
|
264
|
+
expand
|
|
265
|
+
:visible-toasts="1"
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
`,
|
|
270
|
+
}),
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const defaultTemplateSource = `<script setup lang="ts">
|
|
274
|
+
import { UiSnackbar, toast, UiButton } from '@aleph-alpha/ui-library'
|
|
275
|
+
</script>
|
|
276
|
+
|
|
277
|
+
<template>
|
|
278
|
+
<UiButton @click="toast('My first snackbar')">Show snackbar</UiButton>
|
|
279
|
+
<UiSnackbar />
|
|
280
|
+
</template>`;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Plain (untyped) snackbar without a status icon - use for neutral
|
|
284
|
+
* confirmations that don't fit success/info/warning/error semantics. Falls
|
|
285
|
+
* back to the project's inverse surface tokens for contrast.
|
|
286
|
+
*/
|
|
287
|
+
export const Default: Story = {
|
|
288
|
+
args: { richColors: false, closeButton: false },
|
|
289
|
+
render: (args) => ({
|
|
290
|
+
components: { UiSnackbar, UiButton },
|
|
291
|
+
setup() {
|
|
292
|
+
const toasterId = 'story-default';
|
|
293
|
+
const show = () => toast('My first snackbar', { toasterId });
|
|
294
|
+
return { args, show, toasterId };
|
|
295
|
+
},
|
|
296
|
+
template: `
|
|
297
|
+
<div>
|
|
298
|
+
<UiButton @click="show">Show snackbar</UiButton>
|
|
299
|
+
<UiSnackbar v-bind="args" :id="toasterId" />
|
|
300
|
+
</div>
|
|
301
|
+
`,
|
|
302
|
+
}),
|
|
303
|
+
parameters: {
|
|
304
|
+
docs: {
|
|
305
|
+
source: { code: defaultTemplateSource },
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const withDescriptionTemplateSource = `<script setup lang="ts">
|
|
311
|
+
import { UiSnackbar, toast, UiButton } from '@aleph-alpha/ui-library'
|
|
312
|
+
</script>
|
|
313
|
+
|
|
314
|
+
<template>
|
|
315
|
+
<UiButton
|
|
316
|
+
@click="toast('Event has been created', {
|
|
317
|
+
description: 'Sunday, December 03, 2023 at 9:00 AM',
|
|
318
|
+
action: { label: 'Undo', onClick: () => console.log('Undo') },
|
|
319
|
+
})"
|
|
320
|
+
>
|
|
321
|
+
Show snackbar
|
|
322
|
+
</UiButton>
|
|
323
|
+
<UiSnackbar />
|
|
324
|
+
</template>`;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Use when the message needs supporting context (timestamp, location, related
|
|
328
|
+
* record). Not in the current Figma design but supported by the underlying API.
|
|
329
|
+
*/
|
|
330
|
+
export const WithDescription: Story = {
|
|
331
|
+
args: { richColors: false, closeButton: false },
|
|
332
|
+
render: (args) => ({
|
|
333
|
+
components: { UiSnackbar, UiButton },
|
|
334
|
+
setup() {
|
|
335
|
+
const toasterId = 'story-description';
|
|
336
|
+
const show = () =>
|
|
337
|
+
toast('Event has been created', {
|
|
338
|
+
toasterId,
|
|
339
|
+
description: 'Sunday, December 03, 2023 at 9:00 AM',
|
|
340
|
+
action: {
|
|
341
|
+
label: 'Undo',
|
|
342
|
+
// eslint-disable-next-line no-console
|
|
343
|
+
onClick: () => console.log('Undo'),
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
return { args, show, toasterId };
|
|
347
|
+
},
|
|
348
|
+
template: `
|
|
349
|
+
<div>
|
|
350
|
+
<UiButton @click="show">Show snackbar</UiButton>
|
|
351
|
+
<UiSnackbar v-bind="args" :id="toasterId" />
|
|
352
|
+
</div>
|
|
353
|
+
`,
|
|
354
|
+
}),
|
|
355
|
+
parameters: {
|
|
356
|
+
docs: {
|
|
357
|
+
source: { code: withDescriptionTemplateSource },
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const promiseTemplateSource = `<script setup lang="ts">
|
|
363
|
+
import { UiSnackbar, toast, UiButton } from '@aleph-alpha/ui-library'
|
|
364
|
+
|
|
365
|
+
function handlePromiseClick() {
|
|
366
|
+
toast.promise<{ name: string }>(
|
|
367
|
+
() => new Promise((resolve) => setTimeout(() => resolve({ name: 'Event' }), 2000)),
|
|
368
|
+
{
|
|
369
|
+
loading: 'Loading...',
|
|
370
|
+
success: (data) => \`\${data.name} has been created\`,
|
|
371
|
+
error: 'Error',
|
|
372
|
+
},
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
</script>
|
|
376
|
+
|
|
377
|
+
<template>
|
|
378
|
+
<UiButton @click="handlePromiseClick">Show promise snackbar</UiButton>
|
|
379
|
+
<UiSnackbar />
|
|
380
|
+
</template>`;
|
|
381
|
+
|
|
382
|
+
function resolveAfter<T>(value: T, ms: number): Promise<T> {
|
|
383
|
+
return new window.Promise((resolve) => setTimeout(() => resolve(value), ms));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Use to track an async operation - shows loading, then transitions to success
|
|
388
|
+
* or error based on the promise outcome. Good for save/upload flows where you
|
|
389
|
+
* want one snackbar to tell the whole story.
|
|
390
|
+
*/
|
|
391
|
+
export const PromiseSnackbar: Story = {
|
|
392
|
+
name: 'Promise',
|
|
393
|
+
render: (args) => ({
|
|
394
|
+
components: { UiSnackbar, UiButton },
|
|
395
|
+
setup() {
|
|
396
|
+
const toasterId = 'story-promise';
|
|
397
|
+
const show = () => {
|
|
398
|
+
toast.promise<{ name: string }>(
|
|
399
|
+
() => resolveAfter({ name: 'Event' }, 2000),
|
|
400
|
+
{
|
|
401
|
+
toasterId,
|
|
402
|
+
loading: 'Loading...',
|
|
403
|
+
success: (data) => `${data.name} has been created`,
|
|
404
|
+
error: 'Error',
|
|
405
|
+
},
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
return { args, show, toasterId };
|
|
409
|
+
},
|
|
410
|
+
template: `
|
|
411
|
+
<div>
|
|
412
|
+
<UiButton @click="show">Show promise snackbar</UiButton>
|
|
413
|
+
<UiSnackbar v-bind="args" :id="toasterId" />
|
|
414
|
+
</div>
|
|
415
|
+
`,
|
|
416
|
+
}),
|
|
417
|
+
parameters: {
|
|
418
|
+
docs: {
|
|
419
|
+
source: { code: promiseTemplateSource },
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const withDialogTemplateSource = `<script setup lang="ts">
|
|
425
|
+
import {
|
|
426
|
+
UiSnackbar,
|
|
427
|
+
toast,
|
|
428
|
+
UiButton,
|
|
429
|
+
UiDialog,
|
|
430
|
+
UiDialogTrigger,
|
|
431
|
+
UiDialogContent,
|
|
432
|
+
} from '@aleph-alpha/ui-library'
|
|
433
|
+
|
|
434
|
+
function handleInteractOutside(event: Event) {
|
|
435
|
+
const target = event.target as HTMLElement
|
|
436
|
+
if (target?.closest('[data-sonner-toaster]')) event.preventDefault()
|
|
437
|
+
}
|
|
438
|
+
</script>
|
|
439
|
+
|
|
440
|
+
<template>
|
|
441
|
+
<UiDialog>
|
|
442
|
+
<UiDialogTrigger as-child>
|
|
443
|
+
<UiButton variant="outline">Open dialog</UiButton>
|
|
444
|
+
</UiDialogTrigger>
|
|
445
|
+
<UiDialogContent
|
|
446
|
+
title="Confirm action"
|
|
447
|
+
@interact-outside="handleInteractOutside"
|
|
448
|
+
>
|
|
449
|
+
<UiButton
|
|
450
|
+
@click="toast.success('${FIGMA_MESSAGE}', {
|
|
451
|
+
action: { label: '${FIGMA_ACTION_LABEL}', onClick: () => {} },
|
|
452
|
+
})"
|
|
453
|
+
>
|
|
454
|
+
Show snackbar
|
|
455
|
+
</UiButton>
|
|
456
|
+
</UiDialogContent>
|
|
457
|
+
</UiDialog>
|
|
458
|
+
<UiSnackbar rich-colors close-button />
|
|
459
|
+
</template>`;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Trigger a snackbar from inside a modal dialog. Forward `@interact-outside`
|
|
463
|
+
* so clicking the snackbar doesn't dismiss the dialog (the toast renders
|
|
464
|
+
* outside the dialog tree).
|
|
465
|
+
*/
|
|
466
|
+
export const WithDialog: Story = {
|
|
467
|
+
render: (args) => ({
|
|
468
|
+
components: {
|
|
469
|
+
UiSnackbar,
|
|
470
|
+
UiButton,
|
|
471
|
+
UiDialog,
|
|
472
|
+
UiDialogTrigger,
|
|
473
|
+
UiDialogContent,
|
|
474
|
+
},
|
|
475
|
+
setup() {
|
|
476
|
+
const open = ref(false);
|
|
477
|
+
const toasterId = 'story-dialog';
|
|
478
|
+
const show = () => showTypedSnackbar('success', toasterId, true);
|
|
479
|
+
const handleInteractOutside = (event: Event) => {
|
|
480
|
+
const target = event.target as HTMLElement | null;
|
|
481
|
+
if (target?.closest('[data-sonner-toaster]')) event.preventDefault();
|
|
482
|
+
};
|
|
483
|
+
return { args, open, show, handleInteractOutside, toasterId };
|
|
484
|
+
},
|
|
485
|
+
template: `
|
|
486
|
+
<div>
|
|
487
|
+
<UiDialog v-model:open="open">
|
|
488
|
+
<UiDialogTrigger as-child>
|
|
489
|
+
<UiButton variant="outline">Open dialog</UiButton>
|
|
490
|
+
</UiDialogTrigger>
|
|
491
|
+
<UiDialogContent
|
|
492
|
+
title="Confirm action"
|
|
493
|
+
description="Trigger a snackbar from inside the dialog."
|
|
494
|
+
@interact-outside="handleInteractOutside"
|
|
495
|
+
>
|
|
496
|
+
<UiButton @click="show">Show snackbar</UiButton>
|
|
497
|
+
</UiDialogContent>
|
|
498
|
+
</UiDialog>
|
|
499
|
+
<UiSnackbar v-bind="args" :id="toasterId" />
|
|
500
|
+
</div>
|
|
501
|
+
`,
|
|
502
|
+
}),
|
|
503
|
+
parameters: {
|
|
504
|
+
docs: {
|
|
505
|
+
source: { code: withDialogTemplateSource },
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
};
|