Skip to content

Commit 023b947

Browse files
committed
feat: Expose triggerFlow method (resolves #864)
- refactor: Use proper component types
1 parent dca0f90 commit 023b947

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

src/VueDatePicker/VueDatePicker.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@
495495
const setMonthYear = (value: MonthYearOpt) => {
496496
if (dpMenuRef.value) {
497497
dpMenuRef.value.updateMonthYear(0, {
498-
month: getNumVal(value.month),
499-
year: getNumVal(value.year),
498+
month: getNumVal(value.month) as number,
499+
year: getNumVal(value.year) as number,
500500
});
501501
}
502502
};
@@ -514,6 +514,10 @@
514514
return closeMenu();
515515
};
516516
517+
const handleFlow = (skipStep = 0) => {
518+
dpMenuRef.value?.handleFlow(skipStep);
519+
};
520+
517521
onClickOutside(dpWrapMenuRef, inputRef, () => clickOutside(validateBeforeEmit));
518522
519523
defineExpose({
@@ -528,5 +532,6 @@
528532
parseModel,
529533
switchView,
530534
toggleMenu,
535+
handleFlow,
531536
});
532537
</script>

src/VueDatePicker/components/DatepickerMenu.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
};
235235
236236
const { arrowRight, arrowLeft, arrowDown, arrowUp } = useArrowNavigation();
237-
const { flowStep, updateFlowStep, childMount, resetFlow } = useFlow(props, emit, dynCmpRef);
237+
const { flowStep, updateFlowStep, childMount, resetFlow, handleFlow } = useFlow(props, emit, dynCmpRef);
238238
239239
const displayComponent = computed(() => {
240240
if (props.monthPicker) return MonthPicker;
@@ -413,5 +413,6 @@
413413
defineExpose({
414414
updateMonthYear,
415415
switchView,
416+
handleFlow,
416417
});
417418
</script>

src/VueDatePicker/composables/flow.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export const useFlow = (props: AllPropsType, emit: VueEmit, dynCmpRef: Ref<any>)
3434
emit('flow-step', flowStep.value);
3535
handleFlow();
3636
}
37+
if (props.flow?.length === flowStep.value) {
38+
resetFlow();
39+
}
3740
};
3841

3942
const resetFlow = (): void => {
@@ -48,7 +51,10 @@ export const useFlow = (props: AllPropsType, emit: VueEmit, dynCmpRef: Ref<any>)
4851
}
4952
};
5053

51-
const handleFlow = (): void => {
54+
const handleFlow = (skipStep = 0): void => {
55+
if (skipStep) {
56+
flowStep.value += skipStep;
57+
}
5258
handleFlowStep(FlowStep.month, 'toggleMonthPicker', true);
5359
handleFlowStep(FlowStep.year, 'toggleYearPicker', true);
5460
handleFlowStep(FlowStep.calendar, 'toggleTimePicker', false, true);
@@ -60,5 +66,5 @@ export const useFlow = (props: AllPropsType, emit: VueEmit, dynCmpRef: Ref<any>)
6066
}
6167
};
6268

63-
return { childMount, updateFlowStep, resetFlow, flowStep };
69+
return { childMount, updateFlowStep, resetFlow, handleFlow, flowStep };
6470
};

src/VueDatePicker/composables/position.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { h, ref, render, toRef, watch } from 'vue';
2-
import { OpenPosition } from '@/interfaces';
2+
import { type DatepickerInputRef, type DatepickerMenuRef, OpenPosition } from '@/interfaces';
33

44
import { unrefElement } from '@/utils/util';
55
import { MenuPlacement } from '@/constants';
66

7-
import type { Component, ComponentPublicInstance, ComputedRef, Ref, Slots } from 'vue';
8-
import type { ComponentRef, InlineOptions, VueEmit } from '@/interfaces';
7+
import type { Component, ComputedRef, Ref, Slots } from 'vue';
8+
import type { InlineOptions, VueEmit } from '@/interfaces';
99
import type { AllPropsType } from '@/props';
1010

1111
/**
1212
* Extracted code from the main component, used for calculating the position of the menu
1313
*/
1414
interface Params {
1515
menuRef: Ref<HTMLElement | null>;
16-
menuRefInner: Ref<ComponentPublicInstance | null>;
17-
inputRef: ComponentRef;
16+
menuRefInner: Ref<DatepickerMenuRef | null>;
17+
inputRef: Ref<DatepickerInputRef | null>;
1818
pickerWrapperRef: Ref<HTMLElement | null>;
1919
inline: ComputedRef<InlineOptions>;
2020
emit: VueEmit;

src/VueDatePicker/interfaces.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ComponentPublicInstance, Ref } from 'vue';
22
import type { HeaderPicker } from '@/constants';
3+
import DatepickerMenu from '@/components/DatepickerMenu.vue';
4+
import type DatepickerInput from '@/components/DatepickerInput.vue';
35

46
export type DynamicClass = Record<string, boolean | undefined>;
57

@@ -85,7 +87,9 @@ export interface ConfigurableWindow {
8587
window?: Window;
8688
}
8789

88-
export type MaybeElementRef = MaybeRef<HTMLElement | SVGElement | ComponentPublicInstance | undefined | null | Element>;
90+
export type MaybeElementRef = MaybeRef<
91+
HTMLElement | SVGElement | ComponentPublicInstance | undefined | null | Element | any
92+
>;
8993
export type OnClickOutsideEvents = Pick<
9094
WindowEventMap,
9195
'click' | 'mousedown' | 'mouseup' | 'touchstart' | 'touchend' | 'pointerdown' | 'pointerup'
@@ -172,8 +176,6 @@ export interface ICalendarData {
172176
year: number;
173177
}
174178

175-
export type ComponentRef = Ref<ComponentPublicInstance | HTMLElement | null>;
176-
177179
export type TimeOverlayCheck = 'noHoursOverlay' | 'noMinutesOverlay' | 'noSecondsOverlay';
178180

179181
export type DateTimeSetter = number | string | null;
@@ -189,15 +191,9 @@ export interface MonthYearOpt {
189191
year?: number | string;
190192
}
191193

192-
export type DatepickerMenuRef = ComponentPublicInstance<{
193-
updateMonthYear: (ins: number, val: { month: number | null; year: number | null }) => void;
194-
switchView: (view: MenuView, instance?: number) => void;
195-
}>;
194+
export type DatepickerMenuRef = InstanceType<typeof DatepickerMenu>;
196195

197-
export type DatepickerInputRef = ComponentPublicInstance<{
198-
setParsedDate: (date: Date | Date[] | null) => void;
199-
focusInput: () => void;
200-
}>;
196+
export type DatepickerInputRef = InstanceType<typeof DatepickerInput>;
201197

202198
export interface ActionRowData {
203199
showSelect: boolean;

0 commit comments

Comments
 (0)