fix: date-picker props

pull/4499/head
tangjinzhou 2021-08-03 09:29:10 +08:00
parent cd04ba21cf
commit 55f0d33a6d
6 changed files with 111 additions and 29 deletions

View File

@ -12,13 +12,29 @@ import { getTimeProps, Components } from '.';
import { defineComponent, ref } from 'vue'; import { defineComponent, ref } from 'vue';
import useConfigInject from '../../_util/hooks/useConfigInject'; import useConfigInject from '../../_util/hooks/useConfigInject';
import classNames from '../../_util/classNames'; import classNames from '../../_util/classNames';
import { commonProps, rangePickerProps } from './props';
import Omit from 'omit.js';
export default function generateRangePicker<DateType>(generateConfig: GenerateConfig<DateType>) { export default function generateRangePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
const RangePicker = defineComponent<RangePickerProps<DateType>>({ const RangePicker = defineComponent<RangePickerProps<DateType>>({
name: 'ARangePicker', name: 'ARangePicker',
inheritAttrs: false, inheritAttrs: false,
props: ['size', 'prefixCls', 'direction', 'getPopupContainer', 'locale', 'value'] as any, props: {
slots: ['suffixIcon'], ...commonProps<DateType>(),
...rangePickerProps<DateType>(),
} as any,
slots: [
'suffixIcon',
// 'clearIcon',
// 'prevIcon',
// 'nextIcon',
// 'superPrevIcon',
// 'superNextIcon',
// 'panelRender',
'dateRender',
'renderExtraFooter',
// 'separator',
],
emits: ['change', 'panelChange', 'ok', 'openChange', 'update:value', 'calendarChange'], emits: ['change', 'panelChange', 'ok', 'openChange', 'update:value', 'calendarChange'],
setup(props, { expose, slots, attrs, emit }) { setup(props, { expose, slots, attrs, emit }) {
const { prefixCls, direction, getPopupContainer, size, rootPrefixCls } = useConfigInject( const { prefixCls, direction, getPopupContainer, size, rootPrefixCls } = useConfigInject(
@ -62,6 +78,7 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
const pre = prefixCls.value; const pre = prefixCls.value;
return ( return (
<VCRangePicker<DateType> <VCRangePicker<DateType>
{...Omit(slots, ['default'])}
{...restProps} {...restProps}
separator={ separator={
<span aria-label="to" class={`${pre}-separator`}> <span aria-label="to" class={`${pre}-separator`}>

View File

@ -2,22 +2,19 @@ import CalendarOutlined from '@ant-design/icons-vue/CalendarOutlined';
import ClockCircleOutlined from '@ant-design/icons-vue/ClockCircleOutlined'; import ClockCircleOutlined from '@ant-design/icons-vue/ClockCircleOutlined';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled'; import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import RCPicker from '../../vc-picker'; import RCPicker from '../../vc-picker';
import type { DisabledTime, PanelMode, PickerMode } from '../../vc-picker/interface'; import type { PickerMode } from '../../vc-picker/interface';
import type { GenerateConfig } from '../../vc-picker/generate/index'; import type { GenerateConfig } from '../../vc-picker/generate/index';
import enUS from '../locale/en_US'; import enUS from '../locale/en_US';
import { getPlaceholder } from '../util'; import { getPlaceholder } from '../util';
import { useLocaleReceiver } from '../../locale-provider/LocaleReceiver'; import { useLocaleReceiver } from '../../locale-provider/LocaleReceiver';
import type { PickerProps, PickerDateProps, PickerTimeProps, PickerLocale } from '.'; import type { PickerProps, PickerDateProps, PickerTimeProps } from '.';
import { getTimeProps, Components } from '.'; import { getTimeProps, Components } from '.';
import { CSSProperties, defineComponent, PropType, ref } from 'vue'; import { defineComponent, ref } from 'vue';
import useConfigInject from '../../_util/hooks/useConfigInject'; import useConfigInject from '../../_util/hooks/useConfigInject';
import classNames from '../../_util/classNames'; import classNames from '../../_util/classNames';
import { AlignType } from '../../vc-align/interface'; import { commonProps, datePickerProps } from './props';
import { VueNode } from '../../_util/type'; import Omit from 'omit.js';
import { SharedTimeProps } from '../../vc-picker/panels/TimePanel'; import devWarning from '../../vc-util/devWarning';
import { SizeType } from '../../config-provider';
import { DateRender } from '../../vc-picker/panels/DatePanel/DateBody';
import { commonProps } from './props';
export default function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) { export default function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
type DatePickerProps = PickerProps<DateType>; type DatePickerProps = PickerProps<DateType>;
@ -31,10 +28,27 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
inheritAttrs: false, inheritAttrs: false,
props: { props: {
...commonProps<DateType>(), ...commonProps<DateType>(),
...datePickerProps<DateType>(),
} as any, } as any,
slots: ['suffixIcon', 'panelRender', 'dateRender'], slots: [
'suffixIcon',
// 'clearIcon',
// 'prevIcon',
// 'nextIcon',
// 'superPrevIcon',
// 'superNextIcon',
// 'panelRender',
'dateRender',
'renderExtraFooter',
'monthCellRender',
],
emits: ['change', 'openChange', 'focus', 'blur', 'panelChange', 'ok', 'update:value'], emits: ['change', 'openChange', 'focus', 'blur', 'panelChange', 'ok', 'update:value'],
setup(props, { slots, expose, attrs, emit }) { setup(props, { slots, expose, attrs, emit }) {
devWarning(
!(props as any).monthCellContentRender,
'DatePicker',
'`monthCellContentRender` is deprecated. Please use `monthCellRender"` instead.',
);
const { prefixCls, direction, getPopupContainer, size, rootPrefixCls } = useConfigInject( const { prefixCls, direction, getPopupContainer, size, rootPrefixCls } = useConfigInject(
'picker', 'picker',
props, props,
@ -89,6 +103,7 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
const pre = prefixCls.value; const pre = prefixCls.value;
return ( return (
<RCPicker<DateType> <RCPicker<DateType>
{...Omit(slots, ['default'])}
ref={pickerRef} ref={pickerRef}
placeholder={getPlaceholder(mergedPicker, locale, placeholder)} placeholder={getPlaceholder(mergedPicker, locale, placeholder)}
suffixIcon={ suffixIcon={

View File

@ -2,9 +2,19 @@ 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';
import type { AlignType } from '../../vc-align/interface'; import type { AlignType } from '../../vc-align/interface';
import type { PanelMode, PickerMode } from '../../vc-picker/interface'; import type {
CustomFormat,
DisabledTime,
DisabledTimes,
EventValue,
PanelMode,
PickerMode,
RangeValue,
} from '../../vc-picker/interface';
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 { SharedTimeProps } from '../../vc-picker/panels/TimePanel'; import type { SharedTimeProps } from '../../vc-picker/panels/TimePanel';
import type { RangeDateRender, RangeType } from '../../vc-picker/RangePicker';
import type { VueNode } from '../../_util/type'; import type { VueNode } from '../../_util/type';
function commonProps<DateType>() { function commonProps<DateType>() {
@ -68,7 +78,46 @@ function commonProps<DateType>() {
function datePickerProps<DateType>() { function datePickerProps<DateType>() {
return { return {
defaultPickerValue: { type: [String, Object] as PropType<DateType> }, defaultPickerValue: { type: [String, Object] as PropType<DateType> },
defaultValue: { type: [String, Object] as PropType<DateType> },
value: { type: [String, Object] as PropType<DateType> },
disabledTime: { type: Function as PropType<DisabledTime<DateType>> },
format: {
type: [String, Function, Array] as PropType<
string | CustomFormat<DateType> | (string | CustomFormat<DateType>)[]
>,
},
renderExtraFooter: { type: Function as PropType<(mode: PanelMode) => VueNode> },
showNow: { type: Boolean, default: undefined },
monthCellRender: { type: Function as PropType<MonthCellRender<DateType>> },
// deprecated Please use `monthCellRender"` instead.',
monthCellContentRender: { type: Function as PropType<MonthCellRender<DateType>> },
}; };
} }
export { commonProps, datePickerProps }; function rangePickerProps<DateType>() {
return {
allowEmpty: { type: Array as unknown as PropType<[boolean, boolean]> },
dateRender: { type: Function as PropType<RangeDateRender<DateType>> },
defaultPickerValue: { type: Array as unknown as PropType<[DateType, DateType]> },
defaultValue: { type: Array as unknown as PropType<[DateType, DateType]> },
value: { type: Array as unknown as PropType<[DateType, DateType]> },
disabledTime: {
type: Function as PropType<(date: EventValue<DateType>, type: RangeType) => DisabledTimes>,
},
disabled: { type: Array as unknown as PropType<[boolean, boolean]> },
format: String,
renderExtraFooter: { type: Function as PropType<() => VueNode> },
separator: { type: Function as PropType<() => VueNode> },
ranges: {
type: Object as PropType<
Record<
string,
Exclude<RangeValue<DateType>, null> | (() => Exclude<RangeValue<DateType>, null>)
>
>,
},
placeholder: Array,
};
}
export { commonProps, datePickerProps, rangePickerProps };

View File

@ -178,15 +178,15 @@ function Picker<DateType>() {
'autocomplete', 'autocomplete',
'showToday', 'showToday',
] as any, ] as any,
slots: [ // slots: [
'suffixIcon', // 'suffixIcon',
'clearIcon', // 'clearIcon',
'prevIcon', // 'prevIcon',
'nextIcon', // 'nextIcon',
'superPrevIcon', // 'superPrevIcon',
'superNextIcon', // 'superNextIcon',
'panelRender', // 'panelRender',
], // ],
setup(props, { attrs, expose }) { setup(props, { attrs, expose }) {
const inputRef = ref(null); const inputRef = ref(null);
const needConfirmButton = computed( const needConfirmButton = computed(

View File

@ -1,4 +1,5 @@
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import type { VueNode } from '../_util/type';
import type { GenerateConfig } from './generate'; import type { GenerateConfig } from './generate';
export type Locale = { export type Locale = {
@ -65,10 +66,10 @@ export type PanelSharedProps<DateType> = {
locale: Locale; locale: Locale;
disabledDate?: (date: DateType) => boolean; disabledDate?: (date: DateType) => boolean;
// prevIcon?: React.ReactNode; prevIcon?: VueNode;
// nextIcon?: React.ReactNode; nextIcon?: VueNode;
// superPrevIcon?: React.ReactNode; superPrevIcon?: VueNode;
// superNextIcon?: React.ReactNode; superNextIcon?: VueNode;
// /** // /**
// * Typescript can not handle generic type so we can not use `forwardRef` here. // * Typescript can not handle generic type so we can not use `forwardRef` here.

View File

@ -10,7 +10,7 @@ import useMergeProps from '../../hooks/useMergeProps';
export const MONTH_COL_COUNT = 3; export const MONTH_COL_COUNT = 3;
const MONTH_ROW_COUNT = 4; const MONTH_ROW_COUNT = 4;
export type MonthCellRender<DateType> = (currentDate: DateType, locale: Locale) => VueNode; export type MonthCellRender<DateType> = (obj: { current: DateType; locale: Locale }) => VueNode;
export type MonthBodyProps<DateType> = { export type MonthBodyProps<DateType> = {
prefixCls: string; prefixCls: string;
@ -51,7 +51,7 @@ function MonthBody<DateType>(_props: MonthBodyProps<DateType>) {
const baseMonth = generateConfig.setMonth(viewDate, 0); const baseMonth = generateConfig.setMonth(viewDate, 0);
const getCellNode = monthCellRender const getCellNode = monthCellRender
? (date: DateType) => monthCellRender(date, locale) ? (date: DateType) => monthCellRender({ current: date, locale })
: undefined; : undefined;
return ( return (