|
28 | 28 | </div> |
29 | 29 | <div class="dp__instance_calendar" ref="calendarWrapperRef" role="document"> |
30 | 30 | <div :class="menuCalendarClassWrapper"> |
31 | | - <div v-for="instance in calendarAmm" :key="instance" :class="calendarInstanceClassWrapper"> |
| 31 | + <div v-for="(instance, i) in calendarAmm" :key="instance" :class="calendarInstanceClassWrapper"> |
32 | 32 | <component |
33 | 33 | :is="monthYearComponent ? monthYearComponent : MonthYearInput" |
| 34 | + :ref=" |
| 35 | + (el) => { |
| 36 | + if (el) monthYearInputRefs[i] = el; |
| 37 | + } |
| 38 | + " |
34 | 39 | v-if="!disableMonthYearSelect && !timePicker" |
35 | 40 | v-bind="{ |
36 | 41 | months, |
|
46 | 51 | minDate, |
47 | 52 | maxDate, |
48 | 53 | }" |
| 54 | + @mount="childMount('monthYearInput')" |
| 55 | + @reset-flow="resetFlow" |
49 | 56 | @update:month="updateMonthYear(instance, $event, true)" |
50 | 57 | @update:year="updateMonthYear(instance, $event, false)" |
51 | 58 | @month-year-select="monthYearSelect" |
|
56 | 63 | </component> |
57 | 64 | <Calendar |
58 | 65 | v-bind="calendarProps" |
| 66 | + v-model:flow-step="flowStep" |
59 | 67 | :instance="instance" |
60 | 68 | :mapped-dates="mappedDates(instance)" |
61 | 69 | :month="month(instance)" |
|
64 | 72 | @select-date="selectDate($event, !isFirstInstance(instance))" |
65 | 73 | @set-hover-date="setHoverDate($event)" |
66 | 74 | @handle-scroll="handleScroll($event, instance)" |
| 75 | + @mount="childMount('calendar')" |
| 76 | + @reset-flow="resetFlow" |
67 | 77 | > |
68 | 78 | <template v-for="(slot, i) in calendarSlots" #[slot]="args" :key="i"> |
69 | 79 | <slot :name="slot" v-bind="{ ...args }" /> |
|
96 | 106 | customProps, |
97 | 107 | enableSeconds, |
98 | 108 | }" |
| 109 | + @mount="childMount('timePicker')" |
99 | 110 | @update:hours="updateTime($event)" |
100 | 111 | @update:minutes="updateTime($event, false)" |
101 | 112 | @update:seconds="updateTime($event, false, true)" |
| 113 | + @reset-flow="resetFlow" |
102 | 114 | > |
103 | 115 | <template v-for="(slot, i) in timePickerSlots" #[slot]="args" :key="i"> |
104 | 116 | <slot :name="slot" v-bind="args" /> |
|
163 | 175 | ComputedRef, |
164 | 176 | ref, |
165 | 177 | onUnmounted, |
| 178 | + reactive, |
166 | 179 | } from 'vue'; |
167 | 180 | import Calendar from './Calendar.vue'; |
168 | 181 | import ActionRow from './ActionRow.vue'; |
|
171 | 184 |
|
172 | 185 | import { |
173 | 186 | DynamicClass, |
| 187 | + Flow, |
174 | 188 | ICalendarDate, |
175 | 189 | IDateFilter, |
176 | 190 | IDefaultSelect, |
|
179 | 193 | IMarker, |
180 | 194 | InternalModuleValue, |
181 | 195 | ITimeValue, |
| 196 | + MenuChildCmp, |
| 197 | + MonthYearInputRef, |
182 | 198 | PresetRange, |
| 199 | + TimePickerRef, |
183 | 200 | WeekStartNum, |
184 | 201 | WeekStartStr, |
185 | 202 | } from '../interfaces'; |
|
195 | 212 | 'dpOpen', |
196 | 213 | 'autoApply', |
197 | 214 | 'timeUpdate', |
| 215 | + 'flow-step', |
198 | 216 | ]); |
199 | 217 | const props = defineProps({ |
200 | 218 | internalModelValue: { type: [Date, Array] as PropType<InternalModuleValue>, default: null }, |
|
265 | 283 | readonly: { type: Boolean as PropType<boolean>, default: false }, |
266 | 284 | multiDates: { type: Boolean as PropType<boolean>, default: false }, |
267 | 285 | presetRanges: { type: Array as PropType<PresetRange[]>, default: () => [] }, |
| 286 | + flow: { type: Array as PropType<Flow>, default: () => [] }, |
268 | 287 | }); |
269 | 288 | const slots = useSlots(); |
270 | 289 | const calendarWrapperRef = ref(null); |
| 290 | + const childrenMounted = reactive({ timePicker: false, monthYearInput: false, calendar: false }); |
| 291 | + const monthYearInputRefs = ref<MonthYearInputRef[]>([]); |
| 292 | + const timePickerRef = ref<TimePickerRef | null>(null); |
271 | 293 | const dpMenuRef = ref(null); |
272 | 294 | const calendarWidth = ref(0); |
273 | 295 | const menuMount = ref(false); |
| 296 | + const flowStep = ref(0); |
274 | 297 |
|
275 | 298 | onMounted(() => { |
276 | 299 | menuMount.value = true; |
|
294 | 317 | document.removeEventListener('resize', getCalendarWidth); |
295 | 318 | }); |
296 | 319 |
|
| 320 | + const updateFlowStep = (): void => { |
| 321 | + if (props.flow?.length && flowStep.value !== -1) { |
| 322 | + flowStep.value += 1; |
| 323 | + emit('flow-step', flowStep.value); |
| 324 | + handleFlow(); |
| 325 | + } |
| 326 | + }; |
| 327 | +
|
| 328 | + const resetFlow = (): void => { |
| 329 | + flowStep.value = -1; |
| 330 | + }; |
| 331 | +
|
297 | 332 | const { |
298 | 333 | updateTime, |
299 | 334 | updateMonthYear, |
|
322 | 357 | isHoverDateStartEnd, |
323 | 358 | isHoverDate, |
324 | 359 | presetDateRange, |
325 | | - } = useCalendar(props, emit); |
| 360 | + } = useCalendar(props, emit, updateFlowStep); |
326 | 361 |
|
327 | 362 | const calendarSlots = mapSlots(slots, 'calendar'); |
328 | 363 | const actionSlots = mapSlots(slots, 'action'); |
|
494 | 529 | emit('selectDate'); |
495 | 530 | } |
496 | 531 | }; |
| 532 | +
|
| 533 | + const childMount = (cmp: MenuChildCmp): void => { |
| 534 | + if (props.flow?.length) { |
| 535 | + childrenMounted[cmp] = true; |
| 536 | +
|
| 537 | + if (!Object.keys(childrenMounted).filter((key) => !childrenMounted[key as MenuChildCmp]).length) { |
| 538 | + handleFlow(); |
| 539 | + } |
| 540 | + } |
| 541 | + }; |
| 542 | +
|
| 543 | + const handleFlow = (): void => { |
| 544 | + if (props.flow[flowStep.value] === 'month') { |
| 545 | + if (monthYearInputRefs.value[0]) { |
| 546 | + monthYearInputRefs.value[0].toggleMonthPicker(true); |
| 547 | + } |
| 548 | + } |
| 549 | + if (props.flow[flowStep.value] === 'year') { |
| 550 | + if (monthYearInputRefs.value) { |
| 551 | + monthYearInputRefs.value[0].toggleYearPicker(true); |
| 552 | + } |
| 553 | + } |
| 554 | + if (props.flow[flowStep.value] === 'calendar') { |
| 555 | + if (timePickerRef.value) { |
| 556 | + timePickerRef.value.toggleTimePicker(false, true); |
| 557 | + } |
| 558 | + } |
| 559 | + if (props.flow[flowStep.value] === 'time') { |
| 560 | + if (timePickerRef.value) { |
| 561 | + timePickerRef.value.toggleTimePicker(true, true); |
| 562 | + } |
| 563 | + } |
| 564 | + const flowValue = props.flow[flowStep.value]; |
| 565 | + if (flowValue === 'hours' || flowValue === 'minutes' || flowValue === 'seconds') { |
| 566 | + if (timePickerRef.value) { |
| 567 | + timePickerRef.value.toggleTimePicker(true, true, flowValue); |
| 568 | + } |
| 569 | + } |
| 570 | + }; |
497 | 571 | </script> |
0 commit comments