@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.
@@ -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(false);
33
- let timeoutId = $state<ReturnType<typeof setTimeout> | null>(null);
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
- onMount(() => {
87
- showToast = true;
88
- timeoutId = setTimeout(hideToast, duration);
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
- if (timeoutId !== null) {
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="toast {type ?? ''} {classes ?? ''}"
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
- onkeypress={(e) => {
133
- if (e.key === 'Enter' || e.key === ' ') {
134
- e.preventDefault();
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 ToastProperties = ToastEventProperties & {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/svelte-ui-components",
3
- "version": "2.36.0",
3
+ "version": "2.37.0",
4
4
  "description": "A themeable Svelte 5 UI component library with CSS custom property driven styling",
5
5
  "keywords": [
6
6
  "svelte",