I'm using the react-date-range component and want to add some of my own custom inputRanges on the left side of the interface. At the moment it has, yesterday, last week, last month etc. I want to add "this year", "last year", "12 months previous"
I'm able to remove the preset ranges by using
inputRanges={[]}
But I'm struggling to determine how to add my own ranges. I see the shape of the range object is:
{
startDate: PropTypes.object,
endDate: PropTypes.object,
color: PropTypes.string,
key: PropTypes.string,
autoFocus: PropTypes.bool,
disabled: PropTypes.bool,
showDateDisplay: PropTypes.bool,
}
but populating the object and passing it into inputRanges as an array element doesn't work either:
inputRanges={[{
startDate: new Date(),
endDate: new Date(),
color: "#eecc99",
key: "Today",
autoFocus: false,
disabled: false,
showDateDisplay: true,
}]}
I'm reading the documentation here but it's not helping much: https://www.npmjs.com/package/react-date-range
You need to pass
staticRangesprop to theDateRangePickercomponent. Additionally, if you want to include the default ranges of the library, you can pass...defaultStaticRanges, as the first argument of the array. You can take a look at this sandbox for live working example.