2019-12-11 23:32:19 +08:00
|
|
|
import { 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';
|
|
|
|
import { PickerTimeProps, RangePickerTimeProps } from '../date-picker/generatePicker';
|
2020-05-14 15:57:04 +08:00
|
|
|
import devWarning from '../_util/devWarning';
|
2019-12-25 16:23:14 +08:00
|
|
|
import { Omit } from '../_util/type';
|
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'> {
|
|
|
|
popupClassName?: string;
|
|
|
|
}
|
2015-11-16 23:11:41 +08:00
|
|
|
|
2020-12-09 17:12:32 +08:00
|
|
|
const RangePicker = React.forwardRef<any, TimeRangePickerProps>((props, ref) => (
|
2021-03-02 22:09:21 +08:00
|
|
|
<InternalRangePicker
|
|
|
|
{...props}
|
|
|
|
dropdownClassName={props.popupClassName}
|
|
|
|
picker="time"
|
|
|
|
mode={undefined}
|
|
|
|
ref={ref}
|
|
|
|
/>
|
2020-12-09 17:12:32 +08:00
|
|
|
));
|
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;
|
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>(
|
2020-04-14 16:49:58 +08:00
|
|
|
({ addon, renderExtraFooter, popupClassName, ...restProps }, ref) => {
|
2019-12-11 23:32:19 +08:00
|
|
|
const internalRenderExtraFooter = React.useMemo(() => {
|
|
|
|
if (renderExtraFooter) {
|
|
|
|
return renderExtraFooter;
|
|
|
|
}
|
|
|
|
if (addon) {
|
2020-05-14 15:57:04 +08:00
|
|
|
devWarning(
|
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
|
|
|
|
{...restProps}
|
2020-04-14 16:49:58 +08:00
|
|
|
dropdownClassName={popupClassName}
|
2019-12-11 23:32:19 +08:00
|
|
|
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
|
|
|
|
2019-12-11 23:32:19 +08:00
|
|
|
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;
|