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

Choose minutes #119

Merged
merged 1 commit into from
Feb 5, 2017
Merged

Choose minutes #119

merged 1 commit into from
Feb 5, 2017

Conversation

CasperLaiTW
Copy link
Contributor

choose-minutes

Copy link
Member

@joews joews left a comment

Choose a reason for hiding this comment

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

This patch looks great, thanks! I have a few comments about code consistency, but nothing big to change 👍

lib/js/index.js Outdated
@@ -126,12 +126,21 @@ class DateTimePicker extends Events {
this.$('.js-ok')
.addEventListener('click', () => this.clickSubmit(), false);

this.$('.c-datepicker__header-date__hours').addEventListener('click', e => this.showHourClock(e), false);
Copy link
Member

Choose a reason for hiding this comment

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

Please use .js-date-hours here - BEM classnames are for style, js- classes are for JavaScript. I know we don't totally adhere to this yet, but that's the aim 😄

The idea comes from this article by Harry Roberts, btw - it's a good read!

lib/js/index.js Outdated
@@ -126,12 +126,21 @@ class DateTimePicker extends Events {
this.$('.js-ok')
.addEventListener('click', () => this.clickSubmit(), false);

this.$('.c-datepicker__header-date__hours').addEventListener('click', e => this.showHourClock(e), false);
this.$('.c-datepicker__header-date__minutes').addEventListener('click', e => this.showMinuteClock(e), false);
Copy link
Member

Choose a reason for hiding this comment

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

.js-date-minutes, please

lib/js/index.js Outdated
this.$('.c-datepicker__clock__hours').addEventListener('mouseleave', e => this.mouseOutClock(e), false);
this.$(`.${this.options.styles.clockNum}`).forEach((el) => {
this.$(`.c-datepicker__clock__hours .${this.options.styles.clockNum}`).forEach((el) => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a .js- class for this the hours element?

lib/js/index.js Outdated
el.addEventListener('click', e => this.clickClock(e), false);
el.addEventListener('mouseenter', e => this.mouseInClock(e), false);
});

this.$('.c-datepicker__clock__minutes').addEventListener('mouseleave', e => this.mouseOutClock(e), false);
Copy link
Member

Choose a reason for hiding this comment

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

.js- class please. I'll stop making this comment now, but it should apply to each new className referenced in JavaScript.

I'm going to do the same to any pre-existing non js- classes soon.

lib/js/index.js Outdated
@@ -171,6 +180,13 @@ class DateTimePicker extends Events {
return this;
}

clickClockMinutes(e) {
Copy link
Member

Choose a reason for hiding this comment

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

(Github won't let me add a comment to the right line) - do you need to change clickClock to clickClickHour?

I changed clickClock recently to call this.set (to fix #110) - can you update this method to follow the same pattern?

lib/js/index.js Outdated
@@ -216,6 +240,20 @@ class DateTimePicker extends Events {
return this;
}

showHourClock() {
this.$('.c-datepicker__clock__hours').style.display = 'block';
Copy link
Member

Choose a reason for hiding this comment

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

It seems inconsistent to use style.display for one part of the UI and a className for the other. Could you use an active class for both?

@joews
Copy link
Member

joews commented Feb 3, 2017

This is awesome, thank you! One usability comment - the hour and minute have cursor: pointer when the calendar is active. They are not clickable in this state.

Two possible fixes:

  • Only use cursor: pointer when clock is active
  • When the calendar is active, clicking hours/minutes opens the clock

The second option would be cool, but maybe it's one for another PR. If we do this we should also allow clicking on the date to open the calendar.

What do you think?

@joews joews mentioned this pull request Feb 3, 2017
@CasperLaiTW
Copy link
Contributor Author

I fix requested changes :)

About click to open clock, I make first option for this PR.

And I think I can keep working for second option include clicking on the date to open the calendar

Copy link
Member

@joews joews left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! I found a few more consistency issues that I missed last time, and a bug that occurs when a default time is set. Once those are fixed I'll merge 👍

lib/js/index.js Outdated

this.$('.js-clock-hours').addEventListener('mouseleave', e => this.mouseOutClock(e), false);
this.$(`.js-clock-hours .${this.options.styles.clockNum}`).forEach((el) => {
el.addEventListener('click', e => this.clickClickHour(e), false);
el.addEventListener('mouseenter', e => this.mouseInClock(e), false);
Copy link
Member

Choose a reason for hiding this comment

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

I missed this before - can you change to mouseInClockHour ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean mouseInClock change to mouseInHourClock ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that seems a better name. Thanks!

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 make changes, can you check it?

lib/js/index.js Outdated
active.classList.add('hide-hand');
}
}

mouseOutClock() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this mouseOutHourClock ?

lib/js/index.js Outdated
this.$(`.c-datepicker__clock__hours .${this.options.styles.clockNum}[data-number="${hourAsInt}"]`)
.classList.add(`${this.options.styles.clockNum}--active`);
this.$(`.c-datepicker__clock__minutes .${this.options.styles.clockNum}[data-number="${minuteAsInt}"]`)
Copy link
Member

Choose a reason for hiding this comment

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

I found a bug in testing - if the minutes from the datepicker's default time are not on the clock faces, this throws:

index.js:353 Uncaught TypeError: Cannot read property 'classList' of undefined
    at DateTimePicker.setTime (index.js:353)
    at DateTimePicker.open (index.js:92)
    at HTMLAnchorElement.<anonymous>

You can test this by adding default: moment() to the Datepicker options. If the current minutes is not a multiple of 5, you'll hit this error.

lib/js/index.js Outdated
@@ -188,8 +206,16 @@ class DateTimePicker extends Events {
}
}

mouseInMinuteClock() {
const active = this.$(`.c-datepicker__clock__minutes .${this.options.styles.clockNum}--active`);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use .js-clock-minutes instead of .c-datepicker__clock__minutes

lib/js/index.js Outdated
@@ -216,6 +242,20 @@ class DateTimePicker extends Events {
return this;
}

showHourClock() {
this.$('.c-datepicker__clock__hours').classList.add('active');
Copy link
Member

Choose a reason for hiding this comment

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

.js-clock-hours

lib/js/index.js Outdated
showHourClock() {
this.$('.c-datepicker__clock__hours').classList.add('active');
this.$('.c-datepicker__clock__minutes').classList.remove('active');
this.$('.c-datepicker__header-date__hours').classList.add('active');
Copy link
Member

Choose a reason for hiding this comment

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

.js-date-hours

lib/js/index.js Outdated
this.$('.c-datepicker__clock__hours').classList.add('active');
this.$('.c-datepicker__clock__minutes').classList.remove('active');
this.$('.c-datepicker__header-date__hours').classList.add('active');
this.$('.c-datepicker__header-date__minutes').classList.remove('active');
Copy link
Member

Choose a reason for hiding this comment

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

.js-date-minutes

lib/js/index.js Outdated
}

showMinuteClock() {
this.$('.c-datepicker__clock__hours').classList.remove('active');
Copy link
Member

Choose a reason for hiding this comment

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

The same className changes as above, please

lib/js/index.js Outdated
const hourAsInt = parseInt(hour, 10) % 12;
const minuteAsInt = parseInt(minutes, 10);
const oldActiveHours = this.$(`.c-datepicker__clock__hours .${this.options.styles.clockNum}--active`);
Copy link
Member

Choose a reason for hiding this comment

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

.js-clock-hours, please - this one was here already but this seems like a good time to improve the code quality while making similar changes 😄

lib/js/index.js Outdated
const oldActiveHours = this.$(`.c-datepicker__clock__hours .${this.options.styles.clockNum}--active`);
const oldActiveMinutes = this.$(`.c-datepicker__clock__minutes .${this.options.styles.clockNum}--active`);
Copy link
Member

Choose a reason for hiding this comment

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

.js-clock-minutes

@CasperLaiTW
Copy link
Contributor Author

I make changes
About bug I make it will go next multiple of 5

Copy link
Member

@joews joews left a comment

Choose a reason for hiding this comment

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

LGTM! thanks for your patience with the reviews 😄

@joews joews merged commit 011b0b4 into ripjar:master Feb 5, 2017
@joews joews mentioned this pull request Feb 5, 2017
@joews
Copy link
Member

joews commented Feb 5, 2017

Thanks for the contribution, this is such an important feature! Released as v2.1.0.

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.

2 participants