-
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
Allow "disableAlpha" for color Picker component to be optional (replaces #5835) #7151
Conversation
…nel inside color picker
@danielbachhuber here is an updated PR that replaces #5835. Take a look and let me know if is there anything to be tweaked. |
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.
👍 Looks good to me! Flagging a second 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.
Largely seems fine but there are a few tweaks I think you could make to tidy up this code.
components/color-palette/index.js
Outdated
@@ -18,7 +18,7 @@ import { __, sprintf } from '@wordpress/i18n'; | |||
import './style.scss'; | |||
import Button from '../button'; | |||
|
|||
export default function ColorPalette( { colors, disableCustomColors = false, value, onChange } ) { | |||
export default function ColorPalette( { colors, disableCustomColors = false, value, onChange, disableAlpha = 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.
A nitpick but it might be nice to sort these props alphabetically. The current ordering makes it harder to sort through arguments and makes this last one feel especially tacked-on.
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.
@tofumatt done!
components/color-palette/index.js
Outdated
colorString = color.hex; | ||
} else { | ||
const { r, g, b, a } = color.rgb; | ||
colorString = 'rgba(' + [ r, g, b, a ].join( ',' ) + ')'; |
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.
You could use template strings here and omit the join; it'd probably be a bit more readable:
colorString = `rgba(${ r }, ${ g }, ${ b }, ${ a })`;
I'm not sure why the Array.join
is being used at all here, it just seems to make it more complex.
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.
@tofumatt yeah, I guess this is me still not 100% used to use ES6 features. But I totally agree with you. Just switched the variable to template strings.
components/color-palette/index.js
Outdated
const { r, g, b, a } = color.rgb; | ||
colorString = 'rgba(' + [ r, g, b, a ].join( ',' ) + ')'; | ||
} | ||
onChange( colorString ); |
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.
Seems there's a code path here where colorString
is undefined
, should we test for its truthiness before running onChange
?
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.
Seems there's a code path here where
colorString
isundefined
What's the code path?
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.
Oh wait, there isn't, but because it's defined as undefined
above it sort of read like maybe there could be.
I actually see why it's this way, never mind me, all good!
Moving this to 3.2 Milestone as it seems to be blocked with #7246. Do I read it properly @danielbachhuber? Feel free to remove the label I'm about to add. |
Yes, we're currently blocked by #7246 |
#7246 has been fixed. Can you now proceed with this? |
I'm fine with that but we probably won't look to merge it until after 5.0 ships as it's a reasonable UI change and we are trying to freeze the UI–at least as much as possible. 😄 |
disableAlpha will still default to true so from a UI perspective it shouldn't be an issue - existing code will continue to work in the same way. I need this for a plugin I am creating which I was hoping to release when 5.0 is officially out. |
Ah right; sorry, it's been awhile since I looked at the issue. Makes sense to me!
|
It needs to be rebased with the latest changes from |
I just ran into this issue. It would be nice to tidy up the branch and try to get this shipped. @diegoliv are you still working on this? |
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.
@diegoliv, that would be great to get it up to date 👍
This Pull Request wasn't updated for quite some time. Let's close it to let other contributors work on it. @diegoliv you can still refresh your work and ask for another round of review. It looks like this proposal is very close to be ready. Thank you for your contribution so far! |
Description
Currently, the
<ColorPalette />
component enforces the alpha channel fromreact-color
to be disabled. Like described on #5811, there are benefits of giving developers the option to enable the alpha channel inside the color picker.Previously #5835
Fixes #4726
Tested With
WordPress 4.9.4
Gutenberg 2.4.0
PHP 7.0.3 / nginx
MySQL 5.5.55
Types of changes
This PR introduces the ability to conditionally set a
disableAlpha
parameter for the<ColorPallete />
component. It is set tofalse
by default so it won't conflict with existing blocks that uses this component. Also, the returned color string depends on how the alpha channel inside the color picker is set. If opacity is 100%, we just return thehex
value for the color. If opacity has a different level, then we return thergba()
value for the color.