docs(date-picker): modify datepicker select-in-range demo (#27751)

* feat: modify datepicker select-in-range demo

* fix: lint
This commit is contained in:
LeoYang 2020-11-13 17:05:16 +08:00 committed by GitHub
parent 7f8957eb9a
commit 520407925a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,8 @@ const { RangePicker } = DatePicker;
const App = () => {
const [dates, setDates] = useState([]);
const [hackValue, setHackValue] = useState();
const [value, setValue] = useState();
const disabledDate = current => {
if (!dates || dates.length === 0) {
return false;
@ -30,14 +32,22 @@ const App = () => {
return tooEarly || tooLate;
};
const onOpenChange = open => {
if (open) {
setHackValue([]);
setDates([]);
} else {
setHackValue(undefined);
}
};
return (
<RangePicker
value={hackValue || value}
disabledDate={disabledDate}
onCalendarChange={value => {
const [start, end] = value;
const [oldStart, oldEnd] = dates;
setDates([start || oldStart, end || oldEnd]);
}}
onCalendarChange={val => setDates(val)}
onChange={val => setValue(val)}
onOpenChange={onOpenChange}
/>
);
};