mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 08:59:15 +08:00
5904f80a9a
* docs: update docs * chore: fix lint * chore: bump rc-picker * docs: timepicker docs * chore: update ignore
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import { DatePicker } from 'antd';
|
|
import type { Dayjs } from 'dayjs';
|
|
import React, { useState } from 'react';
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
type RangeValue = [Dayjs | null, Dayjs | null] | null;
|
|
|
|
const App: React.FC = () => {
|
|
const [dates, setDates] = useState<RangeValue>(null);
|
|
const [value, setValue] = useState<RangeValue>(null);
|
|
|
|
const disabledDate = (current: Dayjs) => {
|
|
if (!dates) {
|
|
return false;
|
|
}
|
|
const tooLate = dates[0] && current.diff(dates[0], 'days') >= 7;
|
|
const tooEarly = dates[1] && dates[1].diff(current, 'days') >= 7;
|
|
return !!tooEarly || !!tooLate;
|
|
};
|
|
|
|
const onOpenChange = (open: boolean) => {
|
|
if (open) {
|
|
setDates([null, null]);
|
|
} else {
|
|
setDates(null);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<RangePicker
|
|
value={dates || value}
|
|
disabledDate={disabledDate}
|
|
onCalendarChange={(val) => {
|
|
setDates(val);
|
|
}}
|
|
onChange={(val) => {
|
|
setValue(val);
|
|
}}
|
|
onOpenChange={onOpenChange}
|
|
changeOnBlur
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default App;
|