Mobile: Dashicon color override#13977
Mobile: Dashicon color override#13977etoledom wants to merge 12 commits intornmobile/release-v1.0from
Conversation
| width={ size } | ||
| height={ size } | ||
| viewBox="0 0 20 20" | ||
| { ...colorProp } |
There was a problem hiding this comment.
It'd be simpler to express this as just color={ color }, skipping all of the colorProp conditions and object spread. I think it should be have exactly the same.
Further, it makes me wonder why not just pass through all additional props to the SVG.
Further further, these edits are made a generated file, where the source lives at https://github.com/WordPress/dashicons . See the note at the top of the file.
There was a problem hiding this comment.
Thanks @aduth for the comments!
It'd be simpler to express this as just
color={ color }
I did try that, but when color is undefined, it would remove the default color we are using for the rest of the icons. (for some reason)
With @Tug we decided to pass a style prop, and extract color from there, with the added advantage of passing more style props, that we are now taking advantage of. Please check the last PR :)
these edits are made a generated file
I was wondering about that. So I should edit https://github.com/WordPress/dashicons/tree/master/sources/react too 🤔
|
Updated to add more clarity to the intention of the code. |
Tug
left a comment
There was a problem hiding this comment.
Tested on gutenberg and gutenberg-mobile, this LGTM 🚢
| height={ size } | ||
| viewBox="0 0 20 20" | ||
| style={ style } | ||
| { ...color && { color } } |
There was a problem hiding this comment.
Can this be just { ...props } to avoid introducing a mobile specific prop to the web component?
The SVG is a component that have two different implementation, this is where the specific code should go right?
There was a problem hiding this comment.
Thank you @youknowriad for the review!
I updated to pass all remaining props directly to SVG. Tested on mobile (iOS and Android) and it's behaving properly. 🎉
Could you check again please?
cc @Tug
There was a problem hiding this comment.
Thanks for the update, I like this implementation better.
| 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.
Can it cause any issues when the same props get passed down to Button and Dashicon?
This one should be tested:
https://github.com/WordPress/gutenberg/blob/master/packages/components/src/form-token-field/token.js#L72
It might apply aria-describedby twice which probably isn't expected.
There was a problem hiding this comment.
Thank you @gziolo , that's a good concern.
Should we pass a specific iconProps?
I think it looks more declarative if we do this:
<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?
|
There are 7 failing unit test: It looks like this needs some further debugging:
|
|
Does this help in any way avoid the Dashicon component being made aware of a "pressed" state, which does not seem a characteristic of an icon ? |
| @@ -27,7 +27,7 @@ export default class Dashicon extends Component { | |||
| } | |||
There was a problem hiding this comment.
Immediately above this is a shouldComponentUpdate, which will prevent the component from being re-rendered even if we pass a new / different set of extraProps.
There was a problem hiding this comment.
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.
Originally there were very few props, probably not more than just icon and size, and it was considered mostly a static component which would never need to be re-rendered.
There was a problem hiding this comment.
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.
Something like @wordpress/is-shallow-equal can provide some easier mechanism to compare all props:
shouldComponentUpdate( props, nextProps ) {
return ! isShallowEqual( props, nextProps );
}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.
@gziolo I have made changes to make the tests pass locally, but it seems like CI is not running here anymore. Any ideas? |
@aduth I think this is a good step for that, since with these changes we can now set a color directly to dash icon passing a color prop on mobile. |
| className, | ||
| isActive, | ||
| isDisabled, | ||
| extraProps, |
There was a problem hiding this comment.
Just noting that extraProps is already in use in some places in Gutenberg:
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 extraProps prop.
| } | ||
|
|
||
| const iconClass = IconClass( this.props ); | ||
| const iconClass = IconClass( icon, className, ariaPressed ); |
There was a problem hiding this comment.
IconClass - it looks like a name of the class but this is a regular function. It should be renamed to getIconClassName.
| 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.
Out of curiosity, since icon can already be specified as an element for more advanced usage, had you considered just passing your own Dashicon element directly, rather than introduce a new separate prop iconProps?
Something like:
<IconButton icon={ <Dashicon icon="whatever" style={ { fill: 'red' } } /> } />There was a problem hiding this comment.
Thank you for this observation!
I didn't consider that option, but it does simplify the PR quite a bit.
There's a new PR that I have created to replace this one: #14631
Would you mind to take a look at it?
Thank you!
|
Closing in favor of: #14631 |
Description
This PR adds the possibility to override the default Dashicons color. This is necessary to solve wordpress-mobile/gutenberg-mobile#546 .
I didn't find any already implemented way to do this, so I had to modify a couple of Gutenberg's
index.jsfiles. I'm not sure if this will affect Gutenberg Web, but local tests were passing.Hopefully there's a better way!
To test:
$bule-wordpresscolor.