mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-01 23:29:30 +08:00
e3d2754b1d
* fix(time-picker): combine dropdownClassName and popupClassName prop * test(time-picker): add test for popupClassName and dropdownClassName prop * chore(time-picker): add demo for popupClassName prop * test(time-picker): remove rc-picker dependency * doc(time-picker): change default prop of popupClassName to undefined * fix(time-picker): remove the use of dropdownClassName * Apply suggestions from code review Co-authored-by: 偏右 <afc163@gmail.com>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { Moment } from 'moment';
|
|
import * as React from 'react';
|
|
import DatePicker from '../date-picker';
|
|
import { PickerTimeProps, RangePickerTimeProps } from '../date-picker/generatePicker';
|
|
import warning from '../_util/warning';
|
|
import { Omit } from '../_util/type';
|
|
|
|
const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker;
|
|
|
|
export interface TimePickerLocale {
|
|
placeholder?: string;
|
|
rangePlaceholder?: [string, string];
|
|
}
|
|
|
|
export interface TimeRangePickerProps extends RangePickerTimeProps<Moment> {}
|
|
|
|
const RangePicker = React.forwardRef<any, TimeRangePickerProps>((props, ref) => {
|
|
return <InternalRangePicker {...props} picker="time" mode={undefined} ref={ref} />;
|
|
});
|
|
|
|
export interface TimePickerProps extends Omit<PickerTimeProps<Moment>, 'picker'> {
|
|
addon?: () => React.ReactNode;
|
|
popupClassName?: string;
|
|
}
|
|
|
|
const TimePicker = React.forwardRef<any, TimePickerProps>(
|
|
({ addon, renderExtraFooter, popupClassName, ...restProps }, ref) => {
|
|
const internalRenderExtraFooter = React.useMemo(() => {
|
|
if (renderExtraFooter) {
|
|
return renderExtraFooter;
|
|
}
|
|
if (addon) {
|
|
warning(
|
|
false,
|
|
'TimePicker',
|
|
'`addon` is deprecated. Please use `renderExtraFooter` instead.',
|
|
);
|
|
return addon;
|
|
}
|
|
return undefined;
|
|
}, [addon, renderExtraFooter]);
|
|
|
|
return (
|
|
<InternalTimePicker
|
|
{...restProps}
|
|
dropdownClassName={popupClassName}
|
|
mode={undefined}
|
|
ref={ref}
|
|
renderExtraFooter={internalRenderExtraFooter}
|
|
/>
|
|
);
|
|
},
|
|
);
|
|
|
|
TimePicker.displayName = 'TimePicker';
|
|
|
|
type MergedTimePicker = typeof TimePicker & {
|
|
RangePicker: typeof RangePicker;
|
|
};
|
|
|
|
(TimePicker as MergedTimePicker).RangePicker = RangePicker;
|
|
|
|
export default TimePicker as MergedTimePicker;
|