-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[RNMobile] iOS DarkMode toolbar buttons #17356
Conversation
Updated this PR implementing the DarkMode refactor from: #17552 @Tug or @mchowning - Could any of you please take a look? Thank you! |
@@ -56,7 +55,7 @@ function IconButton( props, ref ) { | |||
className={ classes } | |||
ref={ ref } | |||
> | |||
<Icon icon={ icon } ariaPressed={ ariaPressed } /> | |||
<Icon icon={ icon } /> |
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.
Are you sure that it's safe to stop passing down this prop?
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.
Yes, it's basically being replaced by this line here:
https://github.com/WordPress/gutenberg/blob/82a96dd640354ba5068dee5a10e6195e96ea65bb/packages/components/src/button/index.native.js#L97
Were we send the colorScheme
and the active
state to all children of Button.
But considering @Tug's comment here: https://github.com/WordPress/gutenberg/pull/17356/files#r328582023 I might need to change this anyway.
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.
I checked the history and it looks like ariaPressed
was introduced in #11827. It was never really used in the web code. Should it be also removed in other places?
In particular, I think about Dashicon
implementation which used to pass this prop down but it seems to longer be necessary. See:
const iconClass = getIconClassName( icon, className, ariaPressed ); |
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.
Filed here: #17741.
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 left a comment about the way we pass the colorScheme props down tho children.
An alternative would be to consider having the colorScheme available in a more global context. Basically have DarkModeProvider
in the EditorProvider (we could rename mode
to colorScheme
), we could get rid of all the HOCs but we would need to use <DarkModeContext.Consumer> ( { colorScheme, active } ) ) =>
whenever we want to access that value
@@ -80,6 +91,12 @@ export default function Button( props ) { | |||
states.push( 'disabled' ); | |||
} | |||
|
|||
const subscriptInactive = getStylesFromColorScheme( styles.subscriptInactive, styles.subscriptInactiveDark ); | |||
|
|||
const newChildren = Children.map( compact( children ), ( child ) => { |
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'd rather we use a context for this:
// in Button:
export const ButtonContext = React.createContext( {
active: false,
colorScheme: 'light',
} );
export function Button( props ) {
...
const buttonContext = {
active: props.active,
colorScheme: props.colorScheme,
};
{ Children.count( children ) &&
<ButtonContext.Provider value={ buttonContext }>
{ children }
</ButtonContext.Provider>
}
...
// in IconButton
<ButtonContext.Consumer>
{ ( { colorScheme, active } ) =>
<Icon icon={ icon } ariaPressed={ active } colorScheme={ colorScheme } />
</ButtonContext.Consumer>
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 copied the idea from here: https://github.com/WordPress/gutenberg/blob/82a96dd640354ba5068dee5a10e6195e96ea65bb/packages/components/src/primitives/block-quotation/index.native.js#L15
And the main idea was to clear up IconButton
from sending the ariaPressed
or active related states.
I like that we can get enough information to style any child of button, but you are right that this might not be the best option.
I'll give this a try!
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.
Thinking about it, I guess using cloneElement should not have any impact on performance, it's just a bit more limited in terms of features. Basically, you'll only be able to access those props from the direct children of the button, whereas a consumer could be added anywhere. If direct children is fine then I guess we can keep it that way.
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.
Yes, the main (and only, so far) usage of this is the IconButton where the Icon
component is a direct child.
So, if you think it's fine to keep this, let's move on 👍
I restarted a CI job to get the ✅ from travis.
Thanks for your review!
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 didn't know about React Context before. Thanks for leaving this comment @Tug !
This helps to properly style buton icons for the given theme. And removes the need to pass aria-pressed to icons directly.
82a96dd
to
640b17f
Compare
@Tug if you agree with this implementation, could you please ✅ to move forward? :) |
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.
Code LGTM 👍
Thank you @Tug ! Thank you! |
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.
Tested and everything looks good. Nice job @etoledom !
Thank you all! |
It should fix #17695, thank you for working on it 👍 |
gutenberg-mobile
PR: wordpress-mobile/gutenberg-mobile#1357Description
This PR allow us to add different styles to DashIcons inside IconButton component depending on the the style theme (Dark/Light mode).
It also enhance the DarkMode theme for Toolbar buttons (and the toolbar separator)
With this change, is not needed to send
ariaPressed
prop fromIconButton
. This is a change that was requested long ago, (even though we still are sending it button states).A second idea is to send styles directly to DashIcon from the Button, to avoid having to declare styles for every new class. I'm not sure if this is something we want to change though.
As always any moment is welcome!
To test: