2022-02-14 14:40:40 +08:00
|
|
|
import type { Dayjs } from 'dayjs';
|
2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2019-12-11 23:32:19 +08:00
|
|
|
import DatePicker from '../date-picker';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { PickerTimeProps, RangePickerTimeProps } from '../date-picker/generatePicker';
|
2022-07-13 23:06:28 +08:00
|
|
|
import genPurePanel from '../_util/PurePanel';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { InputStatus } from '../_util/statusUtils';
|
2022-06-21 10:24:52 +08:00
|
|
|
import warning from '../_util/warning';
|
2016-08-22 17:26:14 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker;
|
2017-11-20 18:27:36 +08:00
|
|
|
|
2020-03-11 21:08:15 +08:00
|
|
|
export interface TimePickerLocale {
|
|
|
|
placeholder?: string;
|
|
|
|
rangePlaceholder?: [string, string];
|
|
|
|
}
|
|
|
|
|
2022-02-14 14:40:40 +08:00
|
|
|
export interface TimeRangePickerProps extends Omit<RangePickerTimeProps<Dayjs>, 'picker'> {
|
2022-08-05 11:21:07 +08:00
|
|
|
/**
|
|
|
|
* @deprecated `dropdownClassName` is deprecated which will be removed in next major
|
|
|
|
* version.Please use `popupClassName` instead.
|
|
|
|
*/
|
|
|
|
dropdownClassName?: string;
|
2021-03-02 22:09:21 +08:00
|
|
|
popupClassName?: string;
|
|
|
|
}
|
2015-11-16 23:11:41 +08:00
|
|
|
|
2022-08-05 11:21:07 +08:00
|
|
|
const RangePicker = React.forwardRef<any, TimeRangePickerProps>((props, ref) => {
|
|
|
|
const { dropdownClassName, popupClassName } = props;
|
|
|
|
warning(
|
|
|
|
!dropdownClassName,
|
|
|
|
'RangePicker',
|
|
|
|
'`dropdownClassName` is deprecated which will be removed in next major version. Please use `popupClassName` instead.',
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
<InternalRangePicker
|
|
|
|
{...props}
|
|
|
|
dropdownClassName={popupClassName || dropdownClassName}
|
|
|
|
picker="time"
|
|
|
|
mode={undefined}
|
|
|
|
ref={ref}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2018-08-08 14:47:13 +08:00
|
|
|
|
2022-02-14 14:40:40 +08:00
|
|
|
export interface TimePickerProps extends Omit<PickerTimeProps<Dayjs>, 'picker'> {
|
2019-12-11 23:32:19 +08:00
|
|
|
addon?: () => React.ReactNode;
|
2020-04-14 16:49:58 +08:00
|
|
|
popupClassName?: string;
|
2022-08-05 11:21:07 +08:00
|
|
|
/**
|
|
|
|
* @deprecated `dropdownClassName` is deprecated which will be removed in next major
|
|
|
|
* version.Please use `popupClassName` instead.
|
|
|
|
*/
|
|
|
|
dropdownClassName?: string;
|
2022-02-16 21:14:51 +08:00
|
|
|
status?: InputStatus;
|
2019-12-11 23:32:19 +08:00
|
|
|
}
|
2016-08-22 17:26:14 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
const TimePicker = React.forwardRef<any, TimePickerProps>(
|
2022-08-05 11:21:07 +08:00
|
|
|
({ addon, renderExtraFooter, popupClassName, dropdownClassName, ...restProps }, ref) => {
|
2019-12-11 23:32:19 +08:00
|
|
|
const internalRenderExtraFooter = React.useMemo(() => {
|
|
|
|
if (renderExtraFooter) {
|
|
|
|
return renderExtraFooter;
|
|
|
|
}
|
2022-08-05 11:21:07 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
if (addon) {
|
2022-05-10 15:43:29 +08:00
|
|
|
warning(
|
2019-12-11 23:32:19 +08:00
|
|
|
false,
|
|
|
|
'TimePicker',
|
|
|
|
'`addon` is deprecated. Please use `renderExtraFooter` instead.',
|
|
|
|
);
|
|
|
|
return addon;
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}, [addon, renderExtraFooter]);
|
2019-01-25 10:31:09 +08:00
|
|
|
|
2022-08-05 11:21:07 +08:00
|
|
|
warning(
|
|
|
|
!dropdownClassName,
|
|
|
|
'TimePicker',
|
|
|
|
'`dropdownClassName` is deprecated which will be removed in next major version. Please use `popupClassName` instead.',
|
|
|
|
);
|
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
return (
|
|
|
|
<InternalTimePicker
|
2022-08-05 11:21:07 +08:00
|
|
|
dropdownClassName={popupClassName || dropdownClassName}
|
2019-12-11 23:32:19 +08:00
|
|
|
{...restProps}
|
|
|
|
mode={undefined}
|
|
|
|
ref={ref}
|
|
|
|
renderExtraFooter={internalRenderExtraFooter}
|
|
|
|
/>
|
2019-01-25 10:31:09 +08:00
|
|
|
);
|
2019-12-11 23:32:19 +08:00
|
|
|
},
|
|
|
|
);
|
2019-08-05 18:38:10 +08:00
|
|
|
|
2022-06-21 10:24:52 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
TimePicker.displayName = 'TimePicker';
|
|
|
|
}
|
2017-02-21 15:10:28 +08:00
|
|
|
|
2022-07-11 14:58:59 +08:00
|
|
|
// We don't care debug panel
|
|
|
|
/* istanbul ignore next */
|
|
|
|
const PurePanel = genPurePanel(TimePicker, 'picker');
|
|
|
|
(TimePicker as MergedTimePicker)._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
type MergedTimePicker = typeof TimePicker & {
|
|
|
|
RangePicker: typeof RangePicker;
|
2022-07-11 14:58:59 +08:00
|
|
|
_InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel;
|
2019-12-11 23:32:19 +08:00
|
|
|
};
|
2017-11-19 01:41:40 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
(TimePicker as MergedTimePicker).RangePicker = RangePicker;
|
2022-07-11 14:58:59 +08:00
|
|
|
(TimePicker as MergedTimePicker)._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
2018-08-08 14:47:13 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
export default TimePicker as MergedTimePicker;
|