@skeletonlabs/skeleton-svelte 1.0.0 → 1.1.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/dist/components/FileUpload/FileUpload.svelte +1 -1
- package/dist/components/Toast/Toast.svelte +68 -0
- package/dist/components/Toast/Toast.svelte.d.ts +4 -0
- package/dist/components/Toast/Toaster.svelte +68 -0
- package/dist/components/Toast/Toaster.svelte.d.ts +4 -0
- package/dist/components/Toast/create-toaster.d.ts +2 -0
- package/dist/components/Toast/create-toaster.js +5 -0
- package/dist/components/Toast/types.d.ts +31 -75
- package/dist/components/Toast/types.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +27 -27
- package/dist/components/Toast/ToastProvider.svelte +0 -133
- package/dist/components/Toast/ToastProvider.svelte.d.ts +0 -4
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
{#if !children}
|
|
102
102
|
<ul {...api.getItemGroupProps()} class="{filesListBase} {filesListClasses}" data-testid="uploader-files-list">
|
|
103
103
|
<!-- Loop Files -->
|
|
104
|
-
{#each api.acceptedFiles as file (file
|
|
104
|
+
{#each api.acceptedFiles as file (file)}
|
|
105
105
|
<!-- File -->
|
|
106
106
|
<li
|
|
107
107
|
{...api.getItemProps({ file })}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import * as toast from '@zag-js/toast';
|
|
3
|
+
import type { ToastProps } from './types.js';
|
|
4
|
+
import { normalizeProps, useMachine } from '@zag-js/svelte';
|
|
5
|
+
|
|
6
|
+
const props: ToastProps = $props();
|
|
7
|
+
const service = useMachine(toast.machine, () => ({
|
|
8
|
+
...props.toast,
|
|
9
|
+
parent: props.parent,
|
|
10
|
+
index: props.index
|
|
11
|
+
}));
|
|
12
|
+
const api = $derived(toast.connect(service, normalizeProps));
|
|
13
|
+
const rxState = $derived.by(() => {
|
|
14
|
+
switch (api.type) {
|
|
15
|
+
case 'success':
|
|
16
|
+
return props.stateSuccess;
|
|
17
|
+
case 'warning':
|
|
18
|
+
return props.stateWarning;
|
|
19
|
+
case 'error':
|
|
20
|
+
return props.stateError;
|
|
21
|
+
default:
|
|
22
|
+
return props.stateInfo;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<div
|
|
28
|
+
class="{props.base} {props.width} {props.padding} {props.rounded} {rxState} {props.classes}"
|
|
29
|
+
{...api.getRootProps()}
|
|
30
|
+
data-testid="toast-root"
|
|
31
|
+
>
|
|
32
|
+
<!-- Text -->
|
|
33
|
+
<div class="{props.messageBase} {props.messageClasses}" data-testid="toast-message">
|
|
34
|
+
<!-- Title -->
|
|
35
|
+
<span class="{props.titleBase} {props.titleClasses}" {...api.getTitleProps()} data-testid="toast-title">{api.title}</span>
|
|
36
|
+
<!-- Description -->
|
|
37
|
+
<span class="{props.descriptionBase} {props.descriptionClasses}" {...api.getDescriptionProps()} data-testid="toast-description"
|
|
38
|
+
>{api.description}</span
|
|
39
|
+
>
|
|
40
|
+
</div>
|
|
41
|
+
<!-- Dismiss Button -->
|
|
42
|
+
<button class="{props.btnDismissBase} {props.btnDismissClasses}" onclick={api.dismiss} data-testid="toast-dismiss">×</button>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<style>
|
|
46
|
+
[data-part='root'] {
|
|
47
|
+
translate: var(--x) var(--y);
|
|
48
|
+
scale: var(--scale);
|
|
49
|
+
z-index: var(--z-index);
|
|
50
|
+
height: var(--height);
|
|
51
|
+
opacity: var(--opacity);
|
|
52
|
+
will-change: translate, opacity, scale;
|
|
53
|
+
}
|
|
54
|
+
[data-part='root'] {
|
|
55
|
+
transition:
|
|
56
|
+
translate 400ms,
|
|
57
|
+
scale 400ms,
|
|
58
|
+
opacity 400ms;
|
|
59
|
+
transition-timing-function: cubic-bezier(0.21, 1.02, 0.73, 1);
|
|
60
|
+
}
|
|
61
|
+
[data-part='root'][data-state='closed'] {
|
|
62
|
+
transition:
|
|
63
|
+
translate 400ms,
|
|
64
|
+
scale 400ms,
|
|
65
|
+
opacity 200ms;
|
|
66
|
+
transition-timing-function: cubic-bezier(0.06, 0.71, 0.55, 1);
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { normalizeProps, useMachine } from '@zag-js/svelte';
|
|
3
|
+
import * as toast from '@zag-js/toast';
|
|
4
|
+
import Toast from './Toast.svelte';
|
|
5
|
+
import type { ToasterProps } from './types.js';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
// Toaster
|
|
9
|
+
toaster,
|
|
10
|
+
// Toast
|
|
11
|
+
base = 'flex justify-between items-center gap-3',
|
|
12
|
+
width = 'min-w-xs',
|
|
13
|
+
padding = 'p-3',
|
|
14
|
+
rounded = 'rounded-container',
|
|
15
|
+
classes = '',
|
|
16
|
+
// Message
|
|
17
|
+
messageBase = 'grid',
|
|
18
|
+
messageClasses = '',
|
|
19
|
+
// Title
|
|
20
|
+
titleBase = 'font-semibold',
|
|
21
|
+
titleClasses = '',
|
|
22
|
+
// Description
|
|
23
|
+
descriptionBase = 'text-sm',
|
|
24
|
+
descriptionClasses = '',
|
|
25
|
+
// Dismiss Button
|
|
26
|
+
btnDismissBase = 'btn-icon hover:preset-tonal',
|
|
27
|
+
btnDismissClasses = '',
|
|
28
|
+
// State
|
|
29
|
+
stateInfo = 'preset-outlined-surface-200-800 preset-filled-surface-50-950',
|
|
30
|
+
stateSuccess = 'preset-filled-success-500',
|
|
31
|
+
stateWarning = 'preset-filled-warning-500',
|
|
32
|
+
stateError = 'preset-filled-error-500'
|
|
33
|
+
}: ToasterProps = $props();
|
|
34
|
+
|
|
35
|
+
const id = $props.id();
|
|
36
|
+
const service = useMachine(toast.group.machine, () => ({
|
|
37
|
+
id: id,
|
|
38
|
+
store: toaster
|
|
39
|
+
}));
|
|
40
|
+
const api = $derived(toast.group.connect(service, normalizeProps));
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div {...api.getGroupProps()} data-testid="toaster-root">
|
|
44
|
+
{#each api.getToasts() as toast, index (toast.id)}
|
|
45
|
+
<Toast
|
|
46
|
+
{base}
|
|
47
|
+
{width}
|
|
48
|
+
{padding}
|
|
49
|
+
{rounded}
|
|
50
|
+
{classes}
|
|
51
|
+
{messageBase}
|
|
52
|
+
{messageClasses}
|
|
53
|
+
{titleBase}
|
|
54
|
+
{titleClasses}
|
|
55
|
+
{descriptionBase}
|
|
56
|
+
{descriptionClasses}
|
|
57
|
+
{btnDismissBase}
|
|
58
|
+
{btnDismissClasses}
|
|
59
|
+
{stateInfo}
|
|
60
|
+
{stateError}
|
|
61
|
+
{stateWarning}
|
|
62
|
+
{stateSuccess}
|
|
63
|
+
{toast}
|
|
64
|
+
{index}
|
|
65
|
+
parent={service}
|
|
66
|
+
></Toast>
|
|
67
|
+
{/each}
|
|
68
|
+
</div>
|
|
@@ -1,87 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
bottom?: string;
|
|
5
|
-
left?: string;
|
|
6
|
-
right?: string;
|
|
7
|
-
'align-items'?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface Toast {
|
|
10
|
-
/** The unique toast ID. */
|
|
11
|
-
id?: string;
|
|
12
|
-
/** The unique toast title text. */
|
|
13
|
-
title?: string;
|
|
14
|
-
/** The unique toast description text. */
|
|
15
|
-
description?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Define the toast type.
|
|
18
|
-
* @default info
|
|
19
|
-
*/
|
|
20
|
-
type?: 'info' | 'error' | 'success';
|
|
21
|
-
/** The duration of the toast. Default varies by type. */
|
|
22
|
-
duration?: number;
|
|
23
|
-
}
|
|
24
|
-
/** Provides access to the Toast Context API. */
|
|
25
|
-
export interface ToastContext {
|
|
26
|
-
/** Used to create display a new Toast instance. */
|
|
27
|
-
create: (toast: Toast) => void;
|
|
28
|
-
}
|
|
29
|
-
export interface ToastProviderProps {
|
|
30
|
-
/**
|
|
31
|
-
* Offset from the viewport edge.
|
|
32
|
-
* @default bottom-end
|
|
33
|
-
*/
|
|
34
|
-
placement?: 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';
|
|
35
|
-
/**
|
|
36
|
-
* Offset from the viewport edge.
|
|
37
|
-
* @default 16px
|
|
38
|
-
*/
|
|
39
|
-
offset?: string;
|
|
40
|
-
/**
|
|
41
|
-
* The dismiss button label text.
|
|
42
|
-
* @default ×
|
|
43
|
-
*/
|
|
44
|
-
dismissLabel?: string;
|
|
1
|
+
import * as toast from '@zag-js/toast';
|
|
2
|
+
export interface ToasterProps extends toast.StoreProps {
|
|
3
|
+
toaster: toast.Store;
|
|
45
4
|
/** Provide base classes for the root element. */
|
|
46
5
|
base?: string;
|
|
47
|
-
/** Provide
|
|
48
|
-
|
|
49
|
-
/** Provide
|
|
50
|
-
|
|
51
|
-
/** Provide
|
|
52
|
-
|
|
53
|
-
/** Provide base classes for the toast cards. */
|
|
54
|
-
toastBase?: string;
|
|
55
|
-
/** Provide padding classes for the toast cards. */
|
|
56
|
-
toastPadding?: string;
|
|
57
|
-
/** Provide gap classes for the toast cards. */
|
|
58
|
-
toastGap?: string;
|
|
59
|
-
/** Provide shadow classes for the toast cards. */
|
|
60
|
-
toastShadow?: string;
|
|
6
|
+
/** Provide width classes for the root element. */
|
|
7
|
+
width?: string;
|
|
8
|
+
/** Provide padding classes for the root element. */
|
|
9
|
+
padding?: string;
|
|
10
|
+
/** Provide border radius classes for the root element. */
|
|
11
|
+
rounded?: string;
|
|
61
12
|
/** Provide arbitrary classes for the toast cards. */
|
|
62
|
-
|
|
63
|
-
/** Provide base classes for the message
|
|
13
|
+
classes?: string;
|
|
14
|
+
/** Provide base classes for the message. */
|
|
64
15
|
messageBase?: string;
|
|
65
|
-
/** Provide classes for the message
|
|
66
|
-
messageTitle?: string;
|
|
67
|
-
/** Provide classes for the message description text. */
|
|
68
|
-
messageDescription?: string;
|
|
69
|
-
/** Provide arbitrary classes for the message region. */
|
|
16
|
+
/** Provide classes for the message. */
|
|
70
17
|
messageClasses?: string;
|
|
18
|
+
/** Provide base classes for the title. */
|
|
19
|
+
titleBase?: string;
|
|
20
|
+
/** Provide classes for the title. */
|
|
21
|
+
titleClasses?: string;
|
|
22
|
+
/** Provide base classes for the description. */
|
|
23
|
+
descriptionBase?: string;
|
|
24
|
+
/** Provide classes for the description. */
|
|
25
|
+
descriptionClasses?: string;
|
|
71
26
|
/** Provide base classes for the dismiss button. */
|
|
72
|
-
|
|
73
|
-
/** Provide preset classes for the dismiss button. */
|
|
74
|
-
buttonDimissPreset?: string;
|
|
75
|
-
/** Provide hover classes for the dismiss button. */
|
|
76
|
-
buttonDismissHover?: string;
|
|
27
|
+
btnDismissBase?: string;
|
|
77
28
|
/** Provide arbitrary classes for the dismiss button. */
|
|
78
|
-
|
|
29
|
+
btnDismissClasses?: string;
|
|
79
30
|
/** Provide base classes for info toasts. */
|
|
80
31
|
stateInfo?: string;
|
|
81
|
-
/** Provide base classes for error toasts. */
|
|
82
|
-
stateError?: string;
|
|
83
32
|
/** Provide base classes for success toasts. */
|
|
84
33
|
stateSuccess?: string;
|
|
85
|
-
/**
|
|
86
|
-
|
|
34
|
+
/** Provide base classes for warning toasts. */
|
|
35
|
+
stateWarning?: string;
|
|
36
|
+
/** Provide base classes for error toasts. */
|
|
37
|
+
stateError?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ToastProps extends Omit<ToasterProps, 'toaster'> {
|
|
40
|
+
toast: toast.Options;
|
|
41
|
+
index: number;
|
|
42
|
+
parent: toast.GroupService;
|
|
87
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import * as toast from '@zag-js/toast';
|
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,10 @@ export { default as Slider } from './components/Slider/Slider.svelte';
|
|
|
11
11
|
export { default as Switch } from './components/Switch/Switch.svelte';
|
|
12
12
|
export { default as Tabs } from './components/Tabs/index.js';
|
|
13
13
|
export { default as TagsInput } from './components/TagsInput/TagsInput.svelte';
|
|
14
|
+
export { default as Toaster } from './components/Toast/Toaster.svelte';
|
|
15
|
+
export { createToaster } from './components/Toast/create-toaster.js';
|
|
14
16
|
export { default as Rating } from './components/Rating/index.js';
|
|
15
17
|
export type { FileUploadApi } from './components/FileUpload/types.js';
|
|
16
|
-
export { default as ToastProvider } from './components/Toast/ToastProvider.svelte';
|
|
17
|
-
export type { ToastContext } from './components/Toast/types.js';
|
|
18
18
|
export { default as Combobox } from './components/Combobox/Combobox.svelte';
|
|
19
19
|
export { default as Popover } from './components/Popover/Popover.svelte';
|
|
20
20
|
export { default as Tooltip } from './components/Tooltip/Tooltip.svelte';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Exports for skeleton-svelte package
|
|
2
2
|
// REMINDER
|
|
3
3
|
// Do not export parent/child components. Use the dot-notation composition pattern:
|
|
4
|
-
// https://
|
|
4
|
+
// https://skeleton.dev/docs/resources/contribute/components#dot-notation-syntax
|
|
5
5
|
// (See Accordion, Nav, and Tabs for examples)
|
|
6
6
|
// Components
|
|
7
7
|
export { default as Accordion } from './components/Accordion/index.js';
|
|
@@ -17,11 +17,11 @@ export { default as Slider } from './components/Slider/Slider.svelte';
|
|
|
17
17
|
export { default as Switch } from './components/Switch/Switch.svelte';
|
|
18
18
|
export { default as Tabs } from './components/Tabs/index.js';
|
|
19
19
|
export { default as TagsInput } from './components/TagsInput/TagsInput.svelte';
|
|
20
|
+
export { default as Toaster } from './components/Toast/Toaster.svelte';
|
|
21
|
+
export { createToaster } from './components/Toast/create-toaster.js';
|
|
20
22
|
export { default as Rating } from './components/Rating/index.js';
|
|
21
23
|
// Temporary Features ---
|
|
22
24
|
// The following will be removed or replaced in the future.
|
|
23
|
-
// Toasts
|
|
24
|
-
export { default as ToastProvider } from './components/Toast/ToastProvider.svelte';
|
|
25
25
|
// Popvers
|
|
26
26
|
export { default as Combobox } from './components/Combobox/Combobox.svelte';
|
|
27
27
|
export { default as Popover } from './components/Popover/Popover.svelte';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skeletonlabs/skeleton-svelte",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The Svelte package for Skeleton.",
|
|
5
5
|
"author": "endigo9740 <chris@skeletonlabs.dev>",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,46 +16,46 @@
|
|
|
16
16
|
"!dist/**/*.test.*"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@zag-js/accordion": "^1.
|
|
20
|
-
"@zag-js/avatar": "^1.
|
|
21
|
-
"@zag-js/combobox": "^1.
|
|
22
|
-
"@zag-js/dialog": "^1.
|
|
23
|
-
"@zag-js/file-upload": "^1.
|
|
24
|
-
"@zag-js/pagination": "^1.
|
|
25
|
-
"@zag-js/popover": "^1.
|
|
26
|
-
"@zag-js/progress": "^1.
|
|
27
|
-
"@zag-js/radio-group": "^1.
|
|
28
|
-
"@zag-js/rating-group": "^1.
|
|
29
|
-
"@zag-js/slider": "^1.
|
|
30
|
-
"@zag-js/svelte": "^1.
|
|
31
|
-
"@zag-js/switch": "^1.
|
|
32
|
-
"@zag-js/tabs": "^1.
|
|
33
|
-
"@zag-js/tags-input": "^1.
|
|
34
|
-
"@zag-js/
|
|
19
|
+
"@zag-js/accordion": "^1.7.0",
|
|
20
|
+
"@zag-js/avatar": "^1.7.0",
|
|
21
|
+
"@zag-js/combobox": "^1.7.0",
|
|
22
|
+
"@zag-js/dialog": "^1.7.0",
|
|
23
|
+
"@zag-js/file-upload": "^1.7.0",
|
|
24
|
+
"@zag-js/pagination": "^1.7.0",
|
|
25
|
+
"@zag-js/popover": "^1.7.0",
|
|
26
|
+
"@zag-js/progress": "^1.7.0",
|
|
27
|
+
"@zag-js/radio-group": "^1.7.0",
|
|
28
|
+
"@zag-js/rating-group": "^1.7.0",
|
|
29
|
+
"@zag-js/slider": "^1.7.0",
|
|
30
|
+
"@zag-js/svelte": "^1.7.0",
|
|
31
|
+
"@zag-js/switch": "^1.7.0",
|
|
32
|
+
"@zag-js/tabs": "^1.7.0",
|
|
33
|
+
"@zag-js/tags-input": "^1.7.0",
|
|
34
|
+
"@zag-js/toast": "^1.7.0",
|
|
35
|
+
"@zag-js/tooltip": "^1.7.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"svelte": "^5.20.0"
|
|
38
|
-
"@skeletonlabs/skeleton": "^3.0.0"
|
|
38
|
+
"svelte": "^5.20.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@sveltejs/adapter-auto": "^
|
|
42
|
-
"@sveltejs/kit": "^2.
|
|
41
|
+
"@sveltejs/adapter-auto": "^5.0.0",
|
|
42
|
+
"@sveltejs/kit": "^2.20.2",
|
|
43
43
|
"@sveltejs/package": "^2.3.10",
|
|
44
44
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
45
45
|
"@tailwindcss/forms": "^0.5.10",
|
|
46
|
-
"@tailwindcss/vite": "^4.0.
|
|
46
|
+
"@tailwindcss/vite": "^4.0.17",
|
|
47
47
|
"@testing-library/jest-dom": "^6.6.3",
|
|
48
48
|
"@testing-library/svelte": "^5.2.7",
|
|
49
49
|
"jsdom": "^26.0.0",
|
|
50
50
|
"publint": "^0.3.9",
|
|
51
|
-
"svelte": "^5.
|
|
51
|
+
"svelte": "^5.25.3",
|
|
52
52
|
"svelte-check": "^4.1.5",
|
|
53
|
-
"tailwindcss": "^4.0.
|
|
53
|
+
"tailwindcss": "^4.0.17",
|
|
54
54
|
"tslib": "^2.8.1",
|
|
55
55
|
"typescript": "^5.8.2",
|
|
56
|
-
"vite": "^6.2.
|
|
57
|
-
"vitest": "3.
|
|
58
|
-
"@skeletonlabs/skeleton": "3.
|
|
56
|
+
"vite": "^6.2.4",
|
|
57
|
+
"vitest": "3.1.1",
|
|
58
|
+
"@skeletonlabs/skeleton": "3.1.2"
|
|
59
59
|
},
|
|
60
60
|
"type": "module",
|
|
61
61
|
"scripts": {
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { setContext } from 'svelte';
|
|
3
|
-
import { flip } from 'svelte/animate';
|
|
4
|
-
import { fade } from 'svelte/transition';
|
|
5
|
-
|
|
6
|
-
import type { PlacementStyles, Toast, ToastProviderProps } from './types.js';
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
placement = 'bottom-end',
|
|
10
|
-
offset = '16px',
|
|
11
|
-
dismissLabel = '',
|
|
12
|
-
// Group
|
|
13
|
-
base = 'fixed flex flex-col items-end',
|
|
14
|
-
gap = 'gap-4',
|
|
15
|
-
zIndex = 'z-[888]',
|
|
16
|
-
classes = '',
|
|
17
|
-
// Toast
|
|
18
|
-
toastBase = 'card py-2 px-3 grid grid-cols-[1fr_auto] items-center',
|
|
19
|
-
toastPadding = 'py-2 px-3',
|
|
20
|
-
toastGap = 'gap-4',
|
|
21
|
-
toastShadow = 'shadow-xl',
|
|
22
|
-
toastClasses = '',
|
|
23
|
-
// Message
|
|
24
|
-
messageBase = 'grid grid-cols-1 max-w-xs text-xs',
|
|
25
|
-
messageTitle = 'font-bold',
|
|
26
|
-
messageDescription = '',
|
|
27
|
-
messageClasses = '',
|
|
28
|
-
// Dismiss Button
|
|
29
|
-
buttonDismissBase = 'btn-icon btn-icon-sm text-base',
|
|
30
|
-
buttonDimissPreset = '',
|
|
31
|
-
buttonDismissHover = 'hover:preset-tonal',
|
|
32
|
-
buttonDismissClasses = '',
|
|
33
|
-
// State
|
|
34
|
-
stateInfo = 'preset-filled',
|
|
35
|
-
stateError = 'preset-filled-error-500',
|
|
36
|
-
stateSuccess = 'preset-filled-success-500',
|
|
37
|
-
// Snippets
|
|
38
|
-
children
|
|
39
|
-
}: ToastProviderProps = $props();
|
|
40
|
-
|
|
41
|
-
// Local
|
|
42
|
-
const defaults: Record<string, Toast> = {
|
|
43
|
-
info: { duration: 5000 },
|
|
44
|
-
error: { duration: 5000 },
|
|
45
|
-
success: { duration: 2000 }
|
|
46
|
-
};
|
|
47
|
-
const placementOptions: Record<string, PlacementStyles> = {
|
|
48
|
-
'top-start': { top: offset, left: offset, 'align-items': 'flex-start' },
|
|
49
|
-
'top-end': { top: offset, right: offset, 'align-items': 'flex-end' },
|
|
50
|
-
'bottom-start': { bottom: offset, left: offset, 'align-items': 'flex-start' },
|
|
51
|
-
'bottom-end': { bottom: offset, right: offset, 'align-items': 'flex-end' }
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// State
|
|
55
|
-
let toastQueue: Toast[] = $state([]);
|
|
56
|
-
|
|
57
|
-
// Context
|
|
58
|
-
const id = $props.id();
|
|
59
|
-
setContext('toast', {
|
|
60
|
-
create: (toast: Toast) => {
|
|
61
|
-
// Set default settings
|
|
62
|
-
toast = {
|
|
63
|
-
...defaults[String(toast.type || 'info')],
|
|
64
|
-
...toast,
|
|
65
|
-
id: id
|
|
66
|
-
};
|
|
67
|
-
// Push to Queue
|
|
68
|
-
toastQueue.push(toast);
|
|
69
|
-
// Set duration timeout
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
dismiss(toast.id);
|
|
72
|
-
}, toast.duration);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
function formatStyleAttr(style: PlacementStyles) {
|
|
77
|
-
return Object.entries(style)
|
|
78
|
-
.map(([k, v]) => `${k}:${v}`)
|
|
79
|
-
.join(';');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function dismiss(id: string | undefined) {
|
|
83
|
-
if (!id) return;
|
|
84
|
-
toastQueue = toastQueue.filter((t) => t.id !== id);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getStateClasses(type?: string) {
|
|
88
|
-
// prettier-ignore
|
|
89
|
-
switch (type) {
|
|
90
|
-
case 'error': return stateError;
|
|
91
|
-
case 'success': return stateSuccess;
|
|
92
|
-
default: return stateInfo;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<!-- Toast Group -->
|
|
98
|
-
{#if toastQueue.length}
|
|
99
|
-
<div
|
|
100
|
-
class="{base} {gap} {zIndex} {classes}"
|
|
101
|
-
style={formatStyleAttr(placementOptions[placement])}
|
|
102
|
-
data-part="root"
|
|
103
|
-
data-testid="toast-provider"
|
|
104
|
-
>
|
|
105
|
-
{#each toastQueue as toast, i (toast)}
|
|
106
|
-
{@const stateClasses = getStateClasses(toast.type)}
|
|
107
|
-
<!-- Toast -->
|
|
108
|
-
<div
|
|
109
|
-
data-index={i}
|
|
110
|
-
data-type={toast.type}
|
|
111
|
-
class="{toastBase} {toastPadding} {toastGap} {toastShadow} {toastClasses} {stateClasses}"
|
|
112
|
-
animate:flip={{ duration: 200 }}
|
|
113
|
-
transition:fade={{ duration: 200 }}
|
|
114
|
-
>
|
|
115
|
-
<!-- Message -->
|
|
116
|
-
<div class="{messageBase} {messageClasses}">
|
|
117
|
-
{#if toast.title}<div class={messageTitle}>{toast.title}</div>{/if}
|
|
118
|
-
<div class={messageDescription}>{toast.description}</div>
|
|
119
|
-
</div>
|
|
120
|
-
<!-- Dismiss -->
|
|
121
|
-
<button
|
|
122
|
-
type="button"
|
|
123
|
-
class="{buttonDismissBase} {buttonDimissPreset} {buttonDismissHover} {buttonDismissClasses}"
|
|
124
|
-
onclick={() => dismiss(toast.id)}
|
|
125
|
-
>
|
|
126
|
-
{#if dismissLabel}{dismissLabel}{:else}×{/if}
|
|
127
|
-
</button>
|
|
128
|
-
</div>
|
|
129
|
-
{/each}
|
|
130
|
-
</div>
|
|
131
|
-
{/if}
|
|
132
|
-
|
|
133
|
-
{@render children?.()}
|