import {
TimePicker as OldTimePicker,
TimePickerProps,
ConfigProvider,
TimeRangePickerProps,
} from 'antd';
import React, { useContext, useEffect, useMemo, useState } from 'react';
import './index.less';
import classNames from 'classnames';
import locale from 'antd/es/date-picker/locale/zh_CN';
import { Icon } from '../Icon';
import { Button } from '../Button';
import moment from 'moment';
import { AOP } from '../utils/AOP';
import { translate } from '../utils';
interface TimePickerExtraProps {}
const TimePicker = (props: TimePickerProps & TimePickerExtraProps) => {
// 为了与 antd 的生态保持兼容性,我们要求必须要使用 `.@{ant-prefix}` 变量来生成类名
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('btri-timePicker');
const popupCls = getPrefixCls('btri-timePicker-popup');
const { popupClassName, showNow = true, value, onChange } = props;
const [timeValue, setTimeValue] = useState(value);
useEffect(() => {
setTimeValue(value);
}, [value]);
const nowNode = useMemo(() => {
return (
<>
{showNow && (
)}
>
);
}, [showNow]);
const newOnChange = new AOP(onChange)
.after((val) => {
setTimeValue(val as moment.Moment);
})
.getFunction();
return (
}
// clearIcon={}
renderExtraFooter={() => nowNode}
{...props}
showNow={false}
popupClassName={classNames(`${popupCls}-box`, popupClassName)}
value={timeValue}
onChange={newOnChange}
>
);
};
interface RangePickerExtraProps {}
const RangePicker: React.FC = (
props,
) => {
// 为了与 antd 的生态保持兼容性,我们要求必须要使用 `.@{ant-prefix}` 变量来生成类名
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('btri-timeRangePicker');
const popupCls = getPrefixCls('btri-timeRangePicker-popup');
const { popupClassName, onChange, showNow = true } = props;
const [timeRangeValue, setTimeRangeValue] = React.useState<
[moment.Moment, moment.Moment]
>([null, null]);
const newOnChange = new AOP<
[moment.Moment, moment.Moment] | [string, string],
void
>(onChange)
.after((vals) => {
setTimeRangeValue(vals as [moment.Moment, moment.Moment]);
})
.getFunction();
useEffect(() => {
setTimeRangeValue(props.value);
}, [props.value]);
const nowNode = useMemo(() => {
return (
<>
{showNow && (
)}
>
);
}, [showNow]);
return (
}
// clearIcon={
//
// }
renderExtraFooter={() => nowNode}
{...props}
showNow={false}
value={timeRangeValue}
onChange={newOnChange}
popupClassName={classNames(`${popupCls}-box`, popupClassName)}
>
);
};
TimePicker.RangePicker = RangePicker;
export { TimePicker };