fix: time-picker type error #5109

refactor-modal
tangjinzhou 2022-01-01 16:41:34 +08:00
parent ad76bb678d
commit b13756ffbe
20 changed files with 197 additions and 139 deletions

View File

@ -60,6 +60,7 @@ export interface CalendarProps<DateType> {
mode?: CalendarMode; mode?: CalendarMode;
fullscreen?: boolean; fullscreen?: boolean;
onChange?: (date: DateType | string) => void; onChange?: (date: DateType | string) => void;
'onUpdate:value'?: (date: DateType | string) => void;
onPanelChange?: (date: DateType | string, mode: CalendarMode) => void; onPanelChange?: (date: DateType | string, mode: CalendarMode) => void;
onSelect?: (date: DateType | string) => void; onSelect?: (date: DateType | string) => void;
valueFormat?: string; valueFormat?: string;
@ -88,7 +89,25 @@ function generateCalendar<
const Calendar = defineComponent<Props>({ const Calendar = defineComponent<Props>({
name: 'ACalendar', name: 'ACalendar',
inheritAttrs: false, inheritAttrs: false,
emits: ['change', 'panelChange', 'select', 'update:value'], props: [
'prefixCls',
'locale',
'validRange',
'disabledDate',
'dateFullCellRender',
'dateCellRender',
'monthFullCellRender',
'monthCellRender',
'headerRender',
'value',
'defaultValue',
'mode',
'fullscreen',
'onChange',
'onPanelChange',
'onSelect',
'valueFormat',
] as any,
slots: [ slots: [
'dateFullCellRender', 'dateFullCellRender',
'dateCellRender', 'dateCellRender',
@ -306,26 +325,6 @@ function generateCalendar<
}, },
}); });
Calendar.props = [
'prefixCls',
'locale',
'validRange',
'disabledDate',
'dateFullCellRender',
'dateCellRender',
'monthFullCellRender',
'monthCellRender',
'headerRender',
'value',
'defaultValue',
'mode',
'fullscreen',
'onChange',
'onPanelChange',
'onSelect',
'valueFormat',
];
Calendar.install = function (app: App) { Calendar.install = function (app: App) {
app.component(Calendar.name, Calendar); app.component(Calendar.name, Calendar);
return app; return app;

View File

@ -167,7 +167,7 @@ exports[`renders ./components/carousel/demo/basic.vue correctly 1`] = `
exports[`renders ./components/carousel/demo/customArrows.vue correctly 1`] = ` exports[`renders ./components/carousel/demo/customArrows.vue correctly 1`] = `
<div class="ant-carousel"> <div class="ant-carousel">
<div class="slick-slider slick-initialized"> <div class="slick-slider slick-initialized">
<div class="custom-slick-arrow slick-arrow slick-prev" style="left: 10px; display: block;"><span role="img" aria-label="left-circle" class="anticon anticon-left-circle"><svg focusable="false" class="" data-icon="left-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M603.3 327.5l-246 178a7.95 7.95 0 000 12.9l246 178c5.3 3.8 12.7 0 12.7-6.5V643c0-10.2-4.9-19.9-13.2-25.9L457.4 512l145.4-105.2c8.3-6 13.2-15.6 13.2-25.9V334c0-6.5-7.4-10.3-12.7-6.5z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg></span></div> <div class="custom-slick-arrow slick-arrow slick-prev" style="left: 10px; z-index: 1; display: block;"><span role="img" aria-label="left-circle" class="anticon anticon-left-circle"><svg focusable="false" class="" data-icon="left-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M603.3 327.5l-246 178a7.95 7.95 0 000 12.9l246 178c5.3 3.8 12.7 0 12.7-6.5V643c0-10.2-4.9-19.9-13.2-25.9L457.4 512l145.4-105.2c8.3-6 13.2-15.6 13.2-25.9V334c0-6.5-7.4-10.3-12.7-6.5z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg></span></div>
<div class="slick-list"> <div class="slick-list">
<div class="slick-track" style="opacity: 1; transform: translate3d(0px, 0px, 0px);"> <div class="slick-track" style="opacity: 1; transform: translate3d(0px, 0px, 0px);">
<div class="slick-slide slick-cloned" tabindex="-1" data-index="-1" aria-hidden="true" style="width: 0px;"> <div class="slick-slide slick-cloned" tabindex="-1" data-index="-1" aria-hidden="true" style="width: 0px;">

View File

@ -51,7 +51,7 @@ export default defineComponent({
}; };
return { return {
value1: ref<Dayjs>(), value1: ref<Dayjs>(),
value2: ref<Dayjs[]>([]), value2: ref<[Dayjs, Dayjs]>(),
value3: ref<Dayjs>(), value3: ref<Dayjs>(),
getCurrentStyle, getCurrentStyle,
}; };

View File

@ -68,7 +68,7 @@ export default defineComponent({
}; };
}; };
const disabledRangeTime = (_: Dayjs[], type: 'start' | 'end') => { const disabledRangeTime = (_: Dayjs, type: 'start' | 'end') => {
if (type === 'start') { if (type === 'start') {
return { return {
disabledHours: () => range(0, 60).splice(4, 20), disabledHours: () => range(0, 60).splice(4, 20),
@ -87,8 +87,8 @@ export default defineComponent({
dayjs, dayjs,
value1: ref<Dayjs>(), value1: ref<Dayjs>(),
value2: ref<Dayjs>(), value2: ref<Dayjs>(),
value3: ref<Dayjs[]>([]), value3: ref<[Dayjs, Dayjs]>(),
value4: ref<Dayjs[]>([]), value4: ref<[Dayjs, Dayjs]>(),
disabledDate, disabledDate,
disabledDateTime, disabledDateTime,
disabledRangeTime, disabledRangeTime,

View File

@ -33,8 +33,14 @@ export default defineComponent({
return { return {
value1: ref<Dayjs>(dayjs('2015-06-06', dateFormat)), value1: ref<Dayjs>(dayjs('2015-06-06', dateFormat)),
value2: ref<Dayjs>(dayjs('2015-06', 'YYYY-MM')), value2: ref<Dayjs>(dayjs('2015-06', 'YYYY-MM')),
value3: ref<Dayjs[]>([dayjs('2015-06-06', dateFormat), dayjs('2015-06-06', dateFormat)]), value3: ref<[Dayjs, Dayjs]>([
value4: ref<Dayjs[]>([dayjs('2019-09-03', dateFormat), dayjs('2019-11-22', dateFormat)]), dayjs('2015-06-06', dateFormat),
dayjs('2015-06-06', dateFormat),
]),
value4: ref<[Dayjs, Dayjs]>([
dayjs('2019-09-03', dateFormat),
dayjs('2019-11-22', dateFormat),
]),
}; };
}, },
}); });

View File

@ -37,7 +37,10 @@ export default defineComponent({
value1: ref<Dayjs>(dayjs('2015/01/01', dateFormat)), value1: ref<Dayjs>(dayjs('2015/01/01', dateFormat)),
value2: ref<Dayjs>(dayjs('01/01/2015', dateFormatList[0])), value2: ref<Dayjs>(dayjs('01/01/2015', dateFormatList[0])),
value3: ref<Dayjs>(dayjs('2015/01', monthFormat)), value3: ref<Dayjs>(dayjs('2015/01', monthFormat)),
value4: ref<Dayjs[]>([dayjs('2015/01/01', dateFormat), dayjs('2015/01/01', dateFormat)]), value4: ref<[Dayjs, Dayjs]>([
dayjs('2015/01/01', dateFormat),
dayjs('2015/01/01', dateFormat),
]),
value5: ref<Dayjs>(dayjs('2015/01/01', dateFormat)), value5: ref<Dayjs>(dayjs('2015/01/01', dateFormat)),
dateFormat, dateFormat,
monthFormat, monthFormat,

View File

@ -39,9 +39,9 @@ import { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue'; import { defineComponent, ref } from 'vue';
export default defineComponent({ export default defineComponent({
setup() { setup() {
const mode1 = ref<string>('time'); const mode1 = ref<any>('time');
const mode2 = ref<string[]>(['month', 'month']); const mode2 = ref<any>(['month', 'month']);
const value = ref<Dayjs[]>([]); const value = ref<[Dayjs, Dayjs]>();
const handleOpenChange1 = (open: boolean) => { const handleOpenChange1 = (open: boolean) => {
if (open) { if (open) {
@ -49,15 +49,15 @@ export default defineComponent({
} }
}; };
const handleChange = (val: Dayjs[]) => { const handleChange = (val: [Dayjs, Dayjs]) => {
value.value = val; value.value = val;
}; };
const handlePanelChange1 = (_val: Dayjs[], mode: string) => { const handlePanelChange1 = (_val: [Dayjs, Dayjs], mode: any) => {
mode1.value = mode; mode1.value = mode;
}; };
const handlePanelChange2 = (val: Dayjs[], mode: string[]) => { const handlePanelChange2 = (val: [Dayjs, Dayjs], mode: any[]) => {
value.value = val; value.value = val;
mode2.value = [ mode2.value = [
mode[0] === 'date' ? 'month' : mode[0], mode[0] === 'date' ? 'month' : mode[0],

View File

@ -31,12 +31,16 @@ We can set presetted ranges to RangePicker to improve user experience.
<script lang="ts"> <script lang="ts">
import dayjs, { Dayjs } from 'dayjs'; import dayjs, { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue'; import { defineComponent, ref } from 'vue';
type RangeValue = [Dayjs, Dayjs];
export default defineComponent({ export default defineComponent({
setup() { setup() {
return { return {
value1: ref<Dayjs[]>([]), value1: ref<RangeValue>(),
value2: ref<Dayjs[]>([]), value2: ref<RangeValue>(),
ranges: { Today: [dayjs(), dayjs()], 'This Month': [dayjs(), dayjs().endOf('month')] }, ranges: {
Today: [dayjs(), dayjs()] as RangeValue,
'This Month': [dayjs(), dayjs().endOf('month')] as RangeValue,
},
}; };
}, },
}); });

View File

@ -28,14 +28,15 @@ Set range picker type by `picker` prop.
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue'; import { defineComponent, ref } from 'vue';
import type { Dayjs } from 'dayjs'; import type { Dayjs } from 'dayjs';
type RangeValue = [Dayjs, Dayjs];
export default defineComponent({ export default defineComponent({
setup() { setup() {
return { return {
value1: ref<Dayjs[]>([]), value1: ref<RangeValue>(),
value2: ref<Dayjs[]>([]), value2: ref<RangeValue>(),
value3: ref<Dayjs[]>([]), value3: ref<RangeValue>(),
value4: ref<Dayjs[]>([]), value4: ref<RangeValue>(),
value5: ref<Dayjs[]>([]), value5: ref<RangeValue>(),
}; };
}, },
}); });

View File

@ -27,14 +27,15 @@ A example shows how to select a dynamic range by using `onCalendarChange` and `d
<script lang="ts"> <script lang="ts">
import { Dayjs } from 'dayjs'; import { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue'; import { defineComponent, ref } from 'vue';
type RangeValue = [Dayjs, Dayjs];
export default defineComponent({ export default defineComponent({
setup() { setup() {
const dates = ref<Dayjs[]>([]); const dates = ref<RangeValue>();
const value = ref<Dayjs[]>(); const value = ref<RangeValue>();
const hackValue = ref<Dayjs[]>(); const hackValue = ref<RangeValue>();
const disabledDate = (current: Dayjs) => { const disabledDate = (current: Dayjs) => {
if (!dates.value || dates.value.length === 0) { if (!dates.value) {
return false; return false;
} }
const tooLate = dates.value[0] && current.diff(dates.value[0], 'days') > 7; const tooLate = dates.value[0] && current.diff(dates.value[0], 'days') > 7;
@ -44,18 +45,18 @@ export default defineComponent({
const onOpenChange = (open: boolean) => { const onOpenChange = (open: boolean) => {
if (open) { if (open) {
dates.value = []; dates.value = null;
hackValue.value = []; hackValue.value = null;
} else { } else {
hackValue.value = undefined; hackValue.value = undefined;
} }
}; };
const onChange = (val: Dayjs[]) => { const onChange = (val: RangeValue) => {
value.value = val; value.value = val;
}; };
const onCalendarChange = (val: Dayjs[]) => { const onCalendarChange = (val: RangeValue) => {
dates.value = val; dates.value = val;
}; };

View File

@ -34,7 +34,7 @@ import { defineComponent, ref } from 'vue';
export default defineComponent({ export default defineComponent({
setup() { setup() {
return { return {
size: ref<string>('default'), size: ref<any>('default'),
}; };
}, },
}); });

View File

@ -46,7 +46,7 @@ import { Dayjs } from 'dayjs';
import { defineComponent, ref, watch } from 'vue'; import { defineComponent, ref, watch } from 'vue';
export default defineComponent({ export default defineComponent({
setup() { setup() {
const startValue = ref<Dayjs | undefined>(); const startValue = ref<Dayjs>();
const endValue = ref<Dayjs>(); const endValue = ref<Dayjs>();
const endOpen = ref<boolean>(false); const endOpen = ref<boolean>(false);

View File

@ -28,7 +28,7 @@ Customize the suffix icon through `suffixIcon`
<SmileOutlined /> <SmileOutlined />
</template> </template>
</a-date-picker> </a-date-picker>
<a-range-picker @change="onChange"> <a-range-picker @change="onRangeChange">
<template #suffixIcon> <template #suffixIcon>
<SmileOutlined /> <SmileOutlined />
</template> </template>
@ -40,7 +40,7 @@ Customize the suffix icon through `suffixIcon`
</a-date-picker> </a-date-picker>
<a-date-picker suffix-icon="ab" @change="onChange" /> <a-date-picker suffix-icon="ab" @change="onChange" />
<a-date-picker suffix-icon="ab" placeholder="Select month" picker="month" @change="onChange" /> <a-date-picker suffix-icon="ab" placeholder="Select month" picker="month" @change="onChange" />
<a-range-picker suffix-icon="ab" @change="onChange" /> <a-range-picker suffix-icon="ab" @change="onRangeChange" />
<a-date-picker suffix-icon="ab" placeholder="Select week" picker="week" @change="onChange" /> <a-date-picker suffix-icon="ab" placeholder="Select week" picker="week" @change="onChange" />
</a-space> </a-space>
</template> </template>
@ -53,12 +53,16 @@ export default defineComponent({
SmileOutlined, SmileOutlined,
}, },
setup() { setup() {
const onChange = (date: Dayjs, dateString: string[]) => { const onChange = (date: Dayjs | string, dateString: string) => {
console.log(date, dateString); console.log(date, dateString);
}; };
const onRangeChange = (date: [Dayjs, Dayjs], dateString: [string, string]) => {
console.log(date, dateString);
};
return { return {
onChange, onChange,
onRangeChange,
}; };
}, },
}); });

View File

@ -37,7 +37,7 @@ import { defineComponent, ref } from 'vue';
export default defineComponent({ export default defineComponent({
setup() { setup() {
return { return {
type: ref('time'), type: ref<any>('time'),
}; };
}, },
}); });

View File

@ -34,7 +34,7 @@ import { defineComponent, ref } from 'vue';
export default defineComponent({ export default defineComponent({
setup() { setup() {
const time1 = ref<Dayjs>(); const time1 = ref<Dayjs>();
const time2 = ref<Dayjs>(); const time2 = ref<[Dayjs, Dayjs]>();
const onOk = (value: Dayjs) => { const onOk = (value: Dayjs) => {
console.log('onOk: ', value); console.log('onOk: ', value);

View File

@ -23,8 +23,8 @@ This property provide an additional time selection. When `showTime` is an Object
:show-time="{ format: 'HH:mm' }" :show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm"
:placeholder="['Start Time', 'End Time']" :placeholder="['Start Time', 'End Time']"
@change="onChange" @change="onRangeChange"
@ok="onOk" @ok="onRangeOk"
/> />
</a-space> </a-space>
</template> </template>
@ -33,18 +33,29 @@ import { Dayjs } from 'dayjs';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
export default defineComponent({ export default defineComponent({
setup() { setup() {
const onChange = (value: Dayjs[], dateString: string[]) => { const onChange = (value: Dayjs, dateString: string) => {
console.log('Selected Time: ', value); console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString); console.log('Formatted Selected Time: ', dateString);
}; };
const onOk = (value: Dayjs[]) => { const onOk = (value: Dayjs) => {
console.log('onOk: ', value);
};
const onRangeChange = (value: [Dayjs, Dayjs], dateString: [string, string]) => {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString);
};
const onRangeOk = (value: [Dayjs, Dayjs]) => {
console.log('onOk: ', value); console.log('onOk: ', value);
}; };
return { return {
onChange, onChange,
onOk, onOk,
onRangeChange,
onRangeOk,
}; };
}, },
}); });

View File

@ -41,17 +41,6 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
'renderExtraFooter', 'renderExtraFooter',
// 'separator', // 'separator',
], ],
emits: [
'change',
'panelChange',
'ok',
'openChange',
'update:value',
'update:open',
'calendarChange',
'focus',
'blur',
],
setup(props, { expose, slots, attrs, emit }) { setup(props, { expose, slots, attrs, emit }) {
const formItemContext = useInjectFormItemContext(); const formItemContext = useInjectFormItemContext();
devWarning( devWarning(
@ -161,6 +150,8 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
id = formItemContext.id.value, id = formItemContext.id.value,
...restProps ...restProps
} = p; } = p;
delete restProps['onUpdate:value'];
delete restProps['onUpdate:open'];
const { format, showTime } = p as any; const { format, showTime } = p as any;
let additionalOverrideProps: any = {}; let additionalOverrideProps: any = {};

View File

@ -41,16 +41,6 @@ export default function generateSinglePicker<DateType, ExtraProps = {}>(
'renderExtraFooter', 'renderExtraFooter',
'monthCellRender', 'monthCellRender',
], ],
emits: [
'change',
'openChange',
'focus',
'blur',
'panelChange',
'ok',
'update:value',
'update:open',
],
setup(props, { slots, expose, attrs, emit }) { setup(props, { slots, expose, attrs, emit }) {
const formItemContext = useInjectFormItemContext(); const formItemContext = useInjectFormItemContext();
devWarning( devWarning(

View File

@ -1,3 +1,4 @@
import type { FocusEventHandler, MouseEventHandler } from '../../_util/EventInterface';
import type { CSSProperties, PropType } from 'vue'; import type { CSSProperties, PropType } from 'vue';
import type { PickerLocale } from '.'; import type { PickerLocale } from '.';
import type { SizeType } from '../../config-provider'; import type { SizeType } from '../../config-provider';
@ -14,7 +15,7 @@ import type {
import type { DateRender } from '../../vc-picker/panels/DatePanel/DateBody'; import type { DateRender } from '../../vc-picker/panels/DatePanel/DateBody';
import type { MonthCellRender } from '../../vc-picker/panels/MonthPanel/MonthBody'; import type { MonthCellRender } from '../../vc-picker/panels/MonthPanel/MonthBody';
import type { SharedTimeProps } from '../../vc-picker/panels/TimePanel'; import type { SharedTimeProps } from '../../vc-picker/panels/TimePanel';
import type { RangeDateRender, RangeType } from '../../vc-picker/RangePicker'; import type { RangeDateRender, RangeInfo, RangeType } from '../../vc-picker/RangePicker';
import type { VueNode } from '../../_util/type'; import type { VueNode } from '../../_util/type';
function commonProps<DateType>() { function commonProps<DateType>() {
@ -45,17 +46,24 @@ function commonProps<DateType>() {
getPopupContainer: { type: Function as PropType<(node: HTMLElement) => HTMLElement> }, getPopupContainer: { type: Function as PropType<(node: HTMLElement) => HTMLElement> },
panelRender: { type: Function as PropType<(originPanel: VueNode) => VueNode> }, panelRender: { type: Function as PropType<(originPanel: VueNode) => VueNode> },
// // Events // // Events
// onChange?: (value: DateType | null, dateString: string) => void; onChange: {
// onOpenChange?: (open: boolean) => void; type: Function as PropType<(value: DateType | string | null, dateString: string) => void>,
// onFocus?: FocusEventHandler; },
// onBlur?: FocusEventHandler; 'onUpdate:value': { type: Function as PropType<(value: DateType | string | null) => void> },
// onMousedown?: MouseEventHandler; onOk: { type: Function as PropType<(value: DateType | string | null) => void> },
// onMouseup?: MouseEventHandler; onOpenChange: { type: Function as PropType<(open: boolean) => void> },
// onMouseenter?: MouseEventHandler; 'onUpdate:open': { type: Function as PropType<(open: boolean) => void> },
// onMouseleave?: MouseEventHandler; onFocus: { type: Function as PropType<FocusEventHandler> },
// onClick?: MouseEventHandler; onBlur: { type: Function as PropType<FocusEventHandler> },
// onContextmenu?: MouseEventHandler; onMousedown: { type: Function as PropType<MouseEventHandler> },
// onKeydown?: (event: KeyboardEvent, preventDefault: () => void) => void; onMouseup: { type: Function as PropType<MouseEventHandler> },
onMouseenter: { type: Function as PropType<MouseEventHandler> },
onMouseleave: { type: Function as PropType<MouseEventHandler> },
onClick: { type: Function as PropType<MouseEventHandler> },
onContextmenu: { type: Function as PropType<MouseEventHandler> },
onKeydown: {
type: Function as PropType<(event: KeyboardEvent, preventDefault: () => void) => void>,
},
// WAI-ARIA // WAI-ARIA
role: String, role: String,
name: String, name: String,
@ -100,6 +108,20 @@ export interface CommonProps<DateType> {
superNextIcon?: VueNode; superNextIcon?: VueNode;
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement; getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
panelRender?: (originPanel: VueNode) => VueNode; panelRender?: (originPanel: VueNode) => VueNode;
onChange?: (value: DateType | string | null, dateString: string) => void;
'onUpdate:value'?: (value: DateType | string | null) => void;
onOk?: (value: DateType | string | null) => void;
onOpenChange?: (open: boolean) => void;
'onUpdate:open'?: (open: boolean) => void;
onFocus?: FocusEventHandler;
onBlur?: FocusEventHandler;
onMousedown?: MouseEventHandler;
onMouseup?: MouseEventHandler;
onMouseenter?: MouseEventHandler;
onMouseleave?: MouseEventHandler;
onClick?: MouseEventHandler;
onContextmenu?: MouseEventHandler;
onKeydown?: (event: KeyboardEvent, preventDefault: () => void) => void;
role?: string; role?: string;
name?: string; name?: string;
autocomplete?: string; autocomplete?: string;
@ -153,10 +175,10 @@ function rangePickerProps<DateType>() {
allowEmpty: { type: Array as unknown as PropType<[boolean, boolean]> }, allowEmpty: { type: Array as unknown as PropType<[boolean, boolean]> },
dateRender: { type: Function as PropType<RangeDateRender<DateType>> }, dateRender: { type: Function as PropType<RangeDateRender<DateType>> },
defaultPickerValue: { defaultPickerValue: {
type: Array as unknown as PropType<[DateType, DateType] | [string, string]>, type: Array as unknown as PropType<RangeValue<DateType> | RangeValue<string>>,
}, },
defaultValue: { type: Array as unknown as PropType<[DateType, DateType] | [string, string]> }, defaultValue: { type: Array as unknown as PropType<RangeValue<DateType> | RangeValue<string>> },
value: { type: Array as unknown as PropType<[DateType, DateType] | [string, string]> }, value: { type: Array as unknown as PropType<RangeValue<DateType> | RangeValue<string>> },
disabledTime: { disabledTime: {
type: Function as PropType<(date: EventValue<DateType>, type: RangeType) => DisabledTimes>, type: Function as PropType<(date: EventValue<DateType>, type: RangeType) => DisabledTimes>,
}, },
@ -174,15 +196,43 @@ function rangePickerProps<DateType>() {
}, },
placeholder: Array, placeholder: Array,
mode: { type: Array as unknown as PropType<[PanelMode, PanelMode]> }, mode: { type: Array as unknown as PropType<[PanelMode, PanelMode]> },
onChange: {
type: Function as PropType<
(
value: RangeValue<DateType> | RangeValue<string> | null,
dateString: [string, string],
) => void
>,
},
'onUpdate:value': {
type: Function as PropType<(value: RangeValue<DateType> | RangeValue<string> | null) => void>,
},
onCalendarChange: {
type: Function as PropType<
(
values: RangeValue<DateType> | RangeValue<string>,
formatString: [string, string],
info: RangeInfo,
) => void
>,
},
onPanelChange: {
type: Function as PropType<
(values: RangeValue<DateType> | RangeValue<string>, modes: [PanelMode, PanelMode]) => void
>,
},
onOk: {
type: Function as PropType<(dates: RangeValue<DateType> | RangeValue<string>) => void>,
},
}; };
} }
export interface RangePickerProps<DateType> { export interface RangePickerProps<DateType> {
allowEmpty?: [boolean, boolean]; allowEmpty?: [boolean, boolean];
dateRender?: RangeDateRender<DateType>; dateRender?: RangeDateRender<DateType>;
defaultPickerValue?: [DateType, DateType] | [string, string]; defaultPickerValue?: RangeValue<DateType> | RangeValue<string>;
defaultValue?: [DateType, DateType] | [string, string]; defaultValue?: RangeValue<DateType> | RangeValue<string>;
value?: [DateType, DateType] | [string, string]; value?: RangeValue<DateType> | RangeValue<string>;
disabledTime?: (date: EventValue<DateType>, type: RangeType) => DisabledTimes; disabledTime?: (date: EventValue<DateType>, type: RangeType) => DisabledTimes;
disabled?: [boolean, boolean]; disabled?: [boolean, boolean];
format?: string; format?: string;
@ -194,6 +244,21 @@ export interface RangePickerProps<DateType> {
>; >;
placeholder?: [string, string]; placeholder?: [string, string];
mode?: [PanelMode, PanelMode]; mode?: [PanelMode, PanelMode];
onChange?: (
value: RangeValue<DateType> | RangeValue<string> | null,
dateString: [string, string],
) => void;
'onUpdate:value'?: (value: RangeValue<DateType> | RangeValue<string> | null) => void;
onCalendarChange?: (
values: RangeValue<DateType> | RangeValue<string>,
formatString: [string, string],
info: RangeInfo,
) => void;
onPanelChange?: (
values: RangeValue<DateType> | RangeValue<string>,
modes: [PanelMode, PanelMode],
) => void;
onOk?: (dates: RangeValue<DateType> | RangeValue<string>) => void;
} }
export type ExtraDatePickerProps<DateType> = { export type ExtraDatePickerProps<DateType> = {
@ -205,9 +270,9 @@ export type ExtraDatePickerProps<DateType> = {
export type ExtraRangePickerProps<DateType> = { export type ExtraRangePickerProps<DateType> = {
valueFormat?: string; valueFormat?: string;
defaultPickerValue?: [DateType, DateType] | [string, string]; defaultPickerValue?: RangeValue<DateType> | RangeValue<string>;
defaultValue?: [DateType, DateType] | [string, string]; defaultValue?: RangeValue<DateType> | RangeValue<string>;
value?: [DateType, DateType] | [string, string]; value?: RangeValue<DateType> | RangeValue<string>;
}; };
export { commonProps, datePickerProps, rangePickerProps }; export { commonProps, datePickerProps, rangePickerProps };

View File

@ -12,6 +12,7 @@ import type { PanelMode, RangeValue } from '../vc-picker/interface';
import type { RangePickerSharedProps } from '../vc-picker/RangePicker'; import type { RangePickerSharedProps } from '../vc-picker/RangePicker';
import devWarning from '../vc-util/devWarning'; import devWarning from '../vc-util/devWarning';
import { useInjectFormItemContext } from '../form/FormItemContext'; import { useInjectFormItemContext } from '../form/FormItemContext';
import omit from '../_util/omit';
export interface TimePickerLocale { export interface TimePickerLocale {
placeholder?: string; placeholder?: string;
@ -57,11 +58,7 @@ export type TimePickerProps<DateType> = CommonProps<DateType> &
addon?: () => void; addon?: () => void;
}; };
function createTimePicker< function createTimePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
DateType,
DTimePickerProps extends TimePickerProps<DateType> = TimePickerProps<DateType>,
DTimeRangePickerProps extends TimeRangePickerProps<DateType> = TimeRangePickerProps<DateType>,
>(generateConfig: GenerateConfig<DateType>) {
const DatePicker = generatePicker<DateType>(generateConfig, { const DatePicker = generatePicker<DateType>(generateConfig, {
...timePickerProps, ...timePickerProps,
order: { type: Boolean, default: true }, order: { type: Boolean, default: true },
@ -69,11 +66,16 @@ function createTimePicker<
const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker as any; const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker as any;
const TimePicker = defineComponent<DTimePickerProps>({ const TimePicker = defineComponent({
name: 'ATimePicker', name: 'ATimePicker',
inheritAttrs: false, inheritAttrs: false,
props: {
...commonProps<DateType>(),
...datePickerProps<DateType>(),
...timePickerProps,
addon: { type: Function },
},
slot: ['addon', 'renderExtraFooter', 'suffixIcon', 'clearIcon'], slot: ['addon', 'renderExtraFooter', 'suffixIcon', 'clearIcon'],
emits: ['change', 'openChange', 'focus', 'blur', 'ok', 'update:value', 'update:open'],
setup(props, { slots, expose, emit, attrs }) { setup(props, { slots, expose, emit, attrs }) {
const formItemContext = useInjectFormItemContext(); const formItemContext = useInjectFormItemContext();
devWarning( devWarning(
@ -114,7 +116,7 @@ function createTimePicker<
return ( return (
<InternalTimePicker <InternalTimePicker
{...attrs} {...attrs}
{...restProps} {...omit(restProps, ['onUpdate:value', 'onUpdate:open'])}
id={id} id={id}
dropdownClassName={props.popupClassName} dropdownClassName={props.popupClassName}
mode={undefined} mode={undefined}
@ -134,28 +136,16 @@ function createTimePicker<
}, },
}); });
TimePicker.props = { const TimeRangePicker = defineComponent({
...commonProps<DateType>(),
...datePickerProps<DateType>(),
...timePickerProps,
addon: { type: Function },
};
const TimeRangePicker = defineComponent<DTimeRangePickerProps>({
name: 'ATimeRangePicker', name: 'ATimeRangePicker',
inheritAttrs: false, inheritAttrs: false,
props: {
...commonProps<DateType>(),
...rangePickerProps<DateType>(),
...timePickerProps,
order: { type: Boolean, default: true },
},
slot: ['renderExtraFooter', 'suffixIcon', 'clearIcon'], slot: ['renderExtraFooter', 'suffixIcon', 'clearIcon'],
emits: [
'change',
'panelChange',
'ok',
'openChange',
'update:value',
'update:open',
'calendarChange',
'focus',
'blur',
],
setup(props, { slots, expose, emit, attrs }) { setup(props, { slots, expose, emit, attrs }) {
const pickerRef = ref(); const pickerRef = ref();
@ -209,7 +199,7 @@ function createTimePicker<
return ( return (
<InternalRangePicker <InternalRangePicker
{...attrs} {...attrs}
{...restProps} {...omit(restProps, ['onUpdate:open', 'onUpdate:value'])}
id={id} id={id}
dropdownClassName={props.popupClassName} dropdownClassName={props.popupClassName}
picker="time" picker="time"
@ -229,13 +219,6 @@ function createTimePicker<
}, },
}); });
TimeRangePicker.props = {
...commonProps<DateType>(),
...rangePickerProps<DateType>(),
...timePickerProps,
order: { type: Boolean, default: true },
};
return { return {
TimePicker, TimePicker,
TimeRangePicker, TimeRangePicker,