-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 renderCalendarDay
prop
#894
Conversation
9b0a9cc
to
2bb653d
Compare
@@ -23,7 +23,7 @@ const propTypes = forbidExtraProps({ | |||
onDayClick: PropTypes.func, | |||
onDayMouseEnter: PropTypes.func, | |||
onDayMouseLeave: PropTypes.func, | |||
renderDay: PropTypes.func, | |||
renderDayContents: 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.
hm - i'm not sure this prop actually has to change. Is the name that much clearer that it's worth the breaking change now?
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.
This change is already breaking because I've taken the opportunity to restructure the CalendarDay
component. I think with the presence of a renderCalendarDay
prop, renderDay
is confusing and we should take this opportunity to clarify what that prop actually does.
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.
master might already be breaking, but this PR doesn't have to be, and wouldn't be without this prop being renamed.
The naming confusion is a fair point, but CalendarDay
doesn't take a renderCalendarDay
prop - the prop names don't need to be the same across all our components.
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.
Sorry I think in my late night Friday shuffling around, I lost a change in this component that will most definitely making this PR breaking. I don't think master is breaking right now.
I maintain that renderDayContents
is a much more meaningful prop name (in this component and in others) and is not going to be the only breaking change in this PR.
src/components/DateRangePicker.jsx
Outdated
@@ -282,15 +283,15 @@ class DateRangePicker extends React.Component { | |||
if (withPortal || withFullScreenPortal) { | |||
return ( | |||
<Portal> | |||
{this.renderDayPicker()} | |||
{this.renderDayContentsPicker()} |
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.
isn't this still rendering a day picker?
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.
Whoops! D: find and replace :X
src/components/SingleDatePicker.jsx
Outdated
} | ||
|
||
renderDayPicker() { | ||
renderDayContentsPicker() { |
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.
same here?
2bb653d
to
829690c
Compare
@ljharb take another look pls? |
829690c
to
d810291
Compare
In the styles i want to define for the
|
Here are the breaking changes in this PR:
renderDay
is now namedrenderDayContents
CalendarDay
no longer consists of a button inside of a td. It is instead a td with a buttonrole
. The related styles have been simplified accordingly. FYI @backwardokHere is what's new:
renderCalendarDay
, a prop that takes a props arg and expects either aCalendarDay
orCustomizableCalendarDay
node with those props spread onto it to be returned. More details below.===
This is for one-off, no-good, hacky customization of
CalendarDay
styling within the frame of the react-with-styles ecosystem. This PR isn't quite done, but it is close.SO IN AN IDEAL WORLD, you only modify
CalendarDay
styles on an app-wide level, whichreact-with-styles
themes allow you to do easily. After all, why would you have multiple datepickers that all look dramatically different on your site (especially with their color scheme). But sometimes, ya gotta do what ya gotta do. To solve this, we have a new beautifulrenderCalendarDay
prop.The
renderCalendarDay
prop takes in an object (specifically, with the following keys---key
,dayOfWeek
,day
,daySize
,isOutsideDay
,tabIndex
,isFocused
,onDayMouseEnter
,onDayMouseLeave
,onDayClick
,renderDayContents
,phrases
,modifiers
,ariaLabelFormat
) as an argument. What it expects as a return is an instance of eitherCalendarDay
(the default) orCustomizableCalendarDay
. The reason the arg doesn't really matter is because you are kind of expected just to spread it onto theCalendarDay
instance to get a fully functional datepicker.The default
renderCalendarDay
prop looks as follow:The
CalendarDay
is fairly restricted so you can't really do much more than that (as an aside, you could probably use this to hack into the day interaction methods from the DRP or SDP or the controllers). However, let's say you are trying to implement the following design:#PantoneUltraViolet
More importantly, let's say you are trying to implement the above design on one page of your app, AND EVERY OTHER PAGE HAS THE STANDARD TEAL. Well, if you're using
react-with-styles-interface-aphrodite
you might think you're kind of fucked. Aphrodite does not allow for arbitrary CSS overrides, and we have not before had any APIs that would allow for this. Now, you would just leverage therenderCalendarDay
prop and theCustomizableCalendarDay
component like so:And voila, you have a one-off, random ultraviolet datepicker in your app.
@ljharb Taylor Swift's "Look what you made me do" is now stuck in my head because that is how I feel about this PR and the unfortunate circumstances that have led to its necessity.
@airbnb/webinfra @amhunt if you feel like taking a gander at what I expect the customization API to look like