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

Custom Input Icon--calendar position #627

Merged
merged 11 commits into from
Aug 15, 2017
Merged

Custom Input Icon--calendar position #627

merged 11 commits into from
Aug 15, 2017

Conversation

mariepw
Copy link
Contributor

@mariepw mariepw commented Jul 18, 2017

Hi @majapw, Hi all,
I implemented the changes proposed in #625 by adding prop 'showInputIconRight' to 'SingleDatePicker' and 'DateRangePicker'.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 86.283% when pulling 3430bdf on mariepw:CustomPositionIcon into f149c68 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 86.283% when pulling 3a13698 on mariepw:CustomPositionIcon into f149c68 on airbnb:master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

I'm also wondering if perhaps we want an enum for inputIconPosition that can be either "before" or "after", rather than a boolean?

@@ -51,6 +51,7 @@ const defaultProps = {
screenReaderInputMessage: '',
showClearDates: false,
showDefaultInputIcon: false,
showInputIconRight: false,
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid using terms like "Right" - in an RTL world, "after" is more appropriate.

@@ -123,6 +126,18 @@ export default class DateRangePickerInput extends React.Component {
});
}

renderInputIcon(inputIcon) {
return (<button
Copy link
Member

Choose a reason for hiding this comment

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

the ( should end the line, and the ) should begin the line - iow:

return (
  <button
    type="button"
    className="DateRangePickerInput__calendar-icon"
    disabled={this.props.disabled}
    aria-label={this.props.phrases.focusStartDate}
    onClick={this.props.onArrowDown}
  >
    {inputIcon}
  </button>
);

Also, please destructure all props at the top of the function.

@@ -89,6 +92,18 @@ export default class SingleDatePickerInput extends React.Component {
});
}

renderInputIcon(inputIcon) {
return (<button
Copy link
Member

Choose a reason for hiding this comment

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

indentation and prop destructuring here also

@mariepw
Copy link
Contributor Author

mariepw commented Jul 19, 2017

Thanks for your review, I've done the requested changes.

ljharb
ljharb previously requested changes Jul 19, 2017
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM pending the last few comments.

@@ -45,6 +45,7 @@ const propTypes = forbidExtraProps({
readOnly: PropTypes.bool,
showCaret: PropTypes.bool,
showDefaultInputIcon: PropTypes.bool,
inputIconPosition: PropTypes.oneOf('before', 'after'),
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 come from the shape, so that it doesn't have to be defined more than once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DateRangePicker imports shape, but DateRangePickerInput and DateRangePickerInputController don't.. Do I have to change the complete structure?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure you need to refactor much; newly importing the shape should be fine.

Copy link
Contributor Author

@mariepw mariepw Jul 19, 2017

Choose a reason for hiding this comment

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

SimpleDatePickerShape/SimpleDatePicker and DateRangePickerShape/DateRangePicker share same props..
But DateRangePickerInputController SimpleDatePicker DateRangePickerInput, they all have their own props, which are quite different from parents [..Shape and ..Picker]..
I think shape files have props that input ones don't need..
But maybe I miss something, will investigate a bit more..

Copy link
Member

Choose a reason for hiding this comment

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

There's a couple alternatives here; one is importing the shape but only extracting the one propType - another is putting this propType in its own file, and importing that in all the places it's needed. I'd prefer that approach tbh :-)

@@ -123,6 +126,22 @@ export default class DateRangePickerInput extends React.Component {
});
}

renderInputIcon(inputIcon) {
const {disabled, phrases.focusStartDate, onArrowDown} = this.props;
Copy link
Member

Choose a reason for hiding this comment

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

curly braces in JS need padding spaces inside them - the linter should be failing here.

@@ -89,6 +92,22 @@ export default class SingleDatePickerInput extends React.Component {
});
}

renderInputIcon(inputIcon) {
const {disabled, phrases.focusStartDate, onFocus} = this.props;
Copy link
Member

Choose a reason for hiding this comment

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

also here

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 86.303% when pulling 8a62d98 on mariepw:CustomPositionIcon into f149c68 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 86.303% when pulling 05a0d96 on mariepw:CustomPositionIcon into f149c68 on airbnb:master.

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.

I think we should pull before, after, and the prop type into reusable variables. :) I also have a few nits about code duplication. O/w this is looking great!

@@ -51,6 +51,7 @@ const defaultProps = {
screenReaderInputMessage: '',
showClearDates: false,
showDefaultInputIcon: false,
inputIconPosition: 'before',
Copy link
Collaborator

Choose a reason for hiding this comment

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

we probably want to pull this 'before'/'after' into the constants file

Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we have the constants file, it'd be better to import that and use BEFORE_POSITION here.

@@ -45,6 +45,7 @@ const propTypes = forbidExtraProps({
readOnly: PropTypes.bool,
showCaret: PropTypes.bool,
showDefaultInputIcon: PropTypes.bool,
inputIconPosition: PropTypes.oneOf(['before', 'after']),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we reuse this, we probably want to save this as a shape, similar to OrientationShape

{inputIcon}
</button>

{(inputIconPosition === 'before' && (showDefaultInputIcon || customInputIcon !== null)) && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could probably pull (showDefaultInputIcon || customInputIcon !== null) && this.renderInputIcon(inputIcon) into a variable above the return and then just have inputIconPosition === 'before' && inputIcon

>
{inputIcon}
</button>
{(inputIconPosition === 'before' && (showDefaultInputIcon || customInputIcon !== null)) && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment applies here

@ljharb ljharb dismissed their stale review July 19, 2017 21:39

LGTM, deferring to @majapw

@mariepw
Copy link
Contributor Author

mariepw commented Jul 20, 2017

Thanks @majapw and @ljharb.
Changes done !

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 86.324% when pulling f8c583c on mariepw:CustomPositionIcon into f149c68 on airbnb:master.

@mariepw
Copy link
Contributor Author

mariepw commented Jul 24, 2017

Build doesn't seem to fail because of my changes...
It seems like it's a npm error

npm ERR! errno 1
npm ERR! react-dates@12.3.0 tests-karma: `karma start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-dates@12.3.0 tests-karma script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2017-07-20T07_36_39_505Z-debug.log

@majapw
Copy link
Collaborator

majapw commented Jul 24, 2017

@ljharb this actually appears to be failing due to some extraneous dependencies being installed after we attempt to install the relevant react version:

npm ERR! extraneous: babel-plugin-react-docgen@1.5.0 /home/travis/build/airbnb/react-dates/node_modules/babel-plugin-react-docgen
npm ERR! extraneous: css-loader@0.28.4 /home/travis/build/airbnb/react-dates/node_modules/css-loader
npm ERR! extraneous: cssesc@0.1.0 /home/travis/build/airbnb/react-dates/node_modules/cssesc
npm ERR! extraneous: marksy@2.0.1 /home/travis/build/airbnb/react-dates/node_modules/marksy
npm ERR! extraneous: webpack-hot-middleware@2.18.2 /home/travis/build/airbnb/react-dates/node_modules/webpack-hot-middleware
The command "if [ -n "${REACT-}" ] && [ "${TEST-}" = true ]; then sh install-relevant-react.sh && npm ls >/dev/null; fi" failed and exited with 1 during .

Do you have any idea what might be going on with that? Do we need to explicitly remove those as well? That seems... weird.

@ljharb
Copy link
Member

ljharb commented Jul 25, 2017

I think the short term fix might be to temporarily remove the npm ls check in master, and then rebase this PR. I'll take care of that tomorrow.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 86.324% when pulling 10def22 on mariepw:CustomPositionIcon into d32e9b3 on airbnb:master.

@mariepw
Copy link
Contributor Author

mariepw commented Aug 3, 2017

Everything should be ok now ?

@mariepw
Copy link
Contributor Author

mariepw commented Aug 9, 2017

Hi,
Did you have a chance to have a look on this ?
Thanks

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.

Couple of comments! Sorry for the delay in reviewing!

@@ -51,6 +51,7 @@ const defaultProps = {
screenReaderInputMessage: '',
showClearDates: false,
showDefaultInputIcon: false,
inputIconPosition: 'before',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we have the constants file, it'd be better to import that and use BEFORE_POSITION here.

constants.js Outdated
@@ -10,6 +10,9 @@ module.exports = {
VERTICAL_ORIENTATION: 'vertical',
VERTICAL_SCROLLABLE: 'verticalScrollable',

BEFORE_POSITION: 'before',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this even more specific and call it ICON_BEFORE_POSITION or something. even ICON_BEFORE would be fine.

@@ -87,6 +90,7 @@ const defaultProps = {
readOnly: false,
showCaret: false,
showDefaultInputIcon: false,
inputIconPosition: 'before',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same. Let's use the variable here.

@@ -109,6 +113,7 @@ export default class DateRangePickerInput extends React.Component {

this.onClearDatesMouseEnter = this.onClearDatesMouseEnter.bind(this);
this.onClearDatesMouseLeave = this.onClearDatesMouseLeave.bind(this);
this.renderInputIcon = this.renderInputIcon.bind(this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't need to be bound.

@@ -123,6 +128,22 @@ export default class DateRangePickerInput extends React.Component {
});
}

renderInputIcon(calendarIcon) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather have this as a variable inputIcon in the render method than its own method.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed: renderFoo methods are generally an antipattern; could this be an SFC, or inline jsx, instead?

@@ -51,6 +54,7 @@ const defaultProps = {
showCaret: false,
showClearDate: false,
showDefaultInputIcon: false,
inputIconPosition: 'before',
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@@ -47,6 +47,7 @@ const defaultProps = {
screenReaderInputMessage: '',
showClearDate: false,
showDefaultInputIcon: false,
inputIconPosition: 'before',
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@@ -75,6 +79,7 @@ export default class SingleDatePickerInput extends React.Component {

this.onClearDateMouseEnter = this.onClearDateMouseEnter.bind(this);
this.onClearDateMouseLeave = this.onClearDateMouseLeave.bind(this);
this.renderInputIcon = this.renderInputIcon.bind(this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't need to be bound

@@ -89,6 +94,22 @@ export default class SingleDatePickerInput extends React.Component {
});
}

renderInputIcon(calendarIcon) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer this as a variable in the render method

@mariepw
Copy link
Contributor Author

mariepw commented Aug 10, 2017

Done :)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 86.492% when pulling e572cb4 on mariepw:CustomPositionIcon into d32e9b3 on airbnb:master.

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.

A few more comments! We're almost there, I promise

constants.js Outdated
@@ -10,6 +10,9 @@ module.exports = {
VERTICAL_ORIENTATION: 'vertical',
VERTICAL_SCROLLABLE: 'verticalScrollable',

ICON_BEFORE_POSITION: 'before',
AFTER_POSITION: 'after',
Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry and can we make this one ICON_AFTER_POSITION as well?

</button>
)}

{ inputIconPosition === ICON_BEFORE_POSITION && inputIcon }
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no spaces after { or before }

@@ -249,6 +256,9 @@ export default class DateRangePickerInput extends React.Component {
</div>
</button>
)}

{ inputIconPosition === 'after' && inputIcon }
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no spaces after { or before }

Also let's use ICON_AFTER_POSITION here.

</button>
)}

{ inputIconPosition === ICON_BEFORE_POSITION && inputIcon }
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no spaces after { or before }

@@ -174,6 +184,9 @@ export default class SingleDatePickerInput extends React.Component {
</div>
</button>
)}

{ inputIconPosition === 'after' && inputIcon }
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: no spaces after { or before }

Also let's use ICON_AFTER_POSITION here.

Choose a reason for hiding this comment

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

Shouldn't the spaces around brackets be linted..?

Copy link
Member

Choose a reason for hiding this comment

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

ideally, but the linter is never the entirety of a codebase's style.


import {
ICON_BEFORE_POSITION,
AFTER_POSITION,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ICON_AFTER_POSITION

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 86.492% when pulling 2195730 on mariepw:CustomPositionIcon into d32e9b3 on airbnb:master.

@mariepw
Copy link
Contributor Author

mariepw commented Aug 14, 2017

Sorry for my oversight, I've done the changes..

@majapw majapw merged commit 13d6254 into react-dates:master Aug 15, 2017
@mariepw mariepw deleted the CustomPositionIcon branch August 16, 2017 07:09
@nikojohnarellano
Copy link

I'm just wondering if this has been implemented already. If so, how can this be used as this is not part of the latest docs. Thanks

@ljharb
Copy link
Member

ljharb commented Dec 28, 2017

Could you file a new issue about the lack of docs?

@Ildarik Ildarik mentioned this pull request Feb 22, 2018
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.

6 participants