Offshoot from #3064880: Create new default front-end theme

Summary

There is a need to be able to change the default colors of the Olivero theme. Traditionally, this could be done through the Color Module, however, there is an issue to remove this module from core. See #2808151: [policy] Move the Color module to a contributed project when Bartik is deprecated.

If we did not have to support IE11, we could just change the color values in the custom CSS properties that we will have defined. However, these variables get processed down to old-style CSS via PostCSS to remain compatible with IE11.

Options

So, we have a couple options:

1) Support the Color module. I honestly do not know what's involved. I'm assuming we'll have to know every.single.css.selector that uses a color?
2) Remove the PostCSS transpilation and use https://www.npmjs.com/package/css-vars-ponyfill to handle IE11 compatibility. According to @laurii in https://www.drupal.org/project/ideas/issues/3064880#comment-13284844, this can be hosted on Drupal.org. I'm personally concerned about a flash of unstyled content, though.
3) ??

Dark theme

It would be nice to have two options. One for a normal theme, and one for dark that would be activated by media-query!

Timeline

This will not be a requirement for MVP, but I'm also not opposed to adding this functionality (and would like to do so).

Comments

mherchel created an issue. See original summary.

mherchel’s picture

chrisfromredfin’s picture

The one thing I can say about the color module is that it basically does a find and replace of #abc123 with the new color you've chosen, in a CSS file, then it writes that CSS file into public files folder, and adds it at the end of the cascade.

So, to support color module, a "base" CSS file needs to exist that defines all the 'colorable' portions of the theme that serves as overrides to what the default CSS is.

naheemsays’s picture

CSS Variables need to be investigated as a better way of implementing this.

It should also allow all themeable colours to be included in a single themeable stylesheet.

mherchel’s picture

Title: Investigate use of the color module for Olivero » Investigate use of the changing color themes for Olivero
Issue summary: View changes
anruether’s picture

We now have a working color successor candidate based on css variables, see #3090894: Replace color module with a CSS-Variables based module to provide configurable theme parameters.

> I'm personally concerned about a flash of unstyled content, though.

We integrated the mentioned ponyfill library and indeed in ie11 on my machine I see the flash. This could be worked around by #3090875: Add a server side css variables replacer (for JS-less IE11).

Also cssvars is domain config compatible.

anruether’s picture

> I'm personally concerned about a flash of unstyled content, though.

An addition to this: The flicker did improve/disappear once I changed the JS that triggers the ponyfill to this:

(function ($, Drupal, cssVars) {
  'use strict';

  Drupal.behaviors.cssvars_polyfill = {
    attach: function(context, settings) {
      cssVars();
    }
  };

}(jQuery, Drupal, cssVars));

(Effectively removing the curly brackets from within the cssVars function, compare https://git.drupalcode.org/project/cssvars/blob/8.x-1.x/polyfill/run-css... This is possible as long as no ponyfill options are needed)

geek-merlin’s picture

@anruether: Thanks a lot for your investigations in this! Let's discuss this more in the project queue and upstream.

shaal’s picture

Few ideas, that I was discussing with @mherchel during Florida Drupalcamp:

Allow modern browsers use regular CSS (with vars), but then add special files (ie. ie11-color.css, ie11-fixes.css, etc) to deal with IE11 specific issues while allowing take advantage of latest and greatest features in modern browsers.

Inspired by the ideas shown here (and seems like a simple implementation):
https://dev.to/ananyaneogi/create-a-dark-light-mode-switch-with-css-vari...

Add additional special vars

:root {
    --primary-color: #302AE6;
    --secondary-color: #536390;
    --font-color: #424242;
    --bg-color: #fff;
    --heading-color: #292922;
}

[data-theme="dark"] {
    --primary-color: #9A97F3;
    --secondary-color: #818cab;
    --font-color: #e1e1ff;
    --bg-color: #161625;
    --heading-color: #818cab;
}    --heading-color: #292922;

That will make it easy to add a toggle button and/or use prefers-color-scheme.

Additional interesting ideas we can use can be found here:
https://web.dev/prefers-color-scheme

pingwin4eg’s picture

Reviewing the #2808151: [policy] Move the Color module to a contributed project when Bartik is deprecated I can say that the decision on removing the Color module from core heavily depends on whether the new FE theme is going to use it or not. So I guess if the Olivero actually needs the Color, it will stay in core.

andrewmacpherson’s picture

OK, so let's look at some other questions:

  • Which elements in Olivero will be re-colourable? I'm guessing that will probably be "all the blue things", and we're offering a choice of accent colours instead of blue. Maybe a choice of footer background. Any other schemes?
  • How many colour schemes do we want? If we follow Bartik's lead those might be: blue, purple, red, green, grey. Or we could have different ones to Bartik... burgundy, pink, burnt orange. I am not a designer.

It would be nice to have two options. One for a normal theme, and one for dark that would be activated by media-query!

I think support for the prefers-color-scheme media feature is a separate concern, which color module isn't really suited for (in it's current form). Instead, I think there could be a theme setting: dark, light, or respect the user's preference. I'm thinking of the way macOS treats light/dark and accent colour as separate settings. So the site builder could say "red accent scheme, on light background" or "green accent scheme, and respect the visitor's user preference for light/dark mode". If color module is disabled, blue is the only accent colour, but the light/dark functionality is still there.

mherchel’s picture

Status: Active » Postponed
mherchel’s picture

Version: » 8.x-1.0-alpha1

Another CSS polyfill that might work better: https://github.com/nuxodin/ie11CustomProperties

trebormc’s picture

I add another related issue. We have to have all the colors as variables if we want to be able to change them easily.

https://www.drupal.org/project/olivero/issues/3151405

kostyashupenko’s picture

Assigned: Unassigned » kostyashupenko
kostyashupenko’s picture

1. As @jhodgdon said we have at least ~2 years to go with color module
2. I was thinking about how we can deal with it, to easily switch the colours, so i have implemented actually the same thing we use already ~1 year in my Skilld company, let me explain:

I see no reason to go with postcss-custom-properties plugin anymore, instead we have to use css-vars-ponyfill

Globally idea here is to have css variables in the compiled css. I know it doesn't work in IE, that's why css-vars-ponyfill will help here.

3. I added colours implementation to Olivero, check color/ folder in the root. With proper configuration on this page /admin/appearance/settings/olivero we will have this one:
Color Olivero
The list of all colours used within the theme. Note that these colours are not really good to me in terms of its names, it should be changed, but it is not really important for this task. This task is an idea what we can do with colours

4. The next thing is a preview with the ability to change colours on the fly. I have added some elements from header and some little js to change colours if you going to edit it, look how it looks if i'll change some:
Color Olivero

By default these colours were blue, but when i have changed it on this page - it was immediately have changed with the little js script, which is defined here color/preview.js. Also you can see that "Olivero" word becomes blue, it's because i have changed white color by #00e. Sooo.. we can easily put all needed elements to this preview to see visually the difference if colours will be changed (can be form elements, buttons, footer, text, etc).

5. One more thing - all colours were moved from css/src/base/variables.css to color/colors.css - this is necessary for color module to move it into standalone file.

6. All @import "../base/variables.css"; from all components were removed, coz we don't need to import variables anymore, see the 2nd point (we have now all variables in generated css).

Everything works fine, even in IE11, look at left corner, i have change blue color by violet:
Color module

You can change any color from this page /admin/appearance/settings/olivero and it will be applied automatically everywhere, where this color was used in css. (Thanks again to css-vars-ponyfill)

7. I didnt find how i can put css-vars-ponyfill into the theme, so i have copied its sources to js/css-vars-ponyfill.js. Note that this is temporary fix, just for you guys to test / to understand how it feels

Idea of this patch is to forget about IE11 problems about not supported css variables in generated files - it's working fine with css-vars-ponyfill. I'm insist we can update core with that idea and all core themes.

Css variables everywhere :)
color module

mherchel’s picture

This is good work. I created a tugboat preview at https://3086514-change-colors-isvama9kcodb9xfnhynthqpmqnntdche.tugboat.qa/.

Note that within IE11, there is a flash of unstyled content. Video at https://www.youtube.com/watch?v=l48kNWriuhc

geek-merlin’s picture

> Note that within IE11, there is a flash of unstyled content.

Maybe the on efrom #13 performs better wrt this.

mherchel’s picture

kostyashupenko’s picture

Yes @mherchel, i saw these 2 issues, what i can say is the following:
1. For wrong calc cases i would say we can just adapt those variables, look at here how it is done right now, just an ex:

 --grid-gap--nav: var(--grid-gap--md);
--grid-col-width--nav: calc((var(--grid-full-width--nav) - (var(--grid-gap-count--nav) * var(--grid-gap--nav))) / var(--grid-col-count--nav));

 left: calc(-1 * ((var(--grid-col-width--nav) + var(--grid-gap--nav))));

So what i'm trying to say is that there are nested calc functions inside of another calc. It is normal behavior looks like for IE11 when he can't recognize it properly. That means we need to fix nested calcs.

2. About short moment before ponyfill gets working - yep, looks not really good, but this is how it's working. Maybe we can hide whole content by default for IE? And to show it right after ponyfill has finished his job. Or actually is it really an issue for us?

karing’s picture

Tuning in! We colour Olivero into an organization's primary colour - always. It's do-able with a lot of css overrides (packaged into a subtheme). It would be great to have a configuration option for it. Happy to help test any solutions.

mherchel’s picture

Project: Olivero » Drupal core
Version: 8.x-1.0-alpha1 » 9.1.x-dev
Component: Code » Olivero theme
Status: Needs review » Postponed

Postponing for now. My initial thought is that if we didn't have to support IE11, this would be trivial. This isn't a stable blocker, so it's low priority for now.

bwoods’s picture

I was eager to try out the patch in #17, but it doesn't seem to apply to 9.1.4. Any tips on which version of core I should use?

mherchel’s picture

The patch in #17 was made against the contrib version of Olivero (before it was added to core). There hasn't been much if any work on this since.

Our first goal is to get to stable and make Olivero the default. After that, this will be one of the very top priorities.

bwoods’s picture

Thanks for the update, Mike. Looking forward to seeing and testing the stable version.

dqd’s picture

Our first goal is to get to stable and make Olivero the default. After that, this will be one of the very top priorities.

@mherchel would you mind to link to a roadmap or issue or META where this progress is documented, if it is somewhere? It would be helpful.

mherchel’s picture

The issue to make Olivero stable is at #3177296: [META] Make Olivero stable.

As far as issues for changing color, this issue is it :)

dqd’s picture

Oh no it's fine here :-) (for color)

The issue to make Olivero stable is at #3177296: [META] Make Olivero stable and the default theme for Drupal.

That's what I was referring to. Thanks! +1 (Didn't found it)

Reference: I'll wanted to put the META as related Parent in here to make the reasons for postponed clearer, but I saw #3064880: Create new default front-end theme has been chosen as Parent to this one. So I just left it as it is to not confuse things. EDIT: Wait, the other one is closed (fixed). Ok then, so let's do it? Feel free to change it if it doesn't fit.

dqd’s picture

andypost’s picture

Version: 9.1.x-dev » 9.3.x-dev
Status: Postponed » Active
Related issues: +#1651344: Use color input type in the color.module

It looks actionable now

kattekrab’s picture

Wow - Olivero is amazing. I love it! A huge thank you and karma to everyone involved. It's so impressive!

I've just enabled it in an experimental project and was trying to figure out how to change colours like we could do with good 'ol bartik, and ended up here. So a +1 from me this is an important feature for a default theme, so that site builders can easily tweak colours, without having to become themers or developers.

mherchel’s picture

Thanks for the positive feedback! 😊

Yes, this will likely be the very top priority for Drupal 10 after becoming the stable and default.

longwave’s picture

+1 to this feature as well.

https://github.com/nuxodin/ie11CustomProperties/issues/54 suggests the CPU issue may be fixed in the polyfill in the latest release, has this been tested? If this is acceptable I think this can be worked on in D9 - if this is still no use then this issue will have to be postponed until Drupal 10 as unfortunately we need to support IE11 until then.

ressa’s picture

This would be an awesome feature, complementing #3214072: Provide an Olivero sub-theme creation tool perfectly, to easily create a unique looking theme with minimal effort.

dqd’s picture

@ressa: +1

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mherchel’s picture

After talking with @lauriii, I'd like to get some clarification from the core Product Managers on if we

1) Need to refactor and use the Color module for this functionality
2) Can build this functionality using theme settings

I'm hoping the answer is that we can build this into the theme settings. If we have to rebuild the color module, the work will be stalled as we wait for backend devs to work on this (we don't have the available backend chops within the Olivero team). However, if we can go the route of doing it in a theme setting, we can likely get this in by 10.0.0, which would be super cool.

andy-blum’s picture

Version: 9.4.x-dev » 10.0.x-dev
Status: Active » Needs review
StatusFileSize
new16.59 KB
new54.33 KB
new149.5 KB
new149.05 KB

Attached is a patch that makes use of the most recent patch in #3217924: Olivero: Convert all colors (blues and grays) to HSL and normalize hues and saturations. . A new number input has been added to the theme setting to allow users to select the base hue value from which Olivero will derive all theme colors. I originally planned to use a color input for this, but decided against it to prevent confusion when as we'd only be utilizing the hue value. This prevents users from selecting different saturation/lightness values of the same color but ultimately getting the same result in the Olivero theme.

browser color selectors all choosing different shades of red but all sharing the same hue value in HSL notation

Instead, there's now a number input with a step of 0.1 to allow fine-grained control and tweaking of the hue value. To make it easier for users to see the color they're selecting, the number input also has a #suffix that places a span tag that we're styling with a new library in olivero. On load, the span tag picks up the default value, and as the hue selector input changes, the span updates to always show the background color as the most-saturated, and half-lightness version of that hue hsl([value], 100%, 50%)

pair of images showing the theme settings selecting 202 for the hue value, and the olivero theme displaying in shades of blue

pair of images showing the theme settings selecting 40 for the hue value, and the olivero theme displaying in shades of orange

gábor hojtsy’s picture

Re @mherchel in #38: rather than answering whether Color module should be used or not it would be good what's the vision/idea in terms of what kind of color customization would you want to allow practically? The feature gap between #39 and #17 is huge and #39 is actually more appealing in terms of colors working together but appears having a sub-par UX in terms of needing to specify what may appear random numbers for an audience that does not have color theory experience. Either way both are in my understanding proof of concepts, but it would be better IMHO to agree on a direction of what is to be customizable. THEN we can talk about how IMHO :D

karing’s picture

Not sure if this is helpful here, but below are two examples of the kind of color customization that we're currently doing for clients to bring in their primary + secondary colours into Olivero -> menu items, links, buttons, etc.

Example

Example 2

karing’s picture

StatusFileSize
new1.94 MB

PS -> also for mobile menu -> that's the primary colour (not olivero/drupal blue):

Example 3

mherchel’s picture

from @Gábor Hojtsy

Re @mherchel in #38: rather than answering whether Color module should be used or not it would be good what's the vision/idea in terms of what kind of color customization would you want to allow practically? The feature gap between #39 and #17 is huge and #39 is actually more appealing in terms of colors working together but appears having a sub-par UX in terms of needing to specify what may appear random numbers for an audience that does not have color theory experience. Either way both are in my understanding proof of concepts, but it would be better IMHO to agree on a direction of what is to be customizable. THEN we can talk about how IMHO :D

Thanks for the feedback. Agree on all points.

My preference is to use an approach similar to @andy-blum in #39, however with a standard color picker (and use JS to extract the hue and then save to config)

So, in a perfect world, Olivero:

  1. All colors would be HSL
  2. User would select color via color picker
  3. JS will save hue to config
  4. Config will be output to CSS custom property
  5. All colors' "shades" would be relative and look proper.
  6. We'd also have several pre-defined color palettes that could be used.
  7. Possible followup: provide live a11y contrast feedback when doing color selection.

This is my goal and I doubt that this can work in the confines of a (new) color module. Let me know if this makes sense.

gábor hojtsy’s picture

If we are to only pick one color and use browser-native widgets for it (don't build a parallel color module), then in my humbe opinion doing it custom to Olivero is fine.

mherchel’s picture

I had an additional conversation w @Gábor Hojtsy at https://drupal.slack.com/archives/CJT807H7T/p1641307912149300

Transcript:

mherchel 9:51 AM

@Gábor Hojtsy (he/him) thanks for the feedback on https://www.drupal.org/project/drupal/issues/3086514#comment-14356511! Questions:
You say "in my humble opinion" - does this count as product manager sign off? Or should I get further input?
You also say "one color"... literally just 10 min ago @KarinG was talking to me about adding a secondary color. That being said, I'm envisioning more of a system that's custom tailored to Olivero where it picks derivative colors based on the user's choice(s) within the color picker. Assuming we do this the way I'm thinking (which IMO would provide the best UX and options), I'm not sure it'd be easy to abstract this out. Thoughts on all of this?

Gábor Hojtsy (he/him) 2 days ago

I think its its a minimal color thing, then it should be fine in Olivero without color module :smile: So far it looks minimal. Depends on whether it stays like that.

mherchel’s picture

mherchel’s picture

Category: Feature request » Plan
Status: Needs review » Fixed
Issue tags: -Needs product manager review

Assigning credit and marking as fixed.

All subsequent work on this will be done in #3257274: Implement color changing theme settings for Olivero

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.