|
28 | 28 | ></slot> |
29 | 29 | <template v-if="!$slots['time-picker-overlay']"> |
30 | 30 | <div class="dp__overlay_row"> |
31 | | - <template v-if="!range"> |
32 | | - <TimeInput |
33 | | - :hours="hours" |
34 | | - :minutes="minutes" |
35 | | - :seconds="seconds" |
36 | | - v-bind="timeInputProps" |
37 | | - ref="timeInputRef" |
38 | | - @update:hours="updateHours($event)" |
39 | | - @update:minutes="updateMinutes($event)" |
40 | | - @update:seconds="updateSeconds($event)" |
41 | | - @reset-flow="$emit('reset-flow')" |
42 | | - > |
43 | | - <template v-for="(slot, i) in timeInputSlots" #[slot]="args" :key="i"> |
44 | | - <slot :name="slot" v-bind="args" /> |
45 | | - </template> |
46 | | - </TimeInput> |
47 | | - </template> |
48 | | - <template v-if="range"> |
49 | | - <TimeInput |
50 | | - :hours="hours[0]" |
51 | | - :minutes="minutes[0]" |
52 | | - :seconds="seconds[0]" |
53 | | - v-bind="timeInputProps" |
54 | | - @update:hours="updateHours([$event, hours[1]])" |
55 | | - @update:minutes="updateMinutes([$event, minutes[1]])" |
56 | | - @update:seconds="updateSeconds([$event, seconds[1]])" |
57 | | - > |
58 | | - <template v-for="(slot, i) in timeInputSlots" #[slot]="args" :key="i"> |
59 | | - <slot :name="slot" v-bind="args" /> |
60 | | - </template> |
61 | | - </TimeInput> |
62 | | - <TimeInput |
63 | | - :hours="hours[1]" |
64 | | - :minutes="minutes[1]" |
65 | | - :seconds="seconds[1]" |
66 | | - v-bind="timeInputProps" |
67 | | - @update:hours="updateHours([hours[0], $event])" |
68 | | - @update:minutes="updateMinutes([minutes[0], $event])" |
69 | | - @update:seconds="updateSeconds([seconds[0], $event])" |
70 | | - > |
71 | | - <template v-for="(slot, i) in timeInputSlots" #[slot]="args" :key="i"> |
72 | | - <slot :name="slot" v-bind="args" /> |
73 | | - </template> |
74 | | - </TimeInput> |
75 | | - </template> |
| 31 | + <TimeInput |
| 32 | + v-for="(tInput, index) in timeInputs" |
| 33 | + :key="index" |
| 34 | + :disabled="index === 0 ? fixedStart : fixedEnd" |
| 35 | + :hours="tInput.hours" |
| 36 | + :minutes="tInput.minutes" |
| 37 | + :seconds="tInput.seconds" |
| 38 | + v-bind="timeInputProps" |
| 39 | + @update:hours="updateHours(getEvent($event, index, 'hours'))" |
| 40 | + @update:minutes="updateMinutes(getEvent($event, index, 'minutes'))" |
| 41 | + @update:seconds="updateSeconds(getEvent($event, index, 'seconds'))" |
| 42 | + > |
| 43 | + <template v-for="(slot, i) in timeInputSlots" #[slot]="args" :key="i"> |
| 44 | + <slot :name="slot" v-bind="args" /> |
| 45 | + </template> |
| 46 | + </TimeInput> |
76 | 47 | </div> |
77 | 48 | </template> |
78 | 49 | <div |
|
124 | 95 | noSecondsOverlay: { type: Boolean as PropType<boolean>, default: false }, |
125 | 96 | customProps: { type: Object as PropType<Record<string, unknown>>, default: null }, |
126 | 97 | enableSeconds: { type: Boolean as PropType<boolean>, default: false }, |
| 98 | + fixedStart: { type: Boolean as PropType<boolean>, default: false }, |
| 99 | + fixedEnd: { type: Boolean as PropType<boolean>, default: false }, |
127 | 100 | }); |
128 | 101 | const slots = useSlots(); |
129 | 102 | const autoApply = inject('autoApply', false); |
|
137 | 110 |
|
138 | 111 | const showTimePicker = ref(false); |
139 | 112 |
|
| 113 | + const getTimeInput = (i: number) => { |
| 114 | + return { |
| 115 | + hours: Array.isArray(props.hours) ? props.hours[i] : props.hours, |
| 116 | + minutes: Array.isArray(props.minutes) ? props.minutes[i] : props.minutes, |
| 117 | + seconds: Array.isArray(props.seconds) ? props.seconds[i] : props.seconds, |
| 118 | + }; |
| 119 | + }; |
| 120 | +
|
| 121 | + const timeInputs = computed((): { hours: number; minutes: number; seconds: number }[] => { |
| 122 | + const arr = []; |
| 123 | + if (props.range) { |
| 124 | + for (let i = 0; i < 2; i++) { |
| 125 | + arr.push(getTimeInput(i)); |
| 126 | + } |
| 127 | + } else { |
| 128 | + arr.push(getTimeInput(0)); |
| 129 | + } |
| 130 | + return arr; |
| 131 | + }); |
| 132 | +
|
140 | 133 | const toggleTimePicker = (show: boolean, flow = false, childOpen = ''): void => { |
141 | 134 | if (!flow) { |
142 | 135 | emit('reset-flow'); |
|
172 | 165 | enableSeconds: props.enableSeconds, |
173 | 166 | })); |
174 | 167 |
|
| 168 | + const getEvent = (event: number, index: number, property: 'hours' | 'minutes' | 'seconds') => { |
| 169 | + if (index === 0) { |
| 170 | + return [event, timeInputs.value[1][property]]; |
| 171 | + } |
| 172 | + return [timeInputs.value[0][property], event]; |
| 173 | + }; |
| 174 | +
|
175 | 175 | const updateHours = (hours: number | number[]): void => { |
176 | 176 | emit('update:hours', hours); |
177 | 177 | }; |
|
0 commit comments