2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-09-11 17:28:04 +08:00
|
|
|
import type { Dayjs } from 'dayjs';
|
|
|
|
|
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';
|
2024-01-29 15:34:48 +08:00
|
|
|
import type { AnyObject } from '../_util/type';
|
2023-09-11 17:28:04 +08:00
|
|
|
import { devUseWarning } from '../_util/warning';
|
2023-06-07 11:54:50 +08:00
|
|
|
import DatePicker from '../date-picker';
|
2024-01-29 15:34:48 +08:00
|
|
|
import type {
|
2024-03-14 21:06:08 +08:00
|
|
|
GenericTimePickerProps,
|
2024-01-29 15:34:48 +08:00
|
|
|
PickerPropsWithMultiple,
|
|
|
|
RangePickerProps,
|
|
|
|
} from '../date-picker/generatePicker/interface';
|
|
|
|
|
|
|
|
export type PickerTimeProps<DateType extends AnyObject> = PickerPropsWithMultiple<
|
|
|
|
DateType,
|
2024-03-14 21:06:08 +08:00
|
|
|
GenericTimePickerProps<DateType>
|
2024-01-29 15:34:48 +08:00
|
|
|
>;
|
|
|
|
|
|
|
|
export type RangePickerTimeProps<DateType extends AnyObject> = Omit<
|
|
|
|
RangePickerProps<DateType>,
|
|
|
|
'showTime' | 'picker'
|
|
|
|
>;
|
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;
|
2023-08-07 18:05:05 +08:00
|
|
|
rootClassName?: 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) => {
|
2023-09-11 17:28:04 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2023-09-13 22:07:33 +08:00
|
|
|
const warning = devUseWarning('TimePicker');
|
|
|
|
|
|
|
|
warning.deprecated(!addon, 'addon', 'renderExtraFooter');
|
2023-09-11 17:28:04 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
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;
|