2022-11-09 12:28:04 +08:00
|
|
|
import React, { useState } from 'react';
|
2023-07-28 16:17:43 +08:00
|
|
|
import { DatePicker, Space } from 'antd';
|
2024-04-08 14:04:08 +08:00
|
|
|
import type { Dayjs } from 'dayjs';
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
|
|
const App: React.FC = () => {
|
|
|
|
const [startValue, setStartValue] = useState<Dayjs | null>(null);
|
|
|
|
const [endValue, setEndValue] = useState<Dayjs | null>(null);
|
|
|
|
const [endOpen, setEndOpen] = useState(false);
|
|
|
|
|
|
|
|
const disabledStartDate = (startDate: Dayjs) => {
|
|
|
|
if (!startDate || !endValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return startDate.valueOf() > endValue.valueOf();
|
|
|
|
};
|
|
|
|
|
|
|
|
const disabledEndDate = (endDate: Dayjs) => {
|
|
|
|
if (!endDate || !startValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return endDate.valueOf() <= startValue.valueOf();
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleStartOpenChange = (open: boolean) => {
|
|
|
|
if (!open) {
|
|
|
|
setEndOpen(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleEndOpenChange = (open: boolean) => {
|
|
|
|
setEndOpen(open);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Space>
|
|
|
|
<DatePicker
|
|
|
|
disabledDate={disabledStartDate}
|
|
|
|
showTime
|
|
|
|
format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
value={startValue}
|
|
|
|
placeholder="Start"
|
|
|
|
onChange={setStartValue}
|
|
|
|
onOpenChange={handleStartOpenChange}
|
|
|
|
/>
|
|
|
|
<DatePicker
|
|
|
|
disabledDate={disabledEndDate}
|
|
|
|
showTime
|
|
|
|
format="YYYY-MM-DD HH:mm:ss"
|
|
|
|
value={endValue}
|
|
|
|
placeholder="End"
|
|
|
|
onChange={setEndValue}
|
|
|
|
open={endOpen}
|
|
|
|
onOpenChange={handleEndOpenChange}
|
|
|
|
/>
|
|
|
|
</Space>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|