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

Add styles for Notice component #8856

Merged
merged 15 commits into from
Aug 16, 2018
Merged

Add styles for Notice component #8856

merged 15 commits into from
Aug 16, 2018

Conversation

mmtr
Copy link
Contributor

@mmtr mmtr commented Aug 10, 2018

It adds the needed styles by the Notice component, so it is displayed correctly even if the WordPress Core styles are not available.

@mmtr
Copy link
Contributor Author

mmtr commented Aug 11, 2018

@gziolo @youknowriad

import { __ } from '@wordpress/i18n';

function Notice( { className, status, children, onRemove = noop, isDismissible = true } ) {
const classNames = classnames( className, 'notice notice-alt notice-' + status, {
const classNames = classnames( className, 'components-notice components-notice--' + status, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be __ instead of --

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it's looks like this is a modifier. I think in general our guideline is to use unprefixed booleans. So maybe just: is-warning, is-error...

Copy link
Member

Choose a reason for hiding this comment

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

@jasmussen will know what's the best way to deal with it 😃

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'm feeling what Riad is saying.

I believe we have these notices:

  • Green (Success)
  • Orange (Warning)
  • Red (Error)

I can't recall if there's also a blue informational notice, if there isn't there probably should be.

The default notice should be an informational notice. In addition to that, we could have is-succes, is-warning, is-error.

Did this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. It's consistent with what we do in other components. I have just committed the change using these new modifiers.

@gziolo gziolo requested a review from jasmussen August 13, 2018 07:52
@gziolo gziolo added the [Package] Components /packages/components label Aug 13, 2018
@gziolo gziolo added this to the 3.6 milestone Aug 14, 2018
@gziolo gziolo added the [Type] Enhancement A suggestion for improvement. label Aug 14, 2018
@youknowriad
Copy link
Contributor

The dismiss button doesn't look centered vertically to me. Is this related to this changes?
screen shot 2018-08-15 at 14 16 09

@@ -36,7 +36,7 @@ function ContrastChecker( {
__( 'This color combination may be hard for people to read. Try using a brighter background color and/or a darker text color.' );
return (
<div className="editor-contrast-checker">
<Notice status="warning" isDismissible={ false }>
<Notice status="warning" isDismissible={ true }>
Copy link
Contributor

Choose a reason for hiding this comment

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

debug change ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops :)

@mmtr
Copy link
Contributor Author

mmtr commented Aug 15, 2018

I've just realized that the original WordPress notice was placing the dismiss button at the top right corner, so I have removed the vertical alignment.

Original:
screen shot 2018-08-15 at 16 32 16

New:
screen shot 2018-08-15 at 16 38 32

@@ -7,17 +7,21 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import Dashicon from '../dashicon';
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be moved to "Internal dependencies"

{ isDismissible && (
<button className="notice-dismiss" type="button" onClick={ onRemove }>
<button className="components-notice__dismiss" type="button" onClick={ onRemove }>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we replace this by IconButton instead of button. I think it already takes care of the scree reader label (label prop) etc...

Copy link
Contributor Author

@mmtr mmtr Aug 15, 2018

Choose a reason for hiding this comment

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

I tried to do it, but it presents a problem with the hover styles. Either we use exactly the same rule defined in the IconButton styles for the Notice styles so we have the same specificness, or we add a !important to override it.

screen shot 2018-08-15 at 17 20 33

I didn't like any of the options, so that's why I left the button. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @jasmussen for design insights but I'm pretty sure we can override without !important (repeating the same specificity, granted that it's not great either)

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, I don't consider this a blocker for the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, those hover styles are a bit arduous due to having to work with a number of accessibility concerns. However you can override them without !importants, by using the same level of specificity.

For example, if the hover is .components-icon-button:not(:disabled):_not([aria-disabled="true"]):not(.is-default):hover, you can override it with .components-notice__dismiss.components-icon-button:not(:disabled):_not([aria-disabled="true"]):not(.is-default):hover.

But would also not call that a blocker.

Copy link
Contributor Author

@mmtr mmtr Aug 16, 2018

Choose a reason for hiding this comment

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

Yep. My only concern is that this is less maintainable. If we change the style rules for IconButton component, we might need to also change them in the Notice component.

Anyway, I have overridden them with:

&:not(:disabled):not([aria-disabled="true"]):not(.is-default):hover,
&:not(:disabled):not([aria-disabled="true"]):not(.is-default):active,
&:not(:disabled):not([aria-disabled="true"]):focus {
	color: $alert-red;
	background-color: transparent;
}
&:not(:disabled):not([aria-disabled="true"]):not(.is-default):hover {
	box-shadow: none;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool — do you really need to override the color though? $alert-red as a hover/active color doesn't seem necessary, and it probably will run into contrast issues. Probably just keep the color as is?

margin: 0 0 5px;
padding: 6px 12px;
min-height: $panel-header-height;

.notice-dismiss {
.components-notice__dismiss {
margin: 5px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we tweak this margin to make it appear centered by default if the message is in a single line ?

margin: 10px 5px;

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad youknowriad merged commit 837d908 into WordPress:master Aug 16, 2018
@youknowriad
Copy link
Contributor

youknowriad commented Aug 16, 2018

I went ahead and tweaked the margin a bit. Let me know if it doesn't work for you.

@afercia
Copy link
Contributor

afercia commented Aug 30, 2018

This PR made the dismiss button tooltip not visible with tooltip={ false }. Worth reminding all UI controls must have a visible label, or at least a way to expose their accessible name (and tooltips are already a trade-off).
Imagine speech recognition software user: what command are they supposed to voice to dismiss the notices?
"Click X"? won't work
"Click close"? won't work
How are they supposed to discover the control name is "Dismiss this notice" if it's not exposed in the UI in any way? The tooltip allows, at least, to discover what the control name is and once users have learned it, they can use it directly the following times just voicing the command "Click Dismiss this button".

Will fix in #9443.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants