Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

diegoliv
Copy link

@diegoliv diegoliv commented Jun 5, 2018

Description

Currently, the <ColorPalette /> component enforces the alpha channel from react-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 to false 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 the hex value for the color. If opacity has a different level, then we return the rgba() value for the color.

@diegoliv
Copy link
Author

diegoliv commented Jun 5, 2018

@danielbachhuber here is an updated PR that replaces #5835. Take a look and let me know if is there anything to be tweaked.

@danielbachhuber danielbachhuber requested a review from a team June 5, 2018 23:26
Copy link
Member

@danielbachhuber danielbachhuber left a 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.

Copy link
Member

@tofumatt tofumatt left a 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.

@@ -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 } ) {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tofumatt done!

colorString = color.hex;
} else {
const { r, g, b, a } = color.rgb;
colorString = 'rgba(' + [ r, g, b, a ].join( ',' ) + ')';
Copy link
Member

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.

Copy link
Author

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.

const { r, g, b, a } = color.rgb;
colorString = 'rgba(' + [ r, g, b, a ].join( ',' ) + ')';
}
onChange( colorString );
Copy link
Member

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?

Copy link
Member

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

What's the code path?

Copy link
Member

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!

@danielbachhuber
Copy link
Member

Holding on merge per #7246. Sorry about that, @diegoliv — I appreciate the work you've put into this.

@gziolo
Copy link
Member

gziolo commented Jun 21, 2018

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.

@gziolo gziolo added the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Jun 21, 2018
@gziolo gziolo modified the milestones: 3.1, 3.2 Jun 21, 2018
@danielbachhuber
Copy link
Member

Yes, we're currently blocked by #7246

@danielbachhuber danielbachhuber removed this from the 3.2 milestone Jun 21, 2018
@TheoL
Copy link

TheoL commented Nov 5, 2018

#7246 has been fixed. Can you now proceed with this?

@tofumatt
Copy link
Member

tofumatt commented Nov 5, 2018

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. 😄

@TheoL
Copy link

TheoL commented Nov 5, 2018

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.

@tofumatt
Copy link
Member

tofumatt commented Nov 5, 2018 via email

@gziolo
Copy link
Member

gziolo commented Nov 19, 2018

It needs to be rebased with the latest changes from master branch.

@earnjam
Copy link
Contributor

earnjam commented Dec 21, 2018

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?

@diegoliv
Copy link
Author

@earnjam I stopped working on this since the team started working on #7246 and this PR was put on hold. I can pull the latest version and fix the PR.

Copy link
Member

@gziolo gziolo left a 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 👍

@gziolo gziolo added [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. and removed [Status] Blocked Used to indicate that a current effort isn't able to move forward labels Feb 1, 2019
@gziolo
Copy link
Member

gziolo commented Apr 24, 2019

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!

@gziolo gziolo closed this Apr 24, 2019
@gziolo gziolo added [Feature] UI Components Impacts or related to the UI component system [Type] Enhancement A suggestion for improvement. labels Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ColorPalette: enable alpha channel
6 participants