gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Default Colors, Theme Colors, and Custom Colors

Open mtias opened this issue 5 years ago • 58 comments

What is the problem?

Color handling in Gutenberg comes in two forms: colors picked from a palette and custom colors. Core provides a default color palette which can be overwritten by a theme. Colors assigned to a palette are expressed through classes. The same model applies to gradients. This is issue is not about the technical aspects of when to classes, inline styles, variables, etc, are employed but about the user expectations and theme integration.

At the moment, it’s frustrating as a user that upon switching to a theme that overwrites the default color palette you lose access to the rainbow-color set that comes with core. The core palette aims to provide quick access to distinct hues reliably. A theme palette generally aims to define a restricted set of semantic colors for branding.

The heart of the issue is the conflict that arises since colors are not always used semantically but also for individual expression. A theme might have added a color palette with just two colors — a green and a black — to define its aesthetics. Now, if a user is interacting with a pattern that contains an image with a rural landscape and the green color is picked because it matches the tone of the image, that use is not semantic in the sense the user wouldn’t expect it to change if they switch themes. Gradients are even more pronounced given there’s no sense of “primary”, “secondary”, not even distinct color names and they can be a lot more decorative (the theme Seedlet is a good example, with gradients that work more as background patterns). Assembling a gradient from scratch is also more laborious.

This distinction between semantic colors and local colors has implications for theme switching, global styles, etc. So we need to expand the handling of colors.

Another problem is tying user customization to globally used colors. Right now a custom color can only be replicated by remembering and replicating its color code. There should be an easier way to transfer a local color choice into the shared palette.

Finally we have the situation of patterns, which need to set inline colors right now to ensure they work as expected. This shouldn’t be needed if the pattern wants to use a color from the default color palette.

Proposal

Separate the core palette from the theme palette

A first step is to make the theme color palette something that works in addition to the default palette. That would allow themes to register preferred colors without necessarily overwriting the default palette. Of course, it still needs to be possible to fully disable the default palette since sites that have stricter branding guidelines might prefer to remove it entirely, the same way the custom colors interface can be disabled, but it should not be the default behaviour that a theme palette overwrites the color palette.

image

Treat theme colors semantically

The other part is treating theme colors as colors that should change upon a theme switch. This is obvious for the global styles context, where headings or link colors set to a theme color should change when switching themes. But it can also be extended to theme colors employed locally.

There is always going to be some uncertainty in determining what the intention is when applying a local color, but by having a more clearly defined “Theme” group we can set a better expectation than what is currently the case — if I apply a theme color rather than a color from the spectrum to a button block, it’s easier to expect it to change upon theme switching.

The approach of having theme colors more clearly presented in the UI, in addition to the default color-spectrum, will allow us to finally tackle a big part of the conundrum outlined in #7553. Theme colors (of the primary and secondary kind) will be expected to map to the same variables on the next theme while dark-red and light-blue are consistently provided by core but could still be tweaked within their hue range in a still predictable way (for example, we might update the default color palette with a "vibrant" or "muted" variant of the same color-coded names).

Extending the default palette

The default palette should be user customizable (as it is now in Global Styles), so a user can add, edit, or remove from it and sustain it through theme changes. That doesn't change. It's conceivable that the current colors in the default palette would need to be added, updated, or removed in the future. We should work with the assumption that we might add more default palettes in the future and that we should retain the current mappings indefinitely.

Bubble up local changes

Colors picked locally could automatically become part of the custom user palette so that the next time they want to pick the same color it's present there. A user should be able to remove a custom color at any time so that the custom palette doesn’t grow indefinitely if you use many custom colors locally. A tricky implementation detail is how to go from inline disposable color to a class-based one for this reuse, but this also helps address that problem by making it more obvious that adding a color (at least in certain contexts) automatically creates a class mapping for it.

Integration with patterns

By ensuring the default colors are present through their class mappings patterns can reliably work with them even in cases where they might not figure out in the UI for whatever reason. This is important to support a wide range of patterns and limit the need to resort to inline styles for effects.

mtias avatar Mar 04 '21 16:03 mtias

Implementing multiple palettes as described above would go a long way and improve things both for end-users and developers. The only thing I would like to add to the above proposal is that ideally we'd also have some sort of universal naming convention for theme-defined colors. This way the "primary" color will most likely be named primary and not mytheme-primary-dark, sothings won't break when switching themes.

aristath avatar Mar 05 '21 09:03 aristath

Reading the above I imagine:

Gutenberg by default will provide a given set of styles. "Semantic" styles. These are the agreed-upon colors that will always be provided. Themes depend on it, patterns depend on it, blocks depend on it.

--wp--preset--colors--primary is always something we can depend on. This is what you mean by "core palette".

A theme can use that variable to style blocks. "Primary goes in this color, foreground goes in that color" A theme can set those variables. Maybe even from colors in the palette it provides. "Primary = 'golden pond'"

A user can set that value to whatever they want. When they do change that value it sticks between themes. If they change any value of the primary, etc set that it's locked in. That's their global palette. If they reset the global styles then that palette goes to whatever the theme expressed or whatever Gutenberg defaults it to if the theme doesn't express anything.

Templates and blocks can use those variables and styles in their templating. ".has-primary-color" will always be available what you (and the user) think it is.

pbking avatar Mar 05 '21 13:03 pbking

@nosolosw one of the quick steps I imagine here would be to introduce a new defaultColorPalette = true property in theme.json, which themes can disable if they don't want default colors at all.

mtias avatar Apr 21 '21 16:04 mtias

one of the quick steps I imagine here would be to introduce a new defaultColorPalette = true property in theme.json, which themes can disable if they don't want default colors at all.

Thinking on UI: what do you think would be a good first step to match that change? Do we need to create separated palettes in the UI or can we start by having a long list of colors with what we have today (sorted: first core, then theme)?

The default palette should be user customizable (as it is now in Global Styles), so a user can add, edit, or remove from it and sustain it through theme changes. That doesn't change.

So, the user can change all palettes (core, theme, user). In terms of theme.json shape/keys, everything can remain the same, we just need to change behavior (don't overwrite palettes).

What are your thoughts on themes changing the color value of the color palette? For example, does it make sense that a theme can change the core yellow's value to a different sort of yellow? I'm thinking we don't need this to start, it seems to go against the spirit of this issue. If we wanted to do this, we could offer the option to only change the values but not the slug (so the generated classes still have the same names) or the UI name (so there's an incentive that themes that change the color don't do things like changing a yellow to a purple).

We should work with the assumption that we might add more default palettes in the future and that we should retain the current mappings indefinitely.

I'm thinking that we may want to cross that bridge when we get to it? Food for thought: depending on our needs, we could do different things such as allow multiple palettes per origin (multiple palettes for core, multiple for themes, etc), allow for having colors that aren't shown in the UI but still generate classes (deprecated colors, so to speak), etc.

oandregal avatar Apr 21 '21 19:04 oandregal

Do we need to create separated palettes in the UI or can we start by having a long list of colors with what we have today (sorted: first core, then theme)?

Yes, listing one after the other is fine for now.

For example, does it make sense that a theme can change the core yellow's value to a different sort of yellow? I'm thinking we don't need this to start, it seems to go against the spirit of this issue.

Right, this is not planned to be changeable at first through themes. In the future we might unlock the values like you describe.

I'm thinking that we may want to cross that bridge when we get to it?

Agreed :)

mtias avatar Apr 23 '21 14:04 mtias

I've prepared a PR that could be a first step for this https://github.com/WordPress/gutenberg/pull/31669

oandregal avatar May 10 '21 16:05 oandregal

one of the quick steps I imagine here would be to introduce a new defaultColorPalette = true property in theme.json, which themes can disable if they don't want default colors at all.

This is a great idea! I was recently looking for a solution on how to add additional colors to the default colors. I am happy to hear there will be a solution to it.

I am wondering, would it be possible to add additional colors via PHP in classic themes?

Will we be able to use, for example add_theme_support( 'editor-color-palette' ); to extend default colors?

dashkevych avatar May 10 '21 17:05 dashkevych

Initial version of this landed, we have a couple follow-up PRs to address some related issues but for now, I'm removing this issue from the must-have board as the UI is not expected in 5.8.

youknowriad avatar May 26 '21 08:05 youknowriad

I love where this is going! I think having colors coming from core is ideal and gives a great baseline API for theme authors to work with.

Naming variables is never easy. Leveraging a baseline set of semantic variable names and then adding a layer of aliasing on top for theme authors to override is ideal (to me).

colorful-tones avatar May 31 '21 11:05 colorful-tones

Splitting theme and core palettes:

Yes, absolutely, yes. This will be a good thing for the block directory since we would have standard names from core that are always available.

What I'd like to see is the ability for themers to disable the UI part of core colors though while still supporting them as part of the core CSS package. Freelancers/agencies might not want clients choosing something outside of the color scheme.

Semantic theme color palette naming:

I've been working on a solution for this in the last few weeks. Here's a theme.json look at the result: https://gist.github.com/justintadlock/0003b82a1fc753b8bae54fad5b8cfd55

It is a combination of a Tailwind-like "shade" system based on the feedback from several theme designers on what they need on the average project. There are 4 groups of colors: 1) always-available, 2) neutral, 3) primary, and 4) secondary.

The shading system goes from 100, 200...900 (lightest - darkest). Using this system gives us 30 colors in total, which may be complete and utter overkill for many. An easy way to cut back on that is to skip the even shades, going from 100, 300...900. That will cut it down to 18 in total.

I also think such a shading system could have applications as we consider dark mode down the line.

Group 1: Always Available

.wp--preset--color--transparent
.wp--preset--color--black
.wp--preset--color--white

Group 2: Neutral Color

These are often text, borders, backgrounds, etc. Usually your "grays".

.wp--preset--color--neutral-100
.wp--preset--color--neutral-200
.wp--preset--color--neutral-300
.wp--preset--color--neutral-400
.wp--preset--color--neutral-500
.wp--preset--color--neutral-600
.wp--preset--color--neutral-700
.wp--preset--color--neutral-800
.wp--preset--color--neutral-900

Group 3: Primary Color

This would be the primary/brand color used throughout the site. Links, buttons, etc.

.wp--preset--color--primary-100
.wp--preset--color--primary-200
.wp--preset--color--primary-300
.wp--preset--color--primary-400
.wp--preset--color--primary-500
.wp--preset--color--primary-600
.wp--preset--color--primary-700
.wp--preset--color--primary-800
.wp--preset--color--primary-900

Group 4: Secondary Color

Often unneeded, but this is for a secondary or accent color that is separate from the primary.

.wp--preset--color--secondary-100
.wp--preset--color--secondary-200
.wp--preset--color--secondary-300
.wp--preset--color--secondary-400
.wp--preset--color--secondary-500
.wp--preset--color--secondary-600
.wp--preset--color--secondary-700
.wp--preset--color--secondary-800
.wp--preset--color--secondary-900

justintadlock avatar May 31 '21 16:05 justintadlock

Instead of having all those -100 and -800 variants. I would rather maybe see a mechanism like a stepper, slider UI that can be controlled via API. So, if a purple exists but theme developer only wants to allow for certain steps (e.g. --200, --400, --900) then it would have just those increments on slider.

colorful-tones avatar May 31 '21 17:05 colorful-tones

Instead of having all those -100 and -800 variants. I would rather maybe see a mechanism like a stepper, slider UI that can be controlled via API. So, if a purple exists but theme developer only wants to allow for certain steps (e.g. --200, --400, --900) then it would have just those increments on slider.

Upon second thought, the existing color picker UI would still be more suitable for this, as opposed to input type="range". Surfacing the colors as visual color is always more ideal user experience 😄

colorful-tones avatar Jun 01 '21 14:06 colorful-tones

@justintadlock @kjellr and I discussed this in #themereview the other day.

I've come to appreciate @justintadlock approach and naming convention.

I think this lays a solid foundation for theme authors to work with. Standardizing on these variable names is critical to setting up a scaffolding for themes to operate, while allowing interoperability when users switch themes.

colorful-tones avatar Jun 18 '21 11:06 colorful-tones

I've also gone ahead and put this on the radar for #core-css weekly, as we're currently having ongoing discussions about CSS Custom Property naming conventions.

Recently we've been focused on @ryelle experimental work on WP Admin color schemes with Custom Properties. Here is our single source of truth in shared Google Doc: WordPress Core CSS custom property naming

colorful-tones avatar Jun 18 '21 11:06 colorful-tones

A couple thoughts after diving into colors lately:

I've been playing around with the Automattic theme.json supported themes and across a few other points. BlockBase, Seedlot Blocks, and Blank Canvas all have primary, secondary, background, and foreground colors added. Quadrat does not, but perhaps it will (or should).

1. Should we consider background and foreground also standard colors that should be accounted for in block themes?

If so, it would enable patterns to do flex a bit more creatively, if for example, they used a primary color for a background, and the site background color for the foreground/text — like this:

Screen Shot 2021-07-06 at 2 55 16 PM

Looks great — and can make for interesting styles. However... that only works if the primary color and background color are contrasting. In the case of BlockBase and Seedlet, the primary colors are dark, whereas the background color is white (high contrast). So naturally, swapping the two works. 🤨

2. So, should we account for light & dark colors?

Should we have --light or --dark appended to slugs to indicate a primary--dark or primary--light color? This way, a pattern could declare that it should have a dark background with light text (via the theme's color declarations) — instead of working some of the time?

And this wouldn't happen: Screen Shot 2021-07-06 at 3 24 02 PM

3. And (or instead of #2) should we have baseline mono--light and mono--dark colors?

They don't have to be white/black but variations of the like.

These may be a lot to standardize, but if we're really trying to open up flexibility between themes/patterns/block styles, I think we need to lean in this direction.

🎨

richtabor avatar Jul 06 '21 21:07 richtabor

How about a required minimum default palette for themes?

Like @richtabor, I've also been doing a deep dive into handling global colors in block-based themes, here are some findings:

Global Color handling in Elementor = Sensible Defaults + Flexibility

Elementor has done an excellent job as far as handling global colors by offering both sensible defaults and lots of flexibility. In Elementor, you can easily achieve a Tailwind-esque palette as @justintadlock is proposing as well as a more semantic approach like @pbking is referring too.

The default palette naming strategy in Elementor is Primary, Secondary, Text, and Accent. The palette labels can be changed but the underlying custom properties remain the same and can't be deleted: --e-global-color-primary, --e-global-color-secondary, --e-global-color-text, --e-global-color-accent

Screen Shot 2021-07-06 at 3 44 07 PM Screen Shot 2021-07-06 at 3 43 58 PM Screen Shot 2021-07-06 at 3 45 51 PM

Tailwind-esque & Semantic Global Colorl Color handling in Gutenberg

I've found myself testing both versions of these palettes in block-based themes and ultimately it comes down to the design and what colors I need.

In one site build I need multiple shades of a primary color (tailwind-esque variants), in another I need 4 distinctly different but semantically named colors:

Screen Shot 2021-07-06 at 3 52 07 PM

So far I've landed here as my default for block-based themes, which also echos @richtabor's light & dark palette slugs:

Screen Shot 2021-07-06 at 4 06 52 PM

Required minimum default palette for themes?

With all that being said, how about a required minimum default palette for themes that uses a standard naming convention?

  • with semantically named slugs such as primary, secondary, accent
  • theme builders/users can easily extend the minimum default palette
  • theme/pattern/plugin builders can know that a theme is going to have a minimum default palette and its custom properties available and ready to consume
  • If a theme can opt-out of the default core palette, it will ( at least I probably would ), which again becomes a problem if people are searching for patterns in the pattern directory and the theme they're using has opted out of the default core palette
  • theme/pattern/plugin users can rest easy knowing their chosen colors will persist

leeshadle avatar Jul 06 '21 23:07 leeshadle

I do like the idea of cornerstones of colours you can count on across all themes. Background and foreground make sense to me as meaningful terms. Whatever naming appending numbers seems a slippery slope, so avoiding that seems great to me.

What I find problematic actually is the use of primary/secondary and other words that tend to mean less - but that might be because I really want my theme.json right now to read like a recipe, not code. I don’t know if this is going to change for me with time and a personal feeling. Accent also feels strange to me as a term, accent to what? If we settle on some core fixed words, we have to think about translation, their comprehension, meaning and implications. All very doable as this process happens.

I really am intrigued by the light/dark append @richtabor suggested, which reminds me of the approaches in various preprocessors. I think that is also needed to get around some block and pattern issues I think anyone who has played with this for even a short while has encountered now.

karmatosed avatar Jul 07 '21 09:07 karmatosed

Over the years I have found that primary, secondary, accent etc are usually opinionated colors and not always suitable for text or backgrounds of large areas. I agree with the suggestion above, background and foreground (or more appropriately text, since foreground can be perceived as a 2ndary background color which is more on the forground) should be required. Required: background, text. Optional: Everything else.

I have a black&white theme for example, where primary, secondary, accent etc don't make any sense... Background & text will always make sense no matter the theme or context. And they also have the additional benefit that they open the door to dark-mode as well. It's a lot easier to flip background & text colors when we know what they are, and that they will be some reasonable, high-contrast colors that can work.

aristath avatar Jul 07 '21 09:07 aristath

I've been playing around with the Automattic theme.json supported themes and across a few other points. BlockBase, Seedlot Blocks, and Blank Canvas all have primary, secondary, background, and foreground colors added. Quadrat does not, but perhaps it will (or should).

We ended up iterating on Quadrat and going the semantic route as well. I feel like themes need to use semantic colors if they want their users to be able to customize their site's colors in a comprehensive way. Having a "blue" color defined makes little sense when the user goes to the Global Styles panel and changes its value to a red color. Changing a "background" color from blue to red does mean something instead.

In the end, it all boils down to how the user is going to customize their site and a theme providing a color is not useful for that, but a color that is common to certain blocks or elements to the site. What those are named it would be interesting to discuss. I think that since the editor is already providing the ability to change the background and text color, those colors should exist as variables too, and be able to be assigned to other places by the theme (and the user). And then if the theme needs to add extra semantic colors (be it secondary, foreground, accent, or whatever you name it) then that could be a theme decision.

MaggieCabrera avatar Jul 07 '21 09:07 MaggieCabrera

I have a black&white theme for example, where primary, secondary, accent etc don't make any sense...

@aristath This does not land for me. I think that monochromatic grays can easily be assigned to primary, secondary and accent, which reinforces the naming convention as a sound choice.

I definitely lean towards non-semantic color naming (e.g. seaside-blue) when developing a theme. But, I'm now seeing the more significant consideration of the user who would be interacting with the Global Styles UI in WP Admin. In this case, I think that primary, secondary, and accent strike a common ground.

I agree that a set of semantic color variables should be required within themes (and theme.json).

I also agree with @richtabor note on some sort of light/dark variables are necessary.

I think this might be a good required palette:

  • --primary
  • --secondary
  • --accent
  • --light
  • --dark
  • --text (foreground)
  • --background

I think it would be a great polishing feature to put some checks in place in the WP Admin UI for contrast validation (likely similar to what exists in color picker UI for blocks) for --light vs --dark and --text vs --background.

I think that --light vs --dark and --text vs --background will often get assigned the same values by developers, but would like to see them nonetheless.

Also, I wanted to note that I would love to see the ability for a theme.json color palette to contain a duplicate color, which I think would be necessary for allowing theme developers to reuse color variables and names.

I'm currently working on my first theme.json theme and it is for a client that has several brands, which requires several palettes. While this would be more ideal for a child theme or even Multisite scenario, but it is not part of requirements. Therefore, I have about 20-25 colors in palette and some I would like to reuse, but theme.json fails if you try to reuse same hex color for multiple keys with unique slugs.

However, this is a separate issue for implementers to overcome and should not hold up progress on this color discussion.

colorful-tones avatar Jul 07 '21 11:07 colorful-tones