-
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
ColorPalette
: partial support of color-mix()
CSS colors
#64224
Merged
ciampo
merged 6 commits into
WordPress:trunk
from
Rishit30G:fix/incorrect-gradient-dropdown-label
Aug 20, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
250b9c7
Fix incorrect dropdown label with selected color value
Rishit30G a7e789b
Fix normalizeColorValue function
Rishit30G 055a52e
Add isSimpleCSSColor function
Rishit30G cb1bfef
Fix isSimpleCSSColor function, add early return
Rishit30G 9275984
Update CHANGELOG.md with ColorPalette: partial support of color-mix()…
Rishit30G e46f9a8
Update packages/components/CHANGELOG.md
ciampo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure that we can fully support
color-mix
CSS colors at the moment.I took a look at the component, and noticed that this PR is missing changes in the
normalizeColorValue
function at the bottom of this file. ThenormalizeColorValue
function takes care of converting the chosen color option to a CSS color that is passed to theColorPicker
.I applied the same logic in that function too:
But the computed styles that the browser returns from applying a
color-mix()
color to an element use the CSScolor()
function, which is not a valid input tocolord
(the library that we use to manipulate and normalize color strings).And therefore, when opening the
ColorPicker
, the color initially chosen in the picker is not the correct color, but black (which is the default color thatcolord
outputs when the string that it parses is not valid).Kapture.2024-08-15.at.13.11.48.mp4
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.
What are the repro steps for this by the way? I'm just trying it in the browser and not on this PR branch, but when I try it I get a string for the respective color space. So if I
getComputedStyle()
on an element withbackground-color: color-mix(in oklab, #a71e14 75%, white)
for example, I will get'oklab(0.603981 0.113291 0.0640898)'
.If we can do that, we could possibly add support for it if it's a color space that has a
colord
plugin. Maybe not in this PR though.And yes I'm all for merging changes as long as it's incrementally better than trunk 👍
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.
For example, in latest chrome, if I apply
background-color: color-mix(in srgb, indigo, white)
to an element and then query its computedbackground-color
style, I getcolor(srgb 0.647059 0.5 0.754902)
.I had looked into it, and didn't spot any plugin for the
color()
syntax — and not even for newer color spaces likeoklab
andoklch
I guess it's up to the browser to decide the format of the computed style string, and since
color-mix
can target any color space, to support fullycolor-mix
we'd need to be able to virtually support any color syntax.Also, looking at
colord
repo, I think the project is not being maintained anymore 😱 Given that CSS continues to evolve, I think that thecolord
-based approach is showing its limitations. We should ideally find a browser-based way (either through CSS or native JS) that will guarantee us that whatever CSS color was passed to the component, we're able to parse it, show it, and render a working color picker.👌
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.
Actually, hold up my
canvas
: https://codepen.io/ciampo/pen/QWXamNeThis approach could have potential. We'd need to make sure it can't be somehow blocked by the browser, and that there are no severe performance implications (if needed, we can explore using
OffscreenCanvas
in a separate worker thread).