daisy-ui-kit 5.2.2 → 5.2.3
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/app/composables/use-toast.ts +11 -9
- package/package.json +1 -1
|
@@ -29,6 +29,9 @@ export interface Toast {
|
|
|
29
29
|
progress?: number // 0-1 for progress bar
|
|
30
30
|
promiseId?: string // for async/promise support
|
|
31
31
|
ariaLive?: 'polite' | 'assertive' // accessibility
|
|
32
|
+
intervalId?: number
|
|
33
|
+
originalDuration?: number
|
|
34
|
+
startTime?: number
|
|
32
35
|
[key: string]: any
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -118,7 +121,7 @@ export interface UseToastOptions {
|
|
|
118
121
|
* addToast({ message: 'Hi' }) // will use defaults
|
|
119
122
|
* // In UI: <Toast name="admin" />
|
|
120
123
|
*/
|
|
121
|
-
function normalizeToast(toast: any): Toast
|
|
124
|
+
function normalizeToast(toast: any): Toast {
|
|
122
125
|
if (toast.originalDuration == null) {
|
|
123
126
|
toast.originalDuration = toast.duration ?? 0
|
|
124
127
|
}
|
|
@@ -128,7 +131,7 @@ function normalizeToast(toast: any): Toast & { countdown: number; originalDurati
|
|
|
128
131
|
if (typeof toast.intervalId === 'undefined') {
|
|
129
132
|
toast.intervalId = undefined
|
|
130
133
|
}
|
|
131
|
-
return toast as Toast
|
|
134
|
+
return toast as Toast
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
export function useToast(options?: UseToastOptions) {
|
|
@@ -187,7 +190,7 @@ export function useToast(options?: UseToastOptions) {
|
|
|
187
190
|
const idx = channel.value.toasts.findIndex(t => t.id === id)
|
|
188
191
|
if (idx !== -1) {
|
|
189
192
|
// Defensive: clear countdown timer if present
|
|
190
|
-
const toast = channel.value.toasts[idx]
|
|
193
|
+
const toast = channel.value.toasts[idx]!
|
|
191
194
|
if (toast.intervalId) {
|
|
192
195
|
clearInterval(toast.intervalId)
|
|
193
196
|
}
|
|
@@ -311,10 +314,9 @@ export function useToast(options?: UseToastOptions) {
|
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
316
|
|
|
314
|
-
function startToastTimer(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (toast.originalDuration > 0) {
|
|
317
|
+
function startToastTimer(toast: Toast) {
|
|
318
|
+
const duration = toast.originalDuration ?? 0
|
|
319
|
+
if (duration > 0) {
|
|
318
320
|
if (toast.intervalId) {
|
|
319
321
|
clearInterval(toast.intervalId)
|
|
320
322
|
}
|
|
@@ -323,8 +325,8 @@ export function useToast(options?: UseToastOptions) {
|
|
|
323
325
|
|
|
324
326
|
toast.intervalId = setInterval(() => {
|
|
325
327
|
const elapsed = Date.now() - (toast.startTime ?? start)
|
|
326
|
-
toast.countdown = Math.max(0,
|
|
327
|
-
toast.progress = Math.max(0, toast.countdown /
|
|
328
|
+
toast.countdown = Math.max(0, duration - elapsed)
|
|
329
|
+
toast.progress = Math.max(0, toast.countdown / duration)
|
|
328
330
|
if (toast.countdown <= 0) {
|
|
329
331
|
clearInterval(toast.intervalId)
|
|
330
332
|
removeToast(toast.id)
|