Skip to content

Commit

Permalink
feat(count-down): add on-complete event
Browse files Browse the repository at this point in the history
  • Loading branch information
qianmoQ committed Dec 6, 2024
1 parent da3e85f commit d829d77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/components/count-down.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ This document is mainly used to describe some features and usage of the ShadcnCo
['simple', 'Whether to display the simple version', 'boolean', 'false'],
]">
</ApiTable>

## Count Down Events

<ApiTable title="Events"
:headers="['Event', 'Description', 'Callback Parameters']"
:columns="[
['on-complete', 'Triggered when the count down is finished', 'void'],
]">
</ApiTable>
5 changes: 4 additions & 1 deletion src/ui/count-down/ShadcnCountDown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{ `${ timeLeft.days } : ${ timeLeft.hours } : ${ timeLeft.minutes } : ${ timeLeft.seconds }` }}
</div>
</div>

<div v-else class="grid grid-cols-4 gap-4 text-center">
<!-- Days -->
<div class="flex flex-col">
Expand Down Expand Up @@ -45,8 +46,9 @@
import { onMounted, onUnmounted, ref } from 'vue'
import { t } from '@/utils/locale'
import ShadcnCard from '@/ui/card'
import { CountDownProps } from '@/ui/count-down/types'
import { CountDownEmits, CountDownProps } from '@/ui/count-down/types'
const emit = defineEmits<CountDownEmits>()
const props = withDefaults(defineProps<CountDownProps>(), {
simple: false
})
Expand All @@ -70,6 +72,7 @@ const calculateTimeLeft = () => {
if (timer) {
clearInterval(timer)
}
emit('on-complete')
return
}
Expand Down
7 changes: 6 additions & 1 deletion src/ui/count-down/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export interface CountDownProps {
export interface CountDownProps
{
time: Date
simple?: boolean
}

export type CountDownEmits = {
(e: 'on-complete'): void
}

0 comments on commit d829d77

Please sign in to comment.