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

[vertical scrollable] add spacing and scrollbar theme #1298

Merged
merged 2 commits into from
Aug 10, 2018

Conversation

amhunt
Copy link
Contributor

@amhunt amhunt commented Aug 4, 2018

This adds three new theme variables, primarily aimed at the vertical scrollable configuration.

  1. Adds the option to remove the scrollbar from the vertical scrollable orientation. The scroll bar looks bad on the lux calendar and also pushes things over so that elements are no longer aligned.
  2. Adds a horizontal spacing prop for months (i.e. the padding around each individual month)
  3. Adds a horizontal spacing prop for the daypicker container (padding around all of the months).

I also rewrote the getCalendarMonthWidth function because it was using the wrong value (9 instead of 13 in the default case).

@majapw @ljharb

@coveralls
Copy link

coveralls commented Aug 4, 2018

Coverage Status

Coverage remained the same at 84.82% when pulling 0ec2d72 on amh-add-theme-options into ffe96d9 on master.

@@ -260,6 +260,7 @@ class CalendarMonthGrid extends React.Component {
isFocused,
isRTL,
styles,
theme,
Copy link
Member

Choose a reason for hiding this comment

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

theme: { reactDates: theme }?

export default withStyles(({ reactDates: { color, zIndex } }) => ({
export default withStyles(({
reactDates: {
color, noScrollBarOnVerticalScrollable, spacing, zIndex,
Copy link
Member

Choose a reason for hiding this comment

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

each of these needs to be on its own line, if the entire object literal can't fit on one line

@amhunt amhunt force-pushed the amh-add-theme-options branch 2 times, most recently from 64ac9b1 to 2242529 Compare August 6, 2018 21:31
@majapw
Copy link
Collaborator

majapw commented Aug 7, 2018

Taking a look now!

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 looks phenom @amhunt!

So I think that the calendarmonth padding should be a prop---but I think I'm making an assumption that it works a certain way when I say that. If you were to set that value to 0 what would it look like? What is the interplay between the month padding and picker padding?

export default withStyles(({
reactDates: {
color,
noScrollBarOnVerticalScrollable,
Copy link
Collaborator

Choose a reason for hiding this comment

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

QQ: can you investigate as to whether the scrollbar is an issue on the VERTICAL_ORIENTATION as well? It may make sense to have noScrollBarOnVertical be the option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't/if there were an issue, it could be managed outside of the vertical calendar (because the largest div for the vertical calendar is the outermost div, whereas the smaller surrounding div in VERTICAL_SCROLLABLE is the one that's causing the scrollbar to appear).

const calendarMonthWidth = getCalendarMonthWidth(daySize);
const calendarMonthWidth = getCalendarMonthWidth(
daySize,
theme.spacing.calendarMonthHorizontalPadding,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the reason why calendarMonthHorizontalPadding seems like it could be a prop instead of a theme variable. I get that it's only related to CSS---but because it also influences the animations and open source consumers have asked for this as well, I would maybe make this one a prop. We could call it horizontalMonthPadding to align with verticalSpacing and verticalHeight props.

@@ -376,7 +387,7 @@ export default withStyles(({ reactDates: { color, zIndex } }) => ({

CalendarMonthGrid__horizontal: {
position: 'absolute',
left: 9,
left: spacing.dayPickerHorizontalPadding,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this makes sense in the theme.

@@ -956,7 +962,8 @@ class DayPicker extends React.Component {
: 0;

const firstVisibleMonthIndex = this.getFirstVisibleIndex();
const wrapperHorizontalWidth = (calendarMonthWidth * numberOfMonths) + (2 * DAY_PICKER_PADDING);
const wrapperHorizontalWidth = (calendarMonthWidth * numberOfMonths)
+ (2 * dayPickerHorizontalPadding);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do we use this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the width of the calendar for horizontal orientation. So if the outside padding of the dayPicker is 9 and the calendarMonth padding is 13, then the width of the horizontal calendar would be: 2*9 + 2*((2*13) + width_of_calendar_without_padding). Does that answer your question?


export default withStyles(({
reactDates: {
color, font, noScrollBarOnVerticalScrollable, spacing, zIndex,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I'd prefer these to be on their own lines (for ease of rebasing in the future)

Copy link
Member

Choose a reason for hiding this comment

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

+1, see #1298 (comment)

export default function getCalendarMonthWidth(daySize) {
return (7 * (daySize + 1)) + (2 * (CALENDAR_MONTH_PADDING + 1));
export default function getCalendarMonthWidth(daySize, calendarMonthPadding) {
return (7 * daySize) + (2 * calendarMonthPadding) + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes way more sense :P

@amhunt
Copy link
Contributor Author

amhunt commented Aug 8, 2018

@majapw updated :) I made the horizontalMonthPadding a prop. I also removed three styles that didn't have corresponding style objects in CalendarMonth... idk why they were there.

My one remaining question - how should I handle the default case? I just set it as default 13 at all levels - or should it be default 13 at the top level and then a required prop below?

@@ -386,6 +400,13 @@ export default withStyles(({ reactDates: { color, zIndex } }) => ({
CalendarMonthGrid__vertical_scrollable: {
margin: '0 auto',
overflowY: 'scroll',
...noScrollBarOnVerticalScrollable && {
Copy link
Member

Choose a reason for hiding this comment

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

could we add parens here to make it clear that the entire thing is spread, not just the first conditional?

@@ -260,7 +264,8 @@ class DayPicker extends React.Component {

if (nextProps.daySize !== daySize) {
this.setState({
calendarMonthWidth: getCalendarMonthWidth(nextProps.daySize),
calendarMonthWidth:
getCalendarMonthWidth(nextProps.daySize, horizontalMonthPadding),
Copy link
Member

Choose a reason for hiding this comment

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

this should be instead formatted like this:

calendarMonthWidth: getCalendarMonthWidth(
  nextProps.daySize,
  horizontalMonthPadding,
),

@@ -1210,5 +1231,12 @@ export default withStyles(({ reactDates: { color, font, zIndex } }) => ({
right: 0,
left: 0,
overflowY: 'scroll',
...noScrollBarOnVerticalScrollable && {
Copy link
Member

Choose a reason for hiding this comment

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

also parens here?

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.

Love it! :) Thank you so much @amhunt for being patient!

@@ -187,9 +189,7 @@ class CalendarMonth extends React.Component {
<div
{...css(
styles.CalendarMonth,
orientation === HORIZONTAL_ORIENTATION && styles.CalendarMonth__horizontal,
orientation === VERTICAL_ORIENTATION && styles.CalendarMonth__vertical,
verticalScrollable && styles.CalendarMonth__verticalScrollable,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @amhunt Did these get intentionally removed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see below that they don't actually exist :x

@majapw majapw merged commit dcb346e into master Aug 10, 2018
@majapw majapw deleted the amh-add-theme-options branch August 10, 2018 16:53
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