-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Independent Daterangepicker months #575
Conversation
Feels pretty good. Nice to show the bounds of > 2 months ranges on each calendar through the shortcuts 👍 Worth asking: should we disallow "go next" in left calendar / "go prev" in right calendar when the 2 months are contiguous? |
@llorca I guess it depends how valuable the interaction of shuffling both months together might be; that's the capability that would go away if we hide the buttons when the months are contiguous. I don't have a good sense for that at this point. EDIT: But there is definitely some awkwardness/non-clarity there at this point. I could easily see this confusing some users as is. |
@thisisalessandro would love to get your design input |
re- @thisisalessandro 's points
|
I'm not opposed to having |
@llorca @leebyp @thisisalessandro - just touched on outside days in my first PR on the road to merging my |
This is cool, we want it. Can we have it as a simple prop/option on the date range picker? |
* Create new class for DateRangePicker state internals
#678) * Add tests * set indepedent months feature through prop * update docs * update example in docs
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'm going with "Request changes" instead of "Comment" for the first time. Left some questions and corrections. LMK when you're ready for review, @leebyp.
@@ -55,11 +55,26 @@ Styleguide components.datetime.daterangepicker.js | |||
.pt-daterangepicker { | |||
white-space: nowrap; | |||
|
|||
&.pt-daterangepicker-sequential { | |||
.DayPicker { | |||
min-width: $pt-grid-size * 43; |
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.
43
looks so arbitrary, haha. What's the width of each content column here? Can we make variables for (1) the width of each calendar and (2) the width of the shortcuts list, then add them in place here?
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.
Extracted out the width for DayPicker since it's used to calculate the other widths. And made the css a bit more verbose to show what's going on. I haven't moved the shortcuts out, since it is arbitrary.
|
||
~ .DayPicker { | ||
border-left: 1px solid $pt-divider-black; | ||
min-width: $pt-grid-size * 44; |
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.
Why are the min-widths different?
@@ -18,6 +18,7 @@ export const DATEPICKER_MONTH_SELECT = "pt-datepicker-month-select"; | |||
export const DATEPICKER_YEAR_SELECT = "pt-datepicker-year-select"; | |||
|
|||
export const DATERANGEPICKER = "pt-daterangepicker"; | |||
export const DATERANGEPICKER_SEQUENTIAL = "pt-daterangepicker-sequential"; |
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 class still abides by the old isSequential
naming scheme. Can we change to pt-daterangepicker-contiguous
or something?
|
||
export function getDatePreviousMonth(date: Date): Date { | ||
const monthIsJanuary = date.getMonth() === Months.JANUARY; | ||
if (monthIsJanuary) { |
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.
nit: IMO the equality expression above is clear enough without this extra variable.
} | ||
|
||
// returns -ve if left < right | ||
// returns +ve if left > right |
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.
nit: the ...ve
suffix took a sec for me to interpret. I guess I'm not mathy enough. Mild preference for negative
and positive
.
renderDateRangePicker({ contiguousCalendarMonths, maxDate, minDate }); | ||
assert.lengthOf(document.getElementsByClassName("DayPicker"), 1); | ||
assert.lengthOf(document.getElementsByClassName(".DayPicker-NavButton--prev"), 0); | ||
assert.lengthOf(document.getElementsByClassName(".DayPicker-NavButton--next"), 0); |
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.
We don't want the dots in the class name when using document.getElementsByClassName
. Won't return anything.
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.
haha oops...
}); | ||
|
||
it("is a day between minDate and maxDate if only maxDate/minDate set and today is not in range", () => { | ||
const maxDate = new Date(2005, Months.JANUARY); | ||
const minDate = new Date(2000, Months.JANUARY); | ||
renderDateRangePicker({ maxDate, minDate }); | ||
const { displayMonth, displayYear } = dateRangePicker.state; | ||
assert.isTrue(DateUtils.isDayInRange(new Date(displayYear, displayMonth), [minDate, maxDate])); | ||
const leftDisplayMonth = dateRangePicker.state.leftView; |
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.
nit: Pondering to myself it const leftView = ...
would be clearer to me than const leftDisplayMonth = ...
, since the display month includes a year. Thoughts @leebyp?
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.
Ah yes thanks, this was leftover from refactors - updated a couple of other places i missed too.
@cmslewis should be easier to read now |
@leebyp love the "Show shortcuts" toggle and the CSS variables! The Otherwise, looks good IMO. |
Shouldn't it be "Constrain" instead of "Contrain"? |
Fixes #432
Fix existing tests
Add new tests
Update documentation
DateRangePicker months set to be contiguous through prop
Extracted date comparison logic into separate class for readability