-
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 5 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 |
---|---|---|
|
@@ -27,7 +27,7 @@ export default class Dashicon extends Component { | |
} | ||
|
||
render() { | ||
const { icon, size = 20 } = this.props; | ||
const { icon, size = 20, style, color } = this.props; | ||
let path; | ||
|
||
switch ( icon ) { | ||
|
@@ -913,6 +913,8 @@ export default class Dashicon extends Component { | |
width={ size } | ||
height={ size } | ||
viewBox="0 0 20 20" | ||
style={ style } | ||
{ ...color && { color } } | ||
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. Can this be just 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 @youknowriad for the review! Could you check again please? 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. Thanks for the update, I like this implementation better. |
||
> | ||
<Path d={ path } /> | ||
</SVG> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } { ...additionalProps } /> : 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. Can it cause any issues when the same props get passed down to This one should be tested: It might apply 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 @gziolo , that's a good concern. Should we pass a specific <Button aria-label={ label } { ...additionalProps } className={ classes }>
{ isString( icon ) ? <Dashicon icon={ icon } ariaPressed={ ariaPressed } { ...iconProps } /> : icon }
{ children }
</Button> From the caller: <ToolbarButton
label={ __( 'Add block' ) }
icon="plus-alt"
onClick={ onInsertClick }
iconProps={ { style: styles.addBlockButton, color: styles.addBlockButton.color } }
/> What other solution do you think might be good? |
||
{ children } | ||
</Button> | ||
); | ||
|
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.