2022-09-07 05:58:59 +00:00
|
|
|
<template>
|
2023-01-28 22:32:39 +00:00
|
|
|
<div v-if="!inline" class="form-control w-full">
|
|
|
|
<label class="label">
|
2023-02-27 03:42:23 +00:00
|
|
|
<span class="label-text"> {{ label }}</span>
|
2023-01-28 22:32:39 +00:00
|
|
|
</label>
|
|
|
|
<input ref="input" v-model="selected" type="date" class="input input-bordered w-full" />
|
|
|
|
</div>
|
|
|
|
<div v-else class="sm:grid sm:grid-cols-4 sm:items-start sm:gap-4">
|
|
|
|
<label class="label">
|
2023-02-27 03:42:23 +00:00
|
|
|
<span class="label-text"> {{ label }} </span>
|
2023-01-28 22:32:39 +00:00
|
|
|
</label>
|
|
|
|
<input v-model="selected" type="date" class="input input-bordered col-span-3 w-full mt-2" />
|
2022-09-07 05:58:59 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-09-09 22:46:53 +00:00
|
|
|
const emit = defineEmits(["update:modelValue", "update:text"]);
|
2022-09-07 05:58:59 +00:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
modelValue: {
|
2023-02-27 03:42:23 +00:00
|
|
|
type: Date as () => Date | string | null,
|
2022-09-07 05:58:59 +00:00
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
inline: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-02-27 03:42:23 +00:00
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
default: "Date",
|
|
|
|
},
|
2022-09-07 05:58:59 +00:00
|
|
|
});
|
|
|
|
|
2023-01-28 22:32:39 +00:00
|
|
|
const selected = computed({
|
|
|
|
get() {
|
|
|
|
// return modelValue as string as YYYY-MM-DD or null
|
2023-02-09 02:59:04 +00:00
|
|
|
if (validDate(props.modelValue)) {
|
2023-02-13 19:43:09 +00:00
|
|
|
if (typeof props.modelValue === "string") {
|
|
|
|
return props.modelValue;
|
|
|
|
}
|
|
|
|
|
2023-02-09 02:59:04 +00:00
|
|
|
return props.modelValue ? props.modelValue.toISOString().split("T")[0] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-01-28 22:32:39 +00:00
|
|
|
},
|
|
|
|
set(value: string | null) {
|
|
|
|
// emit update:modelValue with a Date object or null
|
|
|
|
emit("update:modelValue", value ? new Date(value) : null);
|
|
|
|
},
|
2022-09-07 05:58:59 +00:00
|
|
|
});
|
2023-01-28 22:32:39 +00:00
|
|
|
</script>
|
2022-09-07 05:58:59 +00:00
|
|
|
|
2023-01-28 22:32:39 +00:00
|
|
|
<style class="scoped">
|
|
|
|
::-webkit-calendar-picker-indicator {
|
|
|
|
filter: invert(1);
|
2022-09-07 05:58:59 +00:00
|
|
|
}
|
2023-01-28 22:32:39 +00:00
|
|
|
</style>
|