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>
|
2024-03-02 00:07:03 +00:00
|
|
|
<VueDatePicker v-model="selected" :enable-time-picker="false" clearable :dark="isDark" />
|
2023-01-28 22:32:39 +00:00
|
|
|
</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>
|
2024-02-29 18:58:26 +00:00
|
|
|
<VueDatePicker v-model="selected" :enable-time-picker="false" clearable :dark="isDark" />
|
2022-09-07 05:58:59 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-02-29 18:58:26 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import VueDatePicker from "@vuepic/vue-datepicker";
|
|
|
|
import "@vuepic/vue-datepicker/dist/main.css";
|
|
|
|
import * as datelib from "~/lib/datelib/datelib";
|
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
|
|
|
});
|
|
|
|
|
2024-02-29 18:58:26 +00:00
|
|
|
const isDark = useIsDark();
|
2023-02-28 04:52:56 +00:00
|
|
|
|
2024-02-29 18:58:26 +00:00
|
|
|
const selected = computed<Date | null>({
|
|
|
|
get() {
|
2023-02-28 04:52:56 +00:00
|
|
|
// String
|
|
|
|
if (typeof props.modelValue === "string") {
|
|
|
|
// Empty string
|
|
|
|
if (props.modelValue === "") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalid Date string
|
|
|
|
if (props.modelValue === "Invalid Date") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-02-29 18:58:26 +00:00
|
|
|
return datelib.parse(props.modelValue);
|
2023-02-28 04:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Date
|
|
|
|
if (props.modelValue instanceof Date) {
|
2024-02-29 18:58:26 +00:00
|
|
|
if (props.modelValue.getFullYear() < 1000) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-02-28 04:52:56 +00:00
|
|
|
if (isNaN(props.modelValue.getTime())) {
|
|
|
|
return null;
|
2023-02-13 19:43:09 +00:00
|
|
|
}
|
|
|
|
|
2023-02-28 04:52:56 +00:00
|
|
|
// Valid Date
|
2024-02-29 18:58:26 +00:00
|
|
|
return props.modelValue;
|
2023-02-09 02:59:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-01-28 22:32:39 +00:00
|
|
|
},
|
2024-02-29 18:58:26 +00:00
|
|
|
set(value: Date | null) {
|
|
|
|
console.debug("DatePicker: SET", value);
|
|
|
|
if (value instanceof Date) {
|
|
|
|
value = datelib.zeroTime(value);
|
|
|
|
emit("update:modelValue", value);
|
|
|
|
} else {
|
|
|
|
value = value ? datelib.zeroTime(new Date(value)) : null;
|
|
|
|
emit("update:modelValue", value);
|
|
|
|
}
|
2023-01-28 22:32:39 +00:00
|
|
|
},
|
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>
|