-
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
Add basic theming to the @wordpress/components
package
#44116
Comments
I'm thinking of starting with something like (in order of priority):
Very simple, three official variables. Everything else (borders, shadows, darkened accent colors, etc.) we can try and automatically generate internally based on the given colors. It might be possible that we can manage without even exposing the foreground color (i.e. text), because we could just infer a black or white scheme based on the background color contrast. The approach diverges on how to handle the auto-generation. We could calculate everything in CSS only, by enforcing consumers to set the CSS variable in distinct RGB or HSL values (some variation on this technique). But I think it would be easier for everyone if we added a nestable theme provider component to handle the calculations in JS: <ThemeProvider accent="#007cba" background="#1e1e1e">
<MyHeader />
<ThemeProvider background="#fff">
<MyEditor />
</ThemeProvider>
</ThemeProvider> This way we can more easily do contrast-based manipulation with I feel like this would cover most sensible use cases. And the very hardcore consumer could still override the generated CSS variables at the CSS level if they wanted to get more granular. |
Agreed. The simpler we start, the better IMO.
Based on personal experience with implementing a similar system, I'm a bit skeptical that we'll manage to find a formula that auto-generates colors in a way that is pleasing and well "proportioned" to the human eye for all possible colors — but we should definitely give it a shot, see where we get, and iterate.
I liked the idea of using vanilla CSS variables, since it feels cleaner and "closer to the metal" (i.e. using CSS APIs for styling components). At the same time, I agree that using React context will give us extra flexibility in handling and transforming the values, while still preserving the same "cascade" mechanism that we would have with CSS |
I was thinking we don't even need context, just render a ThemeProvider as |
Edit: the plane of action originally written in this comment has been moved to the issue's description |
What
Allow the components package to be themed by its consumers
How
The components package would allow theming by exposing a few CSS variables (e.g "primary color", "text color", "background color", "border radius"...). The package would have default values for each variable, but any consumer of the package would be able to override those values.
These variables would be applied to all components in the package, regardless of how they are used within the editor. But given the nature of CSS and CSS variables, different overrides could be applied in different DOM subtrees (e.g the sidebar wrapper could set a different background colors from the navigation panel, etc etc).
Having the package expose its own variables (instead of using gutenberg-specific variables) would help to decouple the package from the rest of the editor, and make it more reusable.
Things to discuss / refine:
Action plan
Theme
component Components: Try color theming #44668accent
color in every component #45249gray
a good name for the theming variables? (see convo)lighten
andrgba
) which don't work with dynamic, runtime theme colors (see convo)Slot/Fill
and portals in general (ie.Popover
and components usingPopover
s that may want their popover content to be themed accordingly)Tooltip
shsl
(and expose each color's component as a separate variable)? Should use OKLCH + polyfills?--wp-admin*
css variables and see if we should something about it@base-styles
and@block-editor
overrides--wp-admin-theme-color
usage in wp-components Components: Add stylelint rule for theme var regressions #58098 Components: Add eslint rule for theme var regressions #58130Context
LIGHT_GRAY
color object #43994 (comment)The text was updated successfully, but these errors were encountered: