5454 -mx-[calc(var(--spacing)*2+2px)]
5555 rounded-none
5656 "
57- :progress =" 100 - ((( notification.isPaused ? (notification._timer.elapsedBeforePause): (notification._timer.elapsedBeforePause + ( time - notification.startTime))) / notification.timeout) * 100 )"
57+ :progress =" calculateNotificationProgress( notification, time! )"
5858 />
5959 </template >
6060 </lib-notification >
@@ -136,11 +136,13 @@ import {
136136 AlertDialogRoot ,
137137 AlertDialogTitle
138138} from " reka-ui"
139- import { computed , ref } from " vue"
139+ import { computed } from " vue"
140140
141+ import { calculateNotificationProgress } from " ./calculateNotificationProgress.js"
141142import LibNotification from " ./LibNotification.vue"
142143
143144import { useNotificationHandler } from " ../../composables/useNotificationHandler.js"
145+ import { useTimeConditionally } from " ../../composables/useTimeConditionally.js"
144146import { NotificationHandler } from " ../../helpers/NotificationHandler.js"
145147import { twMerge } from " ../../utils/twMerge.js"
146148import LibProgressBar from " ../LibProgressBar/LibProgressBar.vue"
@@ -153,18 +155,16 @@ defineOptions({
153155
154156const props = defineProps <Props >()
155157
158+ const handler = props .handler ?? useNotificationHandler ()
159+
156160const topNotifications = computed (() => handler .queue .filter (entry => entry .requiresAction ).reverse ())
157161const notifications = computed (() => handler .queue .filter (entry => ! entry .requiresAction ))
158162
159- const time = ref (Date .now ())
160- setInterval (() => {
161- requestAnimationFrame (() => {
162- time .value = Date .now ()
163- })
164- }, 50 )
165-
163+ const fetchTime = computed (() => {
164+ return notifications .value .filter (entry => entry .timeout !== undefined && ! entry .isPaused ).length > 0
165+ })
166166
167- const handler = props .handler ?? useNotificationHandler ( )
167+ const { time } = useTimeConditionally ( fetchTime , { refreshInterval: props .progressUpdateInterval } )
168168 </script >
169169
170170<script lang="ts">
@@ -173,8 +173,9 @@ import type { HTMLAttributes } from "vue"
173173type RealProps
174174 = & LinkableByIdProps
175175 & {
176- /** If not provided, uses the global handler (this requires useNotificationHandler be called and configured). */
176+ /** If not provided, uses the global handler (this requires useNotificationHandler be called and configured). */
177177 handler? : NotificationHandler
178+ progressUpdateInterval? : number
178179 }
179180
180181interface Props
0 commit comments