-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathDateRangeArgument.vue
43 lines (38 loc) · 923 Bytes
/
DateRangeArgument.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<template>
<div class="ui-predicate__date__range__argument">
<input type="date" v-model="start" @change="emitUpdatedValue" />
<span>and</span>
<input type="date" v-model="end" @change="emitUpdatedValue" />
</div>
</template>
<script setup>
import { ref, watch } from "vue";
const props = defineProps({
value: {
type: null,
required: true,
},
});
const emit = defineEmits(["change"]);
const start = ref(props.value?.[0] || "");
const end = ref(props.value?.[1] || "");
// Watch for external prop changes and update local refs
watch(
() => props.value,
(newValue) => {
if (Array.isArray(newValue)) {
start.value = newValue[0] || "";
end.value = newValue[1] || "";
}
}
);
const emitUpdatedValue = () => {
emit("change", [start.value, end.value]);
};
</script>
<style scoped>
.ui-predicate__date__range__argument {
display: flex;
align-items: center;
}
</style>