-
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
Mobile: Dashicon color override #13977
Changes from all commits
1452702
f60cb58
63f18dc
c28b209
562b9aa
1523473
fc96acd
c2fec4e
91dc3f6
b2a8e62
f7ee93a
59b0824
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export const IconClass = ( props ) => { | ||
const { icon, className } = props; | ||
export const IconClass = ( icon, className ) => { | ||
return [ 'dashicon', 'dashicons-' + icon, className ].filter( Boolean ).join( ' ' ); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export const IconClass = ( props ) => { | ||
const { icon, className, ariaPressed } = props; | ||
export const IconClass = ( icon, className, ariaPressed ) => { | ||
return [ ariaPressed ? 'dashicon-active' : 'dashicon', 'dashicons-' + icon, className ].filter( Boolean ).join( ' ' ); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ export default class Dashicon extends Component { | |
} | ||
|
||
render() { | ||
const { icon, size = 20 } = this.props; | ||
const { icon, size = 20, className, ariaPressed, ...extraProps } = this.props; | ||
let path; | ||
|
||
switch ( icon ) { | ||
|
@@ -901,7 +901,7 @@ export default class Dashicon extends Component { | |
return null; | ||
} | ||
|
||
const iconClass = IconClass( this.props ); | ||
const iconClass = IconClass( icon, className, ariaPressed ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return ( | ||
<SVG | ||
|
@@ -913,6 +913,7 @@ export default class Dashicon extends Component { | |
width={ size } | ||
height={ size } | ||
viewBox="0 0 20 20" | ||
{ ...extraProps } | ||
etoledom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
<Path d={ path } /> | ||
</SVG> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ import Dashicon from '../dashicon'; | |
// is common to apply a ref to the button element (only supported in class) | ||
class IconButton extends Component { | ||
render() { | ||
const { icon, children, label, className, tooltip, shortcut, labelPosition, ...additionalProps } = this.props; | ||
const { icon, children, label, className, tooltip, shortcut, labelPosition, iconProps, ...additionalProps } = this.props; | ||
const { 'aria-pressed': ariaPressed } = this.props; | ||
const classes = classnames( 'components-icon-button', className, { | ||
'has-text': children, | ||
|
@@ -45,7 +45,7 @@ class IconButton extends Component { | |
|
||
let element = ( | ||
<Button aria-label={ label } { ...additionalProps } className={ classes }> | ||
{ isString( icon ) ? <Dashicon icon={ icon } ariaPressed={ ariaPressed } /> : icon } | ||
{ isString( icon ) ? <Dashicon icon={ icon } ariaPressed={ ariaPressed } { ...iconProps } /> : icon } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, since Something like: <IconButton icon={ <Dashicon icon="whatever" style={ { fill: 'red' } } /> } /> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this observation! Thank you! |
||
{ children } | ||
</Button> | ||
); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,8 +19,8 @@ function ToolbarButton( { | |||||||||||||||||||||||||
className, | ||||||||||||||||||||||||||
isActive, | ||||||||||||||||||||||||||
isDisabled, | ||||||||||||||||||||||||||
extraProps, | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that gutenberg/packages/editor/src/components/block-settings-menu/index.js Lines 46 to 57 in 17d509b
So changes proposed will be braking for the components which depend on |
||||||||||||||||||||||||||
children, | ||||||||||||||||||||||||||
...extraProps | ||||||||||||||||||||||||||
} ) { | ||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||
<ToolbarButtonContainer className={ containerClassName }> | ||||||||||||||||||||||||||
|
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.
Immediately above this is a
shouldComponentUpdate
, which will prevent the component from being re-rendered even if we pass a new / different set ofextraProps
.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.
Right. Thank you for pointing that out!
Why are we doing this check with each prop?
Is there any special prop that we don't want it to make the component update?
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.
Originally there were very few props, probably not more than just
icon
andsize
, and it was considered mostly a static component which would never need to be re-rendered.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 for the explanation!
I'm still not sure what's the best approach to follow.
Currently I believe that we are re-rendering icons in some cases.
Would you recommend to remove those checks and let React do its job?
Or is there a good way of comparing
extraProps
directly?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.
Something like
@wordpress/is-shallow-equal
can provide some easier mechanism to compare all props:Which is effectively the same as using
pure
from@wordpress/compose
.But it's lost much of its value here. I don't know that it'd be necessary at all.