Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit af0ed86

Browse files
authored
Merge pull request #487 from hypeserver/add-date-disabling-to-demo
Add date disabling to demo
2 parents 9989400 + 729ce96 commit af0ed86

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/components/DateRange/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class DateRange extends Component {
102102
}
103103
const { rangeColors, ranges } = this.props;
104104
const focusedRange = this.props.focusedRange || this.state.focusedRange;
105-
const color = ranges[focusedRange[0]].color || rangeColors[focusedRange[0]] || color;
105+
const color = ranges[focusedRange[0]]?.color || rangeColors[focusedRange[0]] || color;
106106
this.setState({ preview: { ...val.range, color } });
107107
};
108108
render() {

src/components/DateRangePicker/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,34 @@ function customDayContent(day) {
189189
}}
190190
/>;
191191
```
192+
193+
194+
#### Example: Restrict Date Selection
195+
Restricts access for range selection to (-30, +30) days of current date.
196+
```jsx inside Markdown
197+
import { addDays } from 'date-fns';
198+
import { useState } from 'react';
199+
200+
const [state, setState] = useState({
201+
selection: {
202+
startDate: new Date(),
203+
endDate: null,
204+
key: 'selection'
205+
},
206+
compare: {
207+
startDate: new Date(),
208+
endDate: addDays(new Date(), 3),
209+
key: 'compare'
210+
}
211+
});
212+
213+
<DateRangePicker
214+
onChange={item => setState({ ...state, ...item })}
215+
months={1}
216+
minDate={addDays(new Date(), -30)}
217+
maxDate={addDays(new Date(), 30)}
218+
direction="vertical"
219+
scroll={{ enabled: true }}
220+
ranges={[state.selection, state.compare]}
221+
/>;
222+
```

0 commit comments

Comments
 (0)