Open coreyworrell opened 2 years ago
@aaronrobertshaw curious if you have any insights or thoughts here :)
Thanks for the ping 👍
This is an interesting idea and would be a nice feature. I'm not sure there is an easy win here though.
The predefined colors in a restricted theme palette could be anything including CSS custom properties. This would make modifying the color value itself via a generic opacity control trickier.
There's be some design challenges to address as well. Primarily, the proliferation of opacity controls. We generally have text, background, and link colors but we could also have hover states, secondary colors such as striped table rows etc. That's a lot of opacity controls if we can't wrap those within existing components.
The Cover block's opacity control is a bespoke solution that is surprisingly complex and prone to causing some backwards compatibility issues as we refine the Cover block. That gives some extra cause for proceeding with caution. Ultimately, I'm not sure how portable the Cover block's approach is.
Would be neat to keep the reference to the selected color
@aaronrobertshaw skipping that part above, I don't think it would be any different than how it currently works. I assume that the existing solution is getting the rendered color (even if authored as a variable) and then converts it to an rgba value when opacity is adjusted? So it could work the same under the hood, just not expose the entire custom color UI, rather just the opacity slider.
Okay, I was distracted by the comment stating the desire for it to be like the Cover block opacity.
Just like how the Cover block overlay colors works basically.
Another option to explore might then be:
customOpacity
or value for the color.custom
flag in theme.jsonIt might also be worth considering what colors we allow this for as transparency has accessibility implications. Enabling the alpha channel on text colors already impacts our contrast checking etc. Not a blocker just something to consider in the bigger picture.
Currently the editor uses an inline style to accomplish this. Here's the same theme color swatch in Twenty Twenty-Two, but with the opacity adjusted on the second paragraph:
<p class="has-primary-background-color has-background">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Eam stabilem appellas. Sed ne, dum huic obsequor, vobis molestus sim. Itaque rursus eadem ratione, qua sum paulo ante usus, haerebitis.</p>
<p class="has-background" style="background-color:#1a444787">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Eam stabilem appellas. Sed ne, dum huic obsequor, vobis molestus sim. Itaque rursus eadem ratione, qua sum paulo ante usus, haerebitis.</p>
Enabling the opacity control with custom colors disabled would also lead to inline styles embedded into content, and I can't think of a way to avoid that[^1] outside of revamping the way the editor handles colors to rely on the split property trick, which would really bloat the CSS generated.
If this option is added I hope it will be not be the default, as one reason we disable custom colors is to avoid polluting our markup with inline styles.
[^1]: Eventually, the relative color syntax in CSS Color Level 5 will be great for this, but it hasn't yet shipped in any browsers.
If this option is added I hope it will be not be the default, as one reason we disable custom colors is to avoid polluting our markup with inline styles.
I wouldn't expect it to be the default either. It's more of a niche use case in my view and would require opt-in.
Yes your option 4 sounds just like what I'd expect to happen. As far as accessibility, are you saying that the contrast checker cannot properly work with alpha values yet? Or are you saying that setting opacity could lead to bad contrast? If the latter, users are already warned about that with a message in the panel right? I don't see any reason to disallow certain colors, as ultimately it's the end-users' choice to have "inaccessible" content.
As far as accessibility, are you saying that the contrast checker cannot properly work with alpha values yet?
There are difficulties in accounting for multiple alpha layers to be able to determine whether minimum contrast levels have actually been attained. As a result, when transparent text is chosen, a generic "Transparent text may be hard to read" message is displayed. Some history can be found in the PR enabling the alpha channel for color block supports.
My point was that it is something to consider when the time comes to allow opacity changes to preset colors and what shape the potential flags in theme.json may take. Is it all or nothing? Or, should we allow more fine grained control such as allowing it for backgrounds but not text etc?
I don't see any reason to disallow certain colors, as ultimately it's the end-users' choice to have "inaccessible" content.
I agree we should respect and allow a user's choice. We also have a responsibility to help guide better decisions, design, and accessibility.
What problem does this address?
6.0 introduced opacity control for colors. It only appears though if custom colors are enabled. If you disable those and only allow a theme palette, you cannot control the color opacity.
It would be very cool to be able to limit colors while at the same time allowing an opacity of the theme's palette to be used.
What is your proposed solution?
Perhaps move opacity to a separate control inside the Colors panel. Currently setting an opacity changes the color to a custom color. Would be neat to keep the reference to the selected color, but allow opacity. Just like how the Cover block overlay colors works basically.
@annezazu