From be231f9fb53d65b5fd820ea58259446a11a806e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 31 Dec 2021 11:28:02 +0800 Subject: [PATCH 01/33] feat: Merge TimePicker disabledXXX into disabledTime (#33503) * feat: merge disabledXXX into disabledTime * chore: fix ts --- .../date-picker/generatePicker/index.tsx | 16 ++++--- components/time-picker/index.en-US.md | 36 ++++++++++++--- components/time-picker/index.zh-CN.md | 44 ++++++++++++++----- package.json | 2 +- 4 files changed, 72 insertions(+), 26 deletions(-) diff --git a/components/date-picker/generatePicker/index.tsx b/components/date-picker/generatePicker/index.tsx index 26e14c4bc8..047d2082c4 100644 --- a/components/date-picker/generatePicker/index.tsx +++ b/components/date-picker/generatePicker/index.tsx @@ -27,13 +27,18 @@ function toArray(list: T | T[]): T[] { return Array.isArray(list) ? list : [list]; } -export function getTimeProps( - props: { format?: string; picker?: PickerMode } & SharedTimeProps, +export function getTimeProps( + props: { format?: string; picker?: PickerMode } & Omit< + SharedTimeProps, + 'disabledTime' + > & { + disabledTime?: DisabledTime; + }, ) { const { format, picker, showHour, showMinute, showSecond, use12Hours } = props; const firstFormat = toArray(format)[0]; - const showTimeObj: SharedTimeProps = { ...props }; + const showTimeObj = { ...props }; if (firstFormat && typeof firstFormat === 'string') { if (!firstFormat.includes('s') && showSecond === undefined) { @@ -67,10 +72,7 @@ export function getTimeProps( type InjectDefaultProps = Omit< Props, - | 'locale' - | 'generateConfig' - | 'hideHeader' - | 'components' + 'locale' | 'generateConfig' | 'hideHeader' | 'components' > & { locale?: PickerLocale; size?: SizeType; diff --git a/components/time-picker/index.en-US.md b/components/time-picker/index.en-US.md index c5190a6f71..92f6923b72 100644 --- a/components/time-picker/index.en-US.md +++ b/components/time-picker/index.en-US.md @@ -33,9 +33,7 @@ import moment from 'moment'; | clearText | The clear tooltip of icon | string | clear | | | defaultValue | To set default time | [moment](http://momentjs.com/) | - | | | disabled | Determine whether the TimePicker is disabled | boolean | false | | -| disabledHours | To specify the hours that cannot be selected | function() | - | | -| disabledMinutes | To specify the minutes that cannot be selected | function(selectedHour) | - | | -| disabledSeconds | To specify the seconds that cannot be selected | function(selectedHour, selectedMinute) | - | | +| disabledTime | To specify the time that cannot be selected | [DisabledTime](#DisabledTime) | - | 4.19.0 | | format | To set the time format | string | `HH:mm:ss` | | | getPopupContainer | To set the container of the floating layer, while the default is to create a div element in body | function(trigger) | - | | | hideDisabledOptions | Whether hide the options that can not be selected | boolean | false | | @@ -56,12 +54,22 @@ import moment from 'moment'; | onOpenChange | A callback function which will be called while panel opening/closing | (open: boolean) => void | - | | | onSelect | A callback function, executes when a value is selected | function(time: moment): void | - | | +#### DisabledTime + +```typescript +type DisabledTime = (now: Moment) => { + disabledHours?: () => number[]; + disabledMinutes?: (selectedHour: number) => number[]; + disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[]; +}; +``` + ## Methods -| Name | Description | Version | -| --- | --- | --- | -| blur() | Remove focus | | -| focus() | Get focus | | +| Name | Description | Version | +| ------- | ------------ | ------- | +| blur() | Remove focus | | +| focus() | Get focus | | ### RangePicker @@ -69,8 +77,22 @@ Same props from [RangePicker](/components/date-picker/#RangePicker) of DatePicke | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | +| disabledTime | To specify the time that cannot be selected | [RangeDisabledTime](#RangeDisabledTime) | - | 4.19.0 | | order | Order start and end time | boolean | true | 4.1.0 | +### RangeDisabledTime + +```typescript +type RangeDisabledTime = ( + now: Moment, + type = 'start' | 'end', +) => { + disabledHours?: () => number[]; + disabledMinutes?: (selectedHour: number) => number[]; + disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[]; +}; +``` +