mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-27 10:20:42 +01:00
fix(Notification): update timer when timeout prop changes (#1673)
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ref, computed, toRef, onMounted, onUnmounted, watchEffect, defineComponent } from 'vue'
|
import { ref, computed, toRef, onMounted, onUnmounted, watch, watchEffect, defineComponent } from 'vue'
|
||||||
import type { PropType } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
import { twMerge, twJoin } from 'tailwind-merge'
|
import { twMerge, twJoin } from 'tailwind-merge'
|
||||||
import UIcon from '../elements/Icon.vue'
|
import UIcon from '../elements/Icon.vue'
|
||||||
@@ -123,7 +123,7 @@ export default defineComponent({
|
|||||||
setup (props, { emit }) {
|
setup (props, { emit }) {
|
||||||
const { ui, attrs } = useUI('notification', toRef(props, 'ui'), config)
|
const { ui, attrs } = useUI('notification', toRef(props, 'ui'), config)
|
||||||
|
|
||||||
let timer: any = null
|
let timer: null | ReturnType<typeof useTimer> = null
|
||||||
const remaining = ref(props.timeout)
|
const remaining = ref(props.timeout)
|
||||||
|
|
||||||
const wrapperClass = computed(() => {
|
const wrapperClass = computed(() => {
|
||||||
@@ -191,7 +191,11 @@ export default defineComponent({
|
|||||||
emit('close')
|
emit('close')
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
function initTimer () {
|
||||||
|
if (timer) {
|
||||||
|
timer.stop()
|
||||||
|
}
|
||||||
|
|
||||||
if (!props.timeout) {
|
if (!props.timeout) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -203,7 +207,11 @@ export default defineComponent({
|
|||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
remaining.value = timer.remaining.value
|
remaining.value = timer.remaining.value
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
watch(() => props.timeout, initTimer)
|
||||||
|
|
||||||
|
onMounted(initTimer)
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (timer) {
|
if (timer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user