2023-07-15 12:57:03 +08:00
|
|
|
'use client';
|
|
|
|
|
2022-02-14 14:40:40 +08:00
|
|
|
import type { Dayjs } from 'dayjs';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
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';
|
2023-06-07 11:54:50 +08:00
|
|
|
import DatePicker from '../date-picker';
|
|
|
|
import type { PickerTimeProps, RangePickerTimeProps } from '../date-picker/generatePicker';
|
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'> {
|
2021-03-02 22:09:21 +08:00
|
|
|
popupClassName?: string;
|
|
|
|
}
|
2015-11-16 23:11:41 +08:00
|
|
|
|
2022-08-25 10:33:16 +08:00
|
|
|
const RangePicker = React.forwardRef<any, TimeRangePickerProps>((props, ref) => (
|
|
|
|
<InternalRangePicker {...props} 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;
|
2022-02-16 21:14:51 +08:00
|
|
|
status?: InputStatus;
|
2022-08-25 10:33:16 +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>(
|
2022-08-25 10:33:16 +08:00
|
|
|
({ addon, renderExtraFooter, ...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
|
|
|
|
{...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
|
2023-06-07 21:59:21 +08:00
|
|
|
/* istanbul ignore next */
|
2022-07-11 14:58:59 +08:00
|
|
|
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;
|