-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
New props, functionalities and behaviour #18
base: master
Are you sure you want to change the base?
New props, functionalities and behaviour #18
Conversation
src/TimePicker.spec.js
Outdated
@@ -78,7 +78,6 @@ describe('<TimePicker />', () => { | |||
.simulate('click', testUtils.stubClickEvent(190, 230)) // click on 25 | |||
.simulate('mouseup', testUtils.stubClickEvent(190, 230)) // click on 25 | |||
|
|||
expect(changeHandler).toBeCalled() |
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.
Removed by mistake, amended in the next commit
src/TimePicker.spec.js
Outdated
@@ -260,7 +259,6 @@ describe('<TimePicker />', () => { | |||
.simulate('click', testUtils.stubClickEvent(190, 230)) // click on 25 | |||
.simulate('mouseup', testUtils.stubClickEvent(190, 230)) // click on 25 | |||
|
|||
expect(changeHandler).toBeCalled() |
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.
Removed by mistake, amended in the next commit
@@ -141,7 +141,6 @@ describe('<TimeInput />', () => { | |||
tree.find(Button).at(0).simulate('click') | |||
|
|||
expect(getValue(tree)).toBe('13:37') // unchanged | |||
expect(changeHandler).not.toHaveBeenCalled() |
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.
Now is called in every date change and restored when canceled
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? There is no reason to call the change handler when the date isn't changed.
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 did that change because I needed the time text field (and some other components) to be updated when the user changes the hour in real time, so every time the user moves the clock hands, changeHandler
is called.
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 see, that's a good point. 🤔 We should make that optional and turn it off by default. Maybe call that prop updateImmediately
?
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.
In fact, I think that's the best option, thus maintaining the same behavior (avoiding some developers from going crazy when updating 🙃) and providing that functionality, which in my case is very useful
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.
That was my intention. 👍 Adding your use case while keeping this a minor update (i.e. no breaking changes).
@Serg4554 I'm sorry I didn't see this earlier! This is an awesome first contribution, thank you so much! 🎉 I'd rename |
Thanks to you for this awesome component! |
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 again for this great PR! ❤️ Some nit-picky things (don't worry about them too much 😉).
I don't like the idea of calling onChange even if there are no changes. Is there an actual use case where this behavior is needed? 🤔
Regarding test coverage: While I aim at 💯 %, the -1,2% is fine. 👍
src/TimePicker.js
Outdated
this.setState({ minutes: value }, () => { | ||
this.propagateChange() | ||
}) | ||
} else if (value % (this.props.minutesStep || 1) === 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.
The default step should better be set in the default props.
src/TimePicker.js
Outdated
@@ -186,6 +184,7 @@ class TimePicker extends React.Component { | |||
value={clockMode === 'minutes' ? minutes : hours} | |||
onMouseUp={this.handleClockChangeDone} | |||
onTouchEnd={this.handleClockChangeDone} | |||
minutesStep={this.props.minutesStep || 1} |
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.
See above.
src/Clock.js
Outdated
className={classNames( | ||
classes.number, | ||
{ selected: value === digit.display || (digit.display === 60 && value === 0) }, | ||
{ disabled: digit.display % (this.props.minutesStep || 1) })} |
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.
These two objects can be merged.
src/Clock.js
Outdated
value: PropTypes.number.isRequired | ||
value: PropTypes.number.isRequired, | ||
/** Steps between minutes. */ | ||
minutesStep: PropTypes.number |
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 propTypes were sorted alphabetically before. 😉
src/TimeInput.js
Outdated
@@ -80,19 +89,21 @@ class TimeInput extends React.Component { | |||
value={formattedValue} | |||
readOnly | |||
key='TimeInput-input' | |||
classes={inputClasses || {}} |
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.
No reason to set this to an empty object. Also, instead of introducing a new prop, this could as well be classes.input
(just add input: {}
to the styles object above, the user will then be able to customize it with classes={{ input: 'the-users-input-class' }}
, a common Material-UI pattern).
src/TimeInput.js
Outdated
onChange={this.handleChange} | ||
onMinutesSelected={autoOk ? this.handleOk : null} | ||
classes={{ header: classes.header, body: classes.body }} | ||
minutesStep={minutesStep || 1} |
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.
minutesStep
has a default value set below, so || 1
can be dropped here
src/TimeInput.js
Outdated
@@ -117,14 +128,22 @@ TimeInput.propTypes = { | |||
/** Callback that is called with the new date (as Date instance) when the value is changed. */ | |||
onChange: PropTypes.func, | |||
/** The value of the time picker, for use in controlled mode. */ | |||
value: PropTypes.instanceOf(Date) | |||
value: PropTypes.instanceOf(Date), |
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.
These used to be sorted alphabetically. 😅
} | ||
|
||
TimeInput.defaultProps = { | ||
autoOk: false, | ||
cancelLabel: 'Cancel', | ||
mode: '12h', | ||
okLabel: 'Ok' | ||
okLabel: 'Ok', |
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.
…these, too
src/TimePicker.js
Outdated
value: PropTypes.instanceOf(Date) | ||
value: PropTypes.instanceOf(Date), | ||
/** Steps between minutes. */ | ||
minutesStep: PropTypes.number |
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.
see above
Than you very much for taking the time to review all changes. Right now I'm developing a project against the clock 😅, but as soon as I finish I will try to leave it perfect 👌 |
@Serg4554 No problem, I'm happy that you'll take the time to get this PR ready to merge. :) |
@Serg4554 Do you still have time to finish this PR? Don't worry, I'll update it for you otherwise. 👍 |
@leMaik I will finish the current project that I'm working on in a month aprox. but we have very tight time, so if you could update it, I would appreciate it! Otherwise I will do it, you have my words |
@leMaik All changes we discussed are done, I hope you find them fine and useful! But the coverage has decreased a little bit, I will thank you if you could help me with that :) |
@Serg4554 Awesome! 🎉 I've got this on my radar, I'll look into the tests soon (TM). |
@Serg4554 Would you mind rebasing this on top of master? I'm a bit confused by all the changes right now… |
Hello!
I needed some extra functionalities for my project and I thought that it could be useful for others, so here is the pull request :)
minutesStep
property (number)Allows to choose the steps between minutes, so for instance, if you need to allow times only each 5 minutes, just set
minutesStep={5}
cancelOnClose
property (bool)Allows to decide if the time is cancelled or saved when background is clicked
inputClasses
property (object)Allows to apply classes to input form (only TimePicker was supported)
onChange
when time changesThe time is updated (
onChange
is called) whenever the time is changed and return the init date when is cancelledI hope you find it useful 😃👍