New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a render function for customizable week header text #1787
Conversation
src/components/DayPicker.jsx
Outdated
@@ -88,6 +88,7 @@ const propTypes = forbidExtraProps({ | |||
// month props | |||
renderMonthText: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), | |||
renderMonthElement: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), | |||
renderWeekHeaderText: PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your suggestion of renderWeekHeaderElement
, since an element would be a valid return value.
src/components/DayPicker.jsx
Outdated
@@ -149,6 +150,7 @@ export const defaultProps = { | |||
// month props | |||
renderMonthText: null, | |||
renderMonthElement: null, | |||
renderWeekHeaderText: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is better or worse, but did you consider making the default for this:
renderWeekHeaderText: day => <small>{day}</small>
?
That would collapse the number of conditionals from 2 (the ternary in the render prop and the default prop) to 1 (just the default prop).
But maybe it would be harder to see what the default is when scanning the component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh I like that idea! though I tend to see this pattern more where the function prop is optional and then some functionality is used in its place, rather than assigning that functionality as the default to the function prop—so I'm inclined to keep this as-is for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, and LGTM 🤘
1a3547e
to
9bea561
Compare
9bea561
to
21ec280
Compare
Summary
Add a function
renderWeekHeaderText
(wouldrenderWeekHeaderElemement
be more appropriate?) that allows the week header text for a calendar month to be customized.Screenshots
Default
With custom week header text