1
0

feat: use withDefaults for Datepicker

This commit is contained in:
Dominik Pschenitschni 2024-07-05 15:41:12 +02:00 committed by konrad
parent f19f19bb75
commit 78811d916a

View File

@ -33,7 +33,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ref, onMounted, onBeforeUnmount, toRef, watch, type PropType} from 'vue' import {ref, onMounted, onBeforeUnmount, toRef, watch} from 'vue'
import CustomTransition from '@/components/misc/CustomTransition.vue' import CustomTransition from '@/components/misc/CustomTransition.vue'
import DatepickerInline from '@/components/input/DatepickerInline.vue' import DatepickerInline from '@/components/input/DatepickerInline.vue'
@ -44,26 +44,24 @@ import {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
import {createDateFromString} from '@/helpers/time/createDateFromString' import {createDateFromString} from '@/helpers/time/createDateFromString'
import {useI18n} from 'vue-i18n' import {useI18n} from 'vue-i18n'
const props = defineProps({ const props = withDefaults(defineProps<{
modelValue: { modelValue: Date | null | string,
type: [Date, null, String] as PropType<Date | null | string>, chooseDateLabel: string,
validator: prop => prop instanceof Date || prop === null || typeof prop === 'string', disabled?: boolean,
default: null, }>(), {
}, modelValue: null,
chooseDateLabel: { chooseDateLabel: () => {
type: String, const {t} = useI18n({useScope: 'global'})
default() { return t('input.datepicker.chooseDate')
const {t} = useI18n({useScope: 'global'})
return t('input.datepicker.chooseDate')
},
},
disabled: {
type: Boolean,
default: false,
}, },
disabled: false,
}) })
const emit = defineEmits(['update:modelValue', 'close', 'closeOnChange']) const emit = defineEmits<{
'update:modelValue': [value: Date | null],
'close': [value: boolean],
'closeOnChange': [value: boolean],
}>()
const date = ref<Date | null>() const date = ref<Date | null>()
const show = ref(false) const show = ref(false)