-
Notifications
You must be signed in to change notification settings - Fork 82
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
Choose minutes #119
Conversation
CasperLaiTW
commented
Feb 3, 2017
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 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); |
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.
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); |
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.
.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) => { |
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.
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); |
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.
.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) { |
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.
(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'; |
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.
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?
This is awesome, thank you! One usability comment - the hour and minute have Two possible fixes:
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? |
264423a
to
66929a5
Compare
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 |
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.
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); |
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.
I missed this before - can you change to mouseInClockHour
?
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.
do you mean mouseInClock
change to mouseInHourClock
?
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.
Yes, that seems a better name. Thanks!
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.
I make changes, can you check it?
lib/js/index.js
Outdated
active.classList.add('hide-hand'); | ||
} | ||
} | ||
|
||
mouseOutClock() { |
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.
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}"]`) |
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.
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`); |
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.
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'); |
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.
.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'); |
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.
.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'); |
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.
.js-date-minutes
lib/js/index.js
Outdated
} | ||
|
||
showMinuteClock() { | ||
this.$('.c-datepicker__clock__hours').classList.remove('active'); |
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.
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`); |
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.
.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`); |
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.
.js-clock-minutes
66929a5
to
db042f0
Compare
I make changes |
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.
LGTM! thanks for your patience with the reviews 😄
Thanks for the contribution, this is such an important feature! Released as v2.1.0. |