Skip to content
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

Custom Info Panel position #989

Merged
merged 12 commits into from
Feb 13, 2018
Merged

Custom Info Panel position #989

merged 12 commits into from
Feb 13, 2018

Conversation

mariepw
Copy link
Contributor

@mariepw mariepw commented Jan 30, 2018

Hi @majapw, Hi @ljharb, Hi all,
I implemented the changes proposed in #840 by adding prop 'calendarInfoPosition' to 'SingleDatePicker' and 'DateRangePicker'.
I also directly updated the stories, to test thoses changes.
Thanks.

@coveralls
Copy link

coveralls commented Jan 30, 2018

Coverage Status

Coverage decreased (-0.3%) to 86.513% when pulling ce7c1c0 on mariepw:master into 7dfe618 on airbnb:master.

ref={this.setCalendarInfoRef}
{...css((calendarInfoIsInline) && styles.DayPicker_calendarInfo__horizontal)}
>
{ renderCalendarInfo() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: jsx curly braces shouldn't have padding spaces inside them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

};

const dayPickerStyle = {
width: this.isHorizontal() && fullHorizontalWidth,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we cache the isHorizontal result in a var, so we don't have to call the function multiple times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.. but the function is called at other different places in the code... Will it be better to cache the result in a state?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, that would cause a rerender. It's fine to call multiple times conceptually, but it's nice to minimize duplicate function calls within the body of a single function :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it is okay like that ?


// These values are to center the datepicker (approximately) on the page
marginLeft: this.isHorizontal() && withPortal && -fullHorizontalWidth / 2,
marginTop: this.isHorizontal() && withPortal && -calendarMonthWidth / 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than overloading && for value selection, can these use explicit ternaries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it, but for the record, the implicit ternaries were already here before, I only change their position in the code..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough :-) thanks for leaving it cleaner than you found it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My pleasure ! :)

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mariepw, the code for this looks good and I checked out the branch as well.

Two comments:

  1. Can we default the info position to the bottom so as not to break this for current consumers?
  2. The height animation seems broken when the info panel is on the left or on the right:
    drp_broken_animation

Can you investigate a bit?

@mariepw
Copy link
Contributor Author

mariepw commented Feb 1, 2018

Hi @majapw ,

1 - Totally right, sorry for the "glitch", I changed the default info position.
2 - Still under investigation, but my idea is that it is because of the change of display on wrapper and infoPanel when they are inline... And to be honest, not sure how to change this...

@mariepw
Copy link
Contributor Author

mariepw commented Feb 2, 2018

I just found out where the issue is coming from... It is due to the use of calculateDimension.. Will find a way to fix this..

@mariepw
Copy link
Contributor Author

mariepw commented Feb 6, 2018

I'm still stuck with this problem...

When I change :
const calendarInfoWith = renderCalendarInfo && calendarInfoIsInline ? calculateDimension(this.calendarInfo, 'width', true, true) : 0;
to :
const calendarInfoWith = renderCalendarInfo && calendarInfoIsInline ? 300 // hardcoded random value : 0;
transition works well, and calendar info panel will always have the same width.. But I cannot just hardcode a value like this...

  • I tried to get the width when componentDidMount and add it to a state, transition then works, but the width is not set properly... (render is called several times after componentDidMount).

  • Then I tried :
    - to recalculate the width in componentWillUpdate, and set the state again...
    - change the display of DayPicker_calendarInfo__horizontal and DayPicker_wrapper__horizontal from table-cell to inline-block
    - add 1px to fullHorizontalWidth (to compensate white-space between the two inline-block)
    This solution fix the problem of width for calendar info panel, but the transition is still buggy..

  • I even tried to use this.calendarInfo.getBoundingClientRect().width instead of calculateDimension(this.calendarInfo, 'width', true, true).. But it didn't change nothing..

So... Do you have any idea @majapw @ljharb ?
Thanks a lot!

@mariepw
Copy link
Contributor Author

mariepw commented Feb 8, 2018

I finally fixed the issue..
Calculating the dimensions of calendar info panel, was creating a DOM repaint, this is what was breaking the CSS transition.. Adding a setTimeout to delay calculation, to wait until transition ends, fixed it.
Everything works now, calendar info panel renders itself with expected width, and transition works.
Let me know if it is ok.

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thank you so much. I have two small comments and then I think we're good to go.

Thank you so much for debugging and putting in the work @mariepw! :)

calendarInfoWidth: calendarInfoPanelWidth,
});
}
}, 200);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use transitionDuration here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense :) I didn't see the props...

// The setTimeout will wait until the transition ends.
if (this.calendarInfo) {
const { calendarInfoWidth } = this.state;
this.timeout = setTimeout(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this this.setCalendarInfoWidthTimeout or something else meaningful

@mariepw
Copy link
Contributor Author

mariepw commented Feb 9, 2018

Thanks a lot @majapw !!! Last changes are done now :)
I cannot take all the credits and have to say thanks to @onigoetz, because he gave me the lead about the DOM repaint...
Anyway, yay it's done! Thanks :)

@mariepw
Copy link
Contributor Author

mariepw commented Feb 13, 2018

Hi @majapw do you know when it will be possible to merge ?

@majapw
Copy link
Collaborator

majapw commented Feb 13, 2018

Sorry @mariepw, it slipped off my radar! :) Let me do a release today.

@majapw majapw merged commit cec101b into react-dates:master Feb 13, 2018
@mariepw
Copy link
Contributor Author

mariepw commented Feb 13, 2018

Yeeaah for the release, perfect !! Thanks a lot @majapw !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants