@juspay/svelte-ui-components 2.36.0 → 2.37.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/Toast/Toast.svelte +25 -13
- package/dist/Toast/properties.d.ts +5 -2
- package/package.json +1 -1
package/dist/Toast/Toast.svelte
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
2
3
|
import { fly } from 'svelte/transition';
|
|
3
4
|
import type { ToastDirection, ToastProperties } from './properties';
|
|
4
5
|
import type { FlyAnimationConfig } from '../types';
|
|
5
|
-
import { onMount } from 'svelte';
|
|
6
6
|
import Img from '../Img/Img.svelte';
|
|
7
7
|
|
|
8
8
|
let {
|
|
@@ -29,8 +29,11 @@
|
|
|
29
29
|
|
|
30
30
|
const animationConfig: FlyAnimationConfig = $derived(getAnimationConfig(overlapPage, direction));
|
|
31
31
|
|
|
32
|
-
let showToast = $state(
|
|
33
|
-
|
|
32
|
+
let showToast = $state(true);
|
|
33
|
+
|
|
34
|
+
const rootClass = $derived(
|
|
35
|
+
['toast', type ?? '', classes ?? ''].filter((cls) => cls.length > 0).join(' ')
|
|
36
|
+
);
|
|
34
37
|
|
|
35
38
|
function hideToast() {
|
|
36
39
|
showToast = false;
|
|
@@ -83,21 +86,30 @@
|
|
|
83
86
|
};
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
// Track `message` and `duration` as reactive dependencies so the timer
|
|
90
|
+
// restarts whenever either prop changes. Writing `showToast = true` via
|
|
91
|
+
// `untrack` prevents the assignment from enrolling `showToast` as a
|
|
92
|
+
// dependency of this effect, which would create an unwanted reactive cycle.
|
|
93
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
94
|
+
$effect(() => {
|
|
95
|
+
void message;
|
|
96
|
+
void duration;
|
|
97
|
+
|
|
98
|
+
untrack(() => {
|
|
99
|
+
showToast = true;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const id = setTimeout(hideToast, duration);
|
|
89
103
|
|
|
90
104
|
return () => {
|
|
91
|
-
|
|
92
|
-
clearTimeout(timeoutId);
|
|
93
|
-
}
|
|
105
|
+
clearTimeout(id);
|
|
94
106
|
};
|
|
95
107
|
});
|
|
96
108
|
</script>
|
|
97
109
|
|
|
98
110
|
{#if showToast}
|
|
99
111
|
<div
|
|
100
|
-
class=
|
|
112
|
+
class={rootClass}
|
|
101
113
|
class:no-page-overlap={!overlapPage}
|
|
102
114
|
role="alert"
|
|
103
115
|
aria-live="assertive"
|
|
@@ -129,9 +141,9 @@
|
|
|
129
141
|
tabindex="0"
|
|
130
142
|
role="button"
|
|
131
143
|
onclick={hideToast}
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
|
|
144
|
+
onkeydown={(event) => {
|
|
145
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
146
|
+
event.preventDefault();
|
|
135
147
|
hideToast();
|
|
136
148
|
}
|
|
137
149
|
}}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
export type ToastType = 'success' | 'error' | 'info' | 'warn';
|
|
3
3
|
export type ToastDirection = 'left-to-right' | 'right-to-left' | 'top-to-bottom' | 'bottom-to-top';
|
|
4
|
-
export type
|
|
4
|
+
export type MandatoryToastProperties = {
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export type OptionalToastProperties = {
|
|
5
8
|
duration?: number;
|
|
6
9
|
leftIcon?: string | null;
|
|
7
|
-
message: string;
|
|
8
10
|
subtext?: string | null;
|
|
9
11
|
rightIcon?: string | null;
|
|
10
12
|
type?: ToastType | null;
|
|
@@ -24,3 +26,4 @@ export type ToastProperties = ToastEventProperties & {
|
|
|
24
26
|
export type ToastEventProperties = {
|
|
25
27
|
onToastHide?: () => void;
|
|
26
28
|
};
|
|
29
|
+
export type ToastProperties = MandatoryToastProperties & OptionalToastProperties & ToastEventProperties;
|