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

ColorPalette: Display checkered preview background when value is transparent #42232

Merged

Conversation

danielbachhuber
Copy link
Member

@danielbachhuber danielbachhuber commented Jul 7, 2022

What?

Avoids styling background when the provided value is transparent (either transparent, or a RGBA/HEX value with transparent alpha channel).

After

image

Before

image

Why?

Fixes #42230

@annezazu
Copy link
Contributor

@WordPress/gutenberg-design for thoughts here :)

@jameskoster
Copy link
Contributor

Makes sense to me 👍

It would be good to fix this holistically to account for alpha channels:

Screenshot 2022-07-12 at 10 37 52

@danielbachhuber
Copy link
Member Author

It would be good to fix this holistically to account for alpha channels:

@jameskoster What's the best way to detect the alpha channel?

@jameskoster
Copy link
Contributor

Sorry, I'm not sure 🙈

@danielbachhuber
Copy link
Member Author

It would be good to fix this holistically to account for alpha channels:

What's the best way to detect the alpha channel?

@jameskoster It turned out to be pretty simple! colord( currentValue ).alpha()

Updated in bcfb85a

@danielbachhuber danielbachhuber changed the title ColorPalette: Avoid stylingbackground when value is 'transparent' ColorPalette: Avoid stylingbackground when value is transparent Jul 15, 2022
@danielbachhuber danielbachhuber changed the title ColorPalette: Avoid stylingbackground when value is transparent ColorPalette: Avoid styling background when value is transparent Jul 15, 2022
@mtias mtias added [Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components [Feature] Colors Color management [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels Jul 26, 2022
Copy link
Member

@mtias mtias 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. @jameskoster we should probably update the transparent circle in the palette to match the newer transparent grid design

@mirka mirka self-requested a review July 26, 2022 15:49
Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! If you could add a quick changelog entry before merging, that would be great.


In a follow-up, we may want to look into tweaking the background implementation so the checkered background can be seen through a semi-transparent color. This is already the case with the circular swatch:

The checkered transparent background cannot be seen through a translucent red color

packages/components/src/color-palette/test/utils.ts Outdated Show resolved Hide resolved
Comment on lines 165 to 167
export const showTransparentBackground = ( currentValue ) => {
return colord( currentValue ).alpha() === 0;
};
Copy link
Member

Choose a reason for hiding this comment

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

Can we add handling (and a test case) for an undefined color value? It will be undefined when the "Clear" button is clicked.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we add handling (and a test case) for an undefined color value? It will be undefined when the "Clear" button is clicked.

@mirka Yep, did with d482da9

@danielbachhuber danielbachhuber changed the title ColorPalette: Avoid styling background when value is transparent ColorPalette: Display checkered preview background when value is transparent Jul 26, 2022
Co-authored-by: Lena Morita <[email protected]>
@danielbachhuber
Copy link
Member Author

Thanks for the fix! If you could add a quick changelog entry before merging, that would be great.

@mirka You're welcome 😄 Did with 23f9b51

In a follow-up, we may want to look into tweaking the background implementation so the checkered background can be seen through a semi-transparent color. This is already the case with the circular swatch:

I actually looked into this. I think it will involve a bit of CSS retooling, though. I didn't feel comfortable contributing the change because I felt like it might delay the review process (and solving 'transparent' is my immediate need).

Comment on lines 28 to 30
test( 'should return undefined for transparent colors', () => {
expect( undefined ).toBe( undefined );
} );
Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry this was unclear, I think the behavior we want is for it to return true:

Suggested change
test( 'should return undefined for transparent colors', () => {
expect( undefined ).toBe( undefined );
} );
test( 'should return true for undefined color values', () => {
expect( undefined ).toBe( true );
} );

The fact that it "works" as expected with the current background implementation is only coincidental. It will be misleading to return a falsy value from showTransparentBackground( undefined ).

Copy link
Member Author

Choose a reason for hiding this comment

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

The fact that it "works" as expected with the current background implementation is only coincidental.

@mirka It's actually because the test is missing the call to showTransparentBackground() 🙈

Fixed with 43afb0c

Copy link
Member

Choose a reason for hiding this comment

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

LOL

Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

I think we're good to go then! 🚀

I actually looked into this. I think it will involve a bit of CSS retooling, though. I didn't feel comfortable contributing the change because I felt like it might delay the review process (and solving 'transparent' is my immediate need).

Agreed, this is the right call 👍 Split into a separate issue at #42715.

@danielbachhuber
Copy link
Member Author

I think we're good to go then! 🚀

Awesome, thanks!

@mirka mirka merged commit f42ea1a into WordPress:trunk Jul 26, 2022
@github-actions github-actions bot added this to the Gutenberg 13.8 milestone Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Colors Color management [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] UI Components Impacts or related to the UI component system [Package] Components /packages/components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ColorPalette: Using 'transparent' as color value produces unexpected preview background
5 participants