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

fix(asinput): Add danger theme to asInput component #91

Merged
merged 1 commit into from
Dec 6, 2017

Conversation

MichaelRoytman
Copy link
Contributor

Add danger theme to asInput component to add alert icon, red text for validation message, and red border to input element

@coveralls
Copy link

coveralls commented Dec 5, 2017

Coverage Status

Coverage increased (+0.005%) to 99.515% when pulling 529cd3b on mroytman/asInput-danger-theme into 57c13c4 on master.

...this.props.className,
]}
styles['form-inline'],
{ [styles['is-invalid']]: !this.state.isValid && this.props.theme.includes('danger') },
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 have no strong feelings about this theme's name. Any opinions?

Copy link
Contributor

Choose a reason for hiding this comment

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

My only thought is that if we ever want to add additional styling in the future whenever !this.state.isValid (like always making the background color red or something) we'd probably want to name that style is-invalid, right?

But even if we have to rename this class it won't be a breaking change (right?), so I don't think it's a big deal either way.

<div className={styles['form-control-feedback']} id={errorId} key="0">
{this.state.validationMessage}

<div className={classNames(styles['form-control-feedback'], { [styles['invalid-feedback']]: this.props.theme.includes('danger') })} id={errorId} key="0">
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 can pull out the this.props.theme.includes('danger') condition into a variable, as the condition is being used twice here, but I was interested to see whether it would be an issue as we add more themes. Is the idea that, as we add more themes, we conditionally apply classnames this way? I'll add a 'hasDangerTheme' variable if this looks good to everyone, otherwise.


<div className={classNames(styles['form-control-feedback'], { [styles['invalid-feedback']]: this.props.theme.includes('danger') })} id={errorId} key="0">
{ this.props.theme.includes('danger') &&
<span
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 an alert icon, which follows UI/UX guidelines laid out here.

@@ -89,15 +101,17 @@ const asInput = (WrappedComponent, labelFirst = true) => {
render() {
const { description, error, describedBy } = this.getDescriptions();
return (
<div className={styles['form-group']}>
<div className={classNames(styles['form-group'])}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any harm in adding classNames?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is any harm, but why do you think it is useful here if there are no class names to join?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my bad. I had added class names and then removed them. I'll switch it back.

@coveralls
Copy link

coveralls commented Dec 5, 2017

Coverage Status

Coverage increased (+0.006%) to 99.516% when pulling 9993c2b on mroytman/asInput-danger-theme into 57c13c4 on master.

@MichaelRoytman
Copy link
Contributor Author

MichaelRoytman commented Dec 5, 2017

I'd be interested in thoughts about this "theme". It's a solution we discussed when considering the modal and styling that studio-frontend needed for the modal, but I haven't gotten around to it because of the accessibility form. Does this look like what was envisioned? I tried to use a similar rationale for this asInput theme.

P.S. If anyone has the bandwidth, it would be great to get this merged soon, since it's needed for the Studio accessibility form that's due by December 12th (although we wanted to get it pushed out by mid-day Friday).

@@ -22,6 +24,7 @@ export const inputProps = {
onBlur: PropTypes.func,
validator: PropTypes.func,
className: PropTypes.arrayOf(PropTypes.string),
theme: PropTypes.arrayOf(PropTypes.string),
Copy link
Contributor

@jaebradley jaebradley Dec 6, 2017

Choose a reason for hiding this comment

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

Naming nit: if this is an array of strings should this be called themes instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@@ -49,9 +52,20 @@ const asInput = (WrappedComponent, labelFirst = true) => {
const desc = {};

if (!this.state.isValid) {
const hasDangerTheme = this.props.theme.includes('danger');
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the this.props.theme.includes('danger') check is implemented in getDescriptions and render you could consider moving this to it's own helper method and that way if you ever have to adjust it / add a theme value, you can do it in one place instead of having to remember to do it in two places.

@coveralls
Copy link

coveralls commented Dec 6, 2017

Coverage Status

Coverage increased (+0.007%) to 99.522% when pulling da6ab3e on mroytman/asInput-danger-theme into 1d25dfc on master.

Copy link
Contributor

@jaebradley jaebradley left a comment

Choose a reason for hiding this comment

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

@MichaelRoytman this looks good - let's hold off merging until @arizzitano takes a look?

I know there is a bit of a time component here but I want to throw something out there:

There's a great post on Medium about lessons learned from doing code reviews. One of the lessons is to not use strings when another type should be used (an enum or a UUID) - this is obviously more applicable for something like Java vs. Javascript. Here's the author's example gist.

There are two points to all of this:

  1. That the themes prop seems to be more like an enum? Like we could have a themes enum in a constants.js where you can pick and choose the themes you want to apply via an interface like <Component... themes={[Theme.DANGER, Theme.UNDERLINE]} />. I know this may seem like a lot of (potentially unnecessary) overhead, but I think it makes the API more accurate. It could also allows us to implement better prop type checking / demonstrate the intention of the themes prop by specifying a specific enum / class vs. PropType.string.
  2. It feels like we're trying to conflate two ideas - this idea of theming, and then this idea of supporting custom class names. They seem (and obviously are) coupled together - I can't tell if this will lead to some pitfall in the future, nor do I know what the right solution is right now, but I'm generally paranoid of exposing two API points that change the same piece of data (in this case, the component's class).

Edit: The more I think about the second point the less I'm worried - I think this is fine for now.

@dsjen
Copy link
Contributor

dsjen commented Dec 6, 2017

@arizzitano -- do you want to take a look? We are under time pressure, and if you intend to look at this, we'd appreciate if you could do so at your earliest convenience so that we can wire everything up.

Copy link
Contributor

@arizzitano arizzitano 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 fine for now -- the enum vs. string concerns are probably not a big deal since the danger theme is only being used in this one place. If we want to change it we can circle back later.

@jaebradley
Copy link
Contributor

jaebradley commented Dec 6, 2017

@MichaelRoytman @dsjen hold on, I'm investigating if style will bump the version - regardless, I'm not sure this is a style anyways. This feels like a fix since you're adding functionality.

Update: here are the default release rules used by semantic-release

{type: 'feat', release: 'minor'},
{type: 'fix', release: 'patch'},
{type: 'perf', release: 'patch'},

Since style is not on that list of release rules there will be no release tag associated with them, which means no new NPM version will be published.

Copy link
Contributor

@jaebradley jaebradley 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 the commit message should be fix(asinput): Add danger theme to asInput component - this will guarantee that a new version of Paragon will be published to NPM (and thus, Studio can incorporate the changes).

Add danger theme to asInput component to add alert icon, red text for validation message, and red border to input element
@jaebradley jaebradley changed the title style(asinput): Add danger theme to asInput component fix(asinput): Add danger theme to asInput component Dec 6, 2017
Copy link
Contributor

@jaebradley jaebradley left a comment

Choose a reason for hiding this comment

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

After updating the commit message with @fysheets, I think this is ready to merge after the build succeeds.

@jaebradley jaebradley merged commit 4f253ff into master Dec 6, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.007%) to 99.522% when pulling d545540 on mroytman/asInput-danger-theme into 1d25dfc on master.

@coveralls
Copy link

coveralls commented Dec 6, 2017

Coverage Status

Coverage increased (+0.005%) to 99.515% when pulling 529cd3b on mroytman/asInput-danger-theme into 57c13c4 on master.

@jaebradley jaebradley deleted the mroytman/asInput-danger-theme branch December 6, 2017 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants