Added support for displaying (only) the year picker #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #55
The first commit adds a prop "showYearPicker" to the Datepicker which is just passed to the Calendar component, which just sets
const [showYears, setShowYears] = useState(showYearPicker);
. When a year is selected, the clickYear callback just sets the startDate and endDate to the first of January of the selected year.The second commit adds a prop "yearPickerStartYearOffset" which offsets the years displayed in the year picker. For example if year is 2023 and
yearPickerStartYearOffset = -10
the year picker now displays the years 2013-2024 instead of the default 2023-2034.The third commit adds support for selecting a start- and end-year by moving the functionality which was in the "clickDay" callback to a separate helper function, and calls that helper function from the "clickYear" callback.
To use this, you just need to pass a couple of props to the Datepicker.
This selects a range of years (a start year and an end year):
This selects one single year: