Skip to content

Commit

Permalink
fix: time-picker type error #5109
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jan 1, 2022
1 parent ad76bb6 commit b13756f
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 139 deletions.
41 changes: 20 additions & 21 deletions components/calendar/generateCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface CalendarProps<DateType> {
mode?: CalendarMode;
fullscreen?: boolean;
onChange?: (date: DateType | string) => void;
'onUpdate:value'?: (date: DateType | string) => void;
onPanelChange?: (date: DateType | string, mode: CalendarMode) => void;
onSelect?: (date: DateType | string) => void;
valueFormat?: string;
Expand Down Expand Up @@ -88,7 +89,25 @@ function generateCalendar<
const Calendar = defineComponent<Props>({
name: 'ACalendar',
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: [
'dateFullCellRender',
'dateCellRender',
Expand Down Expand Up @@ -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) {
app.component(Calendar.name, Calendar);
return app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ exports[`renders ./components/carousel/demo/basic.vue correctly 1`] = `
exports[`renders ./components/carousel/demo/customArrows.vue correctly 1`] = `
<div class="ant-carousel">
<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-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;">
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/demo/date-render.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineComponent({
};
return {
value1: ref<Dayjs>(),
value2: ref<Dayjs[]>([]),
value2: ref<[Dayjs, Dayjs]>(),
value3: ref<Dayjs>(),
getCurrentStyle,
};
Expand Down
6 changes: 3 additions & 3 deletions components/date-picker/demo/disabled-date.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default defineComponent({
};
};
const disabledRangeTime = (_: Dayjs[], type: 'start' | 'end') => {
const disabledRangeTime = (_: Dayjs, type: 'start' | 'end') => {
if (type === 'start') {
return {
disabledHours: () => range(0, 60).splice(4, 20),
Expand All @@ -87,8 +87,8 @@ export default defineComponent({
dayjs,
value1: ref<Dayjs>(),
value2: ref<Dayjs>(),
value3: ref<Dayjs[]>([]),
value4: ref<Dayjs[]>([]),
value3: ref<[Dayjs, Dayjs]>(),
value4: ref<[Dayjs, Dayjs]>(),
disabledDate,
disabledDateTime,
disabledRangeTime,
Expand Down
10 changes: 8 additions & 2 deletions components/date-picker/demo/disabled.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ export default defineComponent({
return {
value1: ref<Dayjs>(dayjs('2015-06-06', dateFormat)),
value2: ref<Dayjs>(dayjs('2015-06', 'YYYY-MM')),
value3: ref<Dayjs[]>([dayjs('2015-06-06', dateFormat), dayjs('2015-06-06', dateFormat)]),
value4: ref<Dayjs[]>([dayjs('2019-09-03', dateFormat), dayjs('2019-11-22', dateFormat)]),
value3: ref<[Dayjs, Dayjs]>([
dayjs('2015-06-06', dateFormat),
dayjs('2015-06-06', dateFormat),
]),
value4: ref<[Dayjs, Dayjs]>([
dayjs('2019-09-03', dateFormat),
dayjs('2019-11-22', dateFormat),
]),
};
},
});
Expand Down
5 changes: 4 additions & 1 deletion components/date-picker/demo/format.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export default defineComponent({
value1: ref<Dayjs>(dayjs('2015/01/01', dateFormat)),
value2: ref<Dayjs>(dayjs('01/01/2015', dateFormatList[0])),
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)),
dateFormat,
monthFormat,
Expand Down
12 changes: 6 additions & 6 deletions components/date-picker/demo/mode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ import { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const mode1 = ref<string>('time');
const mode2 = ref<string[]>(['month', 'month']);
const value = ref<Dayjs[]>([]);
const mode1 = ref<any>('time');
const mode2 = ref<any>(['month', 'month']);
const value = ref<[Dayjs, Dayjs]>();
const handleOpenChange1 = (open: boolean) => {
if (open) {
mode1.value = 'time';
}
};
const handleChange = (val: Dayjs[]) => {
const handleChange = (val: [Dayjs, Dayjs]) => {
value.value = val;
};
const handlePanelChange1 = (_val: Dayjs[], mode: string) => {
const handlePanelChange1 = (_val: [Dayjs, Dayjs], mode: any) => {
mode1.value = mode;
};
const handlePanelChange2 = (val: Dayjs[], mode: string[]) => {
const handlePanelChange2 = (val: [Dayjs, Dayjs], mode: any[]) => {
value.value = val;
mode2.value = [
mode[0] === 'date' ? 'month' : mode[0],
Expand Down
10 changes: 7 additions & 3 deletions components/date-picker/demo/presetted-ranges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ We can set presetted ranges to RangePicker to improve user experience.
<script lang="ts">
import dayjs, { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue';
type RangeValue = [Dayjs, Dayjs];
export default defineComponent({
setup() {
return {
value1: ref<Dayjs[]>([]),
value2: ref<Dayjs[]>([]),
ranges: { Today: [dayjs(), dayjs()], 'This Month': [dayjs(), dayjs().endOf('month')] },
value1: ref<RangeValue>(),
value2: ref<RangeValue>(),
ranges: {
Today: [dayjs(), dayjs()] as RangeValue,
'This Month': [dayjs(), dayjs().endOf('month')] as RangeValue,
},
};
},
});
Expand Down
11 changes: 6 additions & 5 deletions components/date-picker/demo/range-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ Set range picker type by `picker` prop.
<script lang="ts">
import { defineComponent, ref } from 'vue';
import type { Dayjs } from 'dayjs';
type RangeValue = [Dayjs, Dayjs];
export default defineComponent({
setup() {
return {
value1: ref<Dayjs[]>([]),
value2: ref<Dayjs[]>([]),
value3: ref<Dayjs[]>([]),
value4: ref<Dayjs[]>([]),
value5: ref<Dayjs[]>([]),
value1: ref<RangeValue>(),
value2: ref<RangeValue>(),
value3: ref<RangeValue>(),
value4: ref<RangeValue>(),
value5: ref<RangeValue>(),
};
},
});
Expand Down
17 changes: 9 additions & 8 deletions components/date-picker/demo/select-in-range.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ A example shows how to select a dynamic range by using `onCalendarChange` and `d
<script lang="ts">
import { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue';
type RangeValue = [Dayjs, Dayjs];
export default defineComponent({
setup() {
const dates = ref<Dayjs[]>([]);
const value = ref<Dayjs[]>();
const hackValue = ref<Dayjs[]>();
const dates = ref<RangeValue>();
const value = ref<RangeValue>();
const hackValue = ref<RangeValue>();
const disabledDate = (current: Dayjs) => {
if (!dates.value || dates.value.length === 0) {
if (!dates.value) {
return false;
}
const tooLate = dates.value[0] && current.diff(dates.value[0], 'days') > 7;
Expand All @@ -44,18 +45,18 @@ export default defineComponent({
const onOpenChange = (open: boolean) => {
if (open) {
dates.value = [];
hackValue.value = [];
dates.value = null;
hackValue.value = null;
} else {
hackValue.value = undefined;
}
};
const onChange = (val: Dayjs[]) => {
const onChange = (val: RangeValue) => {
value.value = val;
};
const onCalendarChange = (val: Dayjs[]) => {
const onCalendarChange = (val: RangeValue) => {
dates.value = val;
};
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/demo/size.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
return {
size: ref<string>('default'),
size: ref<any>('default'),
};
},
});
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/demo/start-end.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { Dayjs } from 'dayjs';
import { defineComponent, ref, watch } from 'vue';
export default defineComponent({
setup() {
const startValue = ref<Dayjs | undefined>();
const startValue = ref<Dayjs>();
const endValue = ref<Dayjs>();
const endOpen = ref<boolean>(false);
Expand Down
10 changes: 7 additions & 3 deletions components/date-picker/demo/suffix.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Customize the suffix icon through `suffixIcon`
<SmileOutlined />
</template>
</a-date-picker>
<a-range-picker @change="onChange">
<a-range-picker @change="onRangeChange">
<template #suffixIcon>
<SmileOutlined />
</template>
Expand All @@ -40,7 +40,7 @@ Customize the suffix icon through `suffixIcon`
</a-date-picker>
<a-date-picker suffix-icon="ab" @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-space>
</template>
Expand All @@ -53,12 +53,16 @@ export default defineComponent({
SmileOutlined,
},
setup() {
const onChange = (date: Dayjs, dateString: string[]) => {
const onChange = (date: Dayjs | string, dateString: string) => {
console.log(date, dateString);
};
const onRangeChange = (date: [Dayjs, Dayjs], dateString: [string, string]) => {
console.log(date, dateString);
};
return {
onChange,
onRangeChange,
};
},
});
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/demo/switchable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
return {
type: ref('time'),
type: ref<any>('time'),
};
},
});
Expand Down
2 changes: 1 addition & 1 deletion components/date-picker/demo/text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const time1 = ref<Dayjs>();
const time2 = ref<Dayjs>();
const time2 = ref<[Dayjs, Dayjs]>();
const onOk = (value: Dayjs) => {
console.log('onOk: ', value);
Expand Down
19 changes: 15 additions & 4 deletions components/date-picker/demo/time.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ This property provide an additional time selection. When `showTime` is an Object
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm"
:placeholder="['Start Time', 'End Time']"
@change="onChange"
@ok="onOk"
@change="onRangeChange"
@ok="onRangeOk"
/>
</a-space>
</template>
Expand All @@ -33,18 +33,29 @@ import { Dayjs } from 'dayjs';
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
const onChange = (value: Dayjs[], dateString: string[]) => {
const onChange = (value: Dayjs, dateString: string) => {
console.log('Selected Time: ', value);
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);
};
return {
onChange,
onOk,
onRangeChange,
onRangeOk,
};
},
});
Expand Down
13 changes: 2 additions & 11 deletions components/date-picker/generatePicker/generateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
'renderExtraFooter',
// 'separator',
],
emits: [
'change',
'panelChange',
'ok',
'openChange',
'update:value',
'update:open',
'calendarChange',
'focus',
'blur',
],
setup(props, { expose, slots, attrs, emit }) {
const formItemContext = useInjectFormItemContext();
devWarning(
Expand Down Expand Up @@ -161,6 +150,8 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
id = formItemContext.id.value,
...restProps
} = p;
delete restProps['onUpdate:value'];
delete restProps['onUpdate:open'];
const { format, showTime } = p as any;

let additionalOverrideProps: any = {};
Expand Down
Loading

0 comments on commit b13756f

Please sign in to comment.