2022-05-07 14:31:54 +08:00
|
|
|
import type { Moment } from 'moment';
|
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';
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2021-03-02 22:09:21 +08:00
|
|
|
export interface TimeRangePickerProps extends Omit<RangePickerTimeProps<Moment>, '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;
|
|
|
|
return (
|
|
|
|
<InternalRangePicker
|
|
|
|
{...props}
|
2022-11-27 22:28:29 +08:00
|
|
|
dropdownClassName={dropdownClassName}
|
|
|
|
popupClassName={popupClassName}
|
2022-08-05 11:21:07 +08:00
|
|
|
picker="time"
|
|
|
|
mode={undefined}
|
|
|
|
ref={ref}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2018-08-08 14:47:13 +08:00
|
|
|
|
2019-12-25 16:23:14 +08:00
|
|
|
export interface TimePickerProps extends Omit<PickerTimeProps<Moment>, '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
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
return (
|
|
|
|
<InternalTimePicker
|
2022-11-27 22:28:29 +08:00
|
|
|
dropdownClassName={dropdownClassName}
|
|
|
|
popupClassName={popupClassName}
|
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
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
type MergedTimePicker = typeof TimePicker & {
|
|
|
|
RangePicker: typeof RangePicker;
|
|
|
|
};
|
2017-11-19 01:41:40 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
(TimePicker as MergedTimePicker).RangePicker = RangePicker;
|
2018-08-08 14:47:13 +08:00
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
export default TimePicker as MergedTimePicker;
|