-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add styles for Notice component #8856
Conversation
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, { |
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.
Should this be __
instead of --
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.
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
...
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.
@jasmussen will know what's the best way to deal with it 😃
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 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?
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.
Yep. It's consistent with what we do in other components. I have just committed the change using these new modifiers.
@@ -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 }> |
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.
debug change ;)
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.
oops :)
@@ -7,17 +7,21 @@ import classnames from 'classnames'; | |||
/** | |||
* WordPress dependencies | |||
*/ | |||
import Dashicon from '../dashicon'; |
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 should be moved to "Internal dependencies"
{ isDismissible && ( | ||
<button className="notice-dismiss" type="button" onClick={ onRemove }> | ||
<button className="components-notice__dismiss" type="button" onClick={ onRemove }> |
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 we replace this by IconButton
instead of button
. I think it already takes care of the scree reader label (label prop) etc...
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 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.
I didn't like any of the options, so that's why I left the button
. What do you think?
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.
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)
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.
Btw, I don't consider this a blocker for the PR.
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.
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.
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.
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;
}
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.
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; |
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 we tweak this margin to make it appear centered by default if the message is in a single line ?
margin: 10px 5px;
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 👍
I went ahead and tweaked the margin a bit. Let me know if it doesn't work for you. |
This PR made the dismiss button tooltip not visible with Will fix in #9443. |
It adds the needed styles by the
Notice
component, so it is displayed correctly even if the WordPress Core styles are not available.