feat: add close event listener and enhance available range prop documentation in SingleDatePicker

This commit is contained in:
Astrian Zheng 2025-02-24 16:49:30 +11:00
parent 28c2192149
commit f1d87f9172
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA
2 changed files with 25 additions and 1 deletions

View File

@ -8,7 +8,7 @@ const date = ref(new Date())
<template> <template>
<div>{{date.toDateString()}}</div> <div>{{date.toDateString()}}</div>
<div class="container"> <div class="container">
<SingleDatePicker :available-range="[new Date(2025, 0, 1), null]" v-model="date" /> <SingleDatePicker :available-range="[new Date(2025, 0, 1), null]" v-model="date" @close="" />
</div> </div>
</template> </template>

View File

@ -13,6 +13,10 @@
type SingleDatePickerPropsAvailableDates = [Date | null, Date | null] type SingleDatePickerPropsAvailableDates = [Date | null, Date | null]
const props = defineProps({ const props = defineProps({
/**
* The color scheme of the component
* @default { mainColor: '#000000', accentColor: '#000000', borderColor: '#e0e0e0', hoverColor: '#00000017', reversedColor: '#ffffff' }
*/
colorScheme: { colorScheme: {
type: Object as () => SingleDatePickerPropsColorScheme, type: Object as () => SingleDatePickerPropsColorScheme,
default: () => ({ default: () => ({
@ -32,12 +36,32 @@
type: Date, type: Date,
required: false, required: false,
}, },
/**
* Available range of dates
*
* @description Limit a range of dates that can be selected. It should be an array of two dates, which the first
* one is the available range start date, and the second one is the available range end date.
*
* The parameter will be ignored if the array length is not 2.
*
* @see {@link https://datenel.js.org/guide/vue/components/SingleDatePicker.html#availablerange}
*
* @example [new Date(2025, 0, 1), new Date(2025, 11, 31)]
* @example [new Date(2025, 0, 1), null]
* @example [null, new Date(2025, 11, 31)]
* @example [new Date(2025, 11, 31), new Date(2025, 0, 1)]
* @default undefined
*/
availableRange: { availableRange: {
type: Array as unknown as PropType<SingleDatePickerPropsAvailableDates>, type: Array as unknown as PropType<SingleDatePickerPropsAvailableDates>,
required: false, required: false,
} }
}) })
/**
* @typedef {Object} Emits
* @property {Function} close - 触发关闭事件
*/
const emit = defineEmits(['update:modelValue', 'close']) const emit = defineEmits(['update:modelValue', 'close'])
const selectMonth = ref(false) const selectMonth = ref(false)
const uniqueId = generateUniqueId() const uniqueId = generateUniqueId()