This is a followup from #3086514: Investigate use of the changing color themes for Olivero.
We want to implement color changing themes within Olivero
Olivero currently has a single blue theme (along with gray colors). We want the user to be able to change this to support their specific branding.
Plan
- This will be done through the use of theme settings to set CSS variables.
- Within #3217924: Olivero: Convert all colors (blues and grays) to HSL and normalize hues and saturations. , we will convert all of the colors to HSL format.
- We will then consolidate and rename the colors within #3217926: Olivero: Rename and consolidate all color CSS variable names.
Theme settings UX
- The site builder will navigate to the theme settings page
- Will have an option to either 1) Select color via color picker or 2) paste in a hex value
- The hex value will be saved to config
- config value will be pulled in and processed by PHP to determine hue
- Hue will then be output as CSS custom property, which will then be utilized by the CSS.
Why not use the color module?
The color module (currently) injects values directly into CSS, and is unworkable with CSS variables and the implementation that Olivero is aiming for.
Olivero’s implementation
Olivero will save a single string to config (the hex value). The interface within the theme settings will be made accessible by adding a input[type=”color] that will be kept in sync with the default input[type=”text”] that’s provided from the Form API.
Within preprocess, we extract this string, and parse it with PHP to generate the hue and saturation. These values are injected into the HTML as CSS variables. These variables, in turn, are used to generate the entire color palette.
Why not update the color module?
This is possible, but not within this theme. The Olivero theme is experimenting with these settings, and abstracting out the code with an eye toward inclusion in a new version of the color module. If and when this happens, we will provide an upgrade path.
Followup issues
- Provide accessibility contrast feedback when selecting colors
- Implement secondary color option when allowing users to select Olivero color scheme
| Comment | File | Size | Author |
|---|---|---|---|
| #64 | olivero-color-scheme-voice-over.mp4 | 1.86 MB | mherchel |
| #43 | Olivero___Olivero.png | 83.32 KB | mherchel |
| #40 | image.png | 50.13 KB | mherchel |
| #26 | Screen_Shot_2022-02-02_at_8_13_21_AM.png | 280.9 KB | mherchel |
| #23 | drops.png | 408.44 KB | andy-blum |
Issue fork drupal-3257274
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3257274-implement-color-changing
changes, plain diff MR !1623
Comments
Comment #3
mherchel@andy-blum posted an initial patch for this at https://www.drupal.org/project/drupal/issues/3086514#comment-14347541 within the parent issue.
Comment #4
andy-blumIn the patch @mherchel references in #3, all we did was add a number input to allow users to select a hue that we could inject to the CSS custom properties.
In the current issue fork, I'm working on a way to take a hex code from a color input and convert it to HSL to pass all three values into the CSS. Per this comment, the HTML5 color picker isn't accessible enough to meet accessibility maintainer sign-off. After a looking around at different color picker libraries, the main two issues we continually run into is they either require jQuery (because they were written before HTML5 introduced input[type=color]), or they themselves have a fair number of accessibility concerns.
Per a slack conversation with @bnjmnm:
@andy-blum, 2022-01-07 9:02am:
@bnjmnm, 2022-01-07 9:07am:
With tentative approval, I'm going to move forward on mimicking the design & functionality of hslpicker.com
Comment #6
mherchelWent through the code without actually trying it out. Left comments in the MR. This is looking great so far!
Comment #7
mherchelUpdating the summary to reflect @andy-blum's approach.
Comment #8
andy-blum@mherchel I've addressed your feedback as well as made some additional changes for accessibility. Would love to see @bnjmnm's opinion on the UX as a potential farbtastic replacement
Comment #9
mherchelAdded some minor requests.
We also need the ability to revert back to the default, and with that, it'd be nice to have some options for default (accessible) colors.
Can you create an option to have some default colors (you can pick them out, and we'll have @jwitkowski79 and @jponch change or approve), and add that?
Thanks!
Comment #10
mherchelOn tugboat in the standard profile, I'm getting the following PHP errors. Not sure if this is your code (don't have time to look deep into it)
Comment #11
andy-blumComment #12
andy-blumComment #13
andy-blumComment #14
mherchelMore thorough review incoming, but the reason this is currently failing is:
Comment #15
mherchelLooks like the final compiled JS was not committed. Will compile it and continue the review later tonight.
Comment #16
andy-blumComment #17
andy-blumComment #18
andy-blumFinally passed the tests!
Comment #21
mherchelThis is looking so great!
Some additional feedback (with images)
1. The icon that appears in maintenance mode should change too
2. The overlay color should be changed to a transparent black.
3. When setting the color scheme to "ice", I see the hue is set to
190.99. This should probably be rounded.Comment #22
mherchelNeeds tests. I can work on these if needed.
Comment #23
andy-blum@mherchel do we want to adjust the hue of the "drops" background?
Comment #24
andy-blumComment #25
andy-blumUpdated to use --color--primary variables. Also changed how the lightness calculation is done to prevent clipping. The previous method had the potential for colors to try to use lightness values over 100. The new calculation does not.
Comment #26
mherchelAt line 116 in
oliveroColorTest.js, we're getting the following PHP error:Comment #27
mherchelSo the problem is that there's a check to ensure that the theme settings are in the
olivero.schema.ymlfile. And thecolor_schemeis missing (https://git.drupalcode.org/project/drupal/-/merge_requests/1623/diffs#c0...)So, we have a choice:
<select>via JavaScript, since it doesn't really do anything unless JavaScript is enabled.Thoughts?
Comment #28
andy-blumMoved the element to JS.
Comment #29
andy-blumtheme_get_setting()is deprecated. We should move to using the theme manager specified in the change recordComment #30
andy-blumDisregard the above. theme_get_setting() will eventually be deprecated but it seems to be blocked at the moment.
Comment #31
andy-blum10.0.x chromedriver got updated. Re-queuing tests!
Comment #32
tim.plunkettInstead of the approach in abdea896, you should be able to add
'#input' => FALSE,to that form element.Comment #33
xjmI apologize in advance; I'm about to push a merge of HEAD because rebase has too many conflicts...
Comment #34
xjmPhew, no explosions. :)
Comment #35
xjmJust to validate the merge, this is the current diffstat from 10.0.x:
Comment #36
andy-blumNow that #3257274: Implement color changing theme settings for Olivero is fixed, re-queuing tests.
Comment #37
mherchelWe're getting a failure on
Comment #38
andy-blumTurns out the chromedriver wasn't fully fixed. Should be happening soon though and we can re test
Comment #39
mherchelcolor-picker.js needed to be recompiled too.
Comment #40
mherchelThis is looking so good!
In addition to the MR comments above, there's two more:
1) We should nest the two new form fields in a fieldset to visually (and semantically) indicate that they are related.
2) We need to validate the hex string server-side. If I remove the
patternattribute from the input, it allows me to submit invalid colors. This then throws an error on the front-end when it tries to parse it.Comment #41
andy-blumMost recent changes appear to be working just fine, see the tugboat preview for a working example.
We still need to add the backend validation for the hexcode.
Comment #42
andy-blumComment #43
mherchelThis is so close!
A couple changes:
1) We need to modify the
.header-nav-overlayCSS class incore/themes/olivero/css/components/header-navigation.pcss.cssto make the background transparent black. Currently the MR is adding a new CSS class inbase.pcss.css(which we recently refactored out). We need to remove that from the MR.2) If you have Olivero up and running and apply the patch, the config does not exist. This makes the form look incorrect.
We probably need to add an update hook to add the config. We might be able to get away with seeing if the config exists -- and if it doesn't then load the default blue value. I'm not sure what's best practice.
Comment #44
andy-blumComment #45
mherchelI asked in the #contribute channel, and this was the response from @alexpott (among others)
Comment #46
mherchelAnother update from the same Slack thread (with a workaround that unblocks us).
From @berdir
From @alexpott
Comment #47
shaalThis is so cool :) I tested it with DrupalPod.
Click here to open branch 3257274-implement-color-changing in DrupalPod
Comment #48
andy-blumFor the sake of clarity, the solution described in #46 is to use hook_post_update_NAME() within system.post_update.php.
I'm working to add this in now.
Comment #49
andy-blumComment #50
andy-blumLooks like the inputs don't stay synchronized correctly now that we've changed the HTMLColorInput's name attribute. Also causing the test failures below:
Comment #51
mherchelUpdating the summary to add discussion regarding the color module.
Comment #52
mherchelComment #53
andy-blumComment #54
andy-blumComment #55
mherchelWe discussed this issue at #3267550: Drupal Usability Meeting 2022-03-11 that issue will have a link to the recording.
The key points are
Comment #57
andy-blumComment #58
mglamanFixed @andy-blum feedback on my last commit which added unit test for the HEX -> HSL conversion. Pushing this back to Needs Review and removing Needs Tests flag.
Comment #59
mherchelThis MR is a thing of beauty. I can't think of anything else. It works well, is robust, and is well tested.
**Chef's Kiss**
Comment #60
benjifisherFor the record, the participants at the usability meeting (see #55 for a link) were
AaronMcHale, andregp, Antoniya, ckrina, mherchel, shaal, rkoller, tmaiochi, worldlinemine, andy-blum
Comment #61
andy-blumDiscussed with Mike Gifford to get feedback on accessibility, and there are 2 primary takeaways.
Comment #62
mgiffordThanks @andy-blum - thanks for summarizing our conversation.
Comment #63
andy-blumComment #64
mherchelThis last change looks perfect. The text is announcing on every change now. Video with VoiceOver attached.
At this point we have sign offs from both the UX and accessibility teams!
Comment #72
xjmAdding credit for UX review participants. Thank you all!
Comment #73
alexpottI posted some comments in gitlab that need addressing.
Comment #74
mherchelComments from @alexpott in Drupal Slack (https://drupal.slack.com/archives/C1BMUQ9U6/p1648555120415739)
alexpott 4 minutes ago
It’s tricky - determining the same value from a constant every request is unnecessary work. The caching for preprocess_html is the page cache :slightly_smiling_face:
alexpott 3 minutes ago
As stated in the comment I think changing the config to an hsl value means we need to convert back to #hex value - which seems awkward so lets not.
alexpott 2 minutes ago
So we need to remove the if because it is unnecessary - the value is always set. And the we need to fix the schema to use the correct type.
mherchel 1 minute ago
gotcha! Thanks for the clarification!
New
alexpott < 1 minute ago
I left the thoughts on storing the HSL values in case someone thought - “oh I know how that could work”
Comment #75
andy-blumComment #76
mherchelChanges look perfect. I eyeball'ed the code one last time and it looks good. I also tested out the upgrade script, etc, and made sure that works as expected. Everything looks great. Thanks for the work on this!
Comment #77
mherchelCreated followup #3275990: Create theme function for dynamically inserted (via JS) form elements within Olivero's color changing form
Comment #78
lauriiiHave we tried the proposed approach from #32 for generating the form input? That would allow us to avoid the problems we would have to resolve in #77.
Comment #79
mherchelComment #80
andy-blumMost recent push should satisfy @tim.plunkett in #32 and @laurii in #78, as well as nullify @mherchel's spin off issue #3275990: Create theme function for dynamically inserted (via JS) form elements within Olivero's color changing form.
The tests here are going to fail, as we are now utilizing the ThemeColorsParser class as created in patch #38 in #788332: Provide a parser for THEME.colors.yml, but I'm excited about this as a more human-readable solution and one that more clearly outlines the direction of a hypothetical color module replacement.
Comment #81
andy-blumComment #82
alexpottI've split out the fix to theme update function registry that this issue found - see #3279850: Theme post updates are not recognised when the theme is used in the installer
Comment #83
andy-blumAll the PHP tests are passing now, so that's good! Looks like I forgot to update the nightwatch tests though after changing the form element markup, so back to needs work.
Comment #84
andy-blumComment #85
mherchelOpened #3280398: Theme's post updates within update.php refer to themes as "module"
Comment #86
mherchelThis looks amazing! I tested out the update functionality (and opened the followup in #85). I also reviewed the latest commits since my last review, and that looks good. Finally, I tested out the functionality and was unsuccessful in my attempts to break it.
Amazing work everyone!
Comment #87
andy-blumDisregard php7.3 tests. This is D10 only
Comment #88
lauriiiCommitted ce2f2b5 and pushed to 10.0.x. Thanks!
Comment #92
thulenb commentedWill this also be available for D9?
Comment #93
mherchelNope 😭 It relies on CSS variables. D9 has a commitment to support IE11 (which does not support CSS variables).
Comment #94
thulenb commentedUnderstand, thanks.
So I tried to do this with a subtheme of Olivero. Is there any other way to build css besides using Yarn. My hosting provider just told me that I can’t use it. How can I build CSS in order to get my color changes active?
Comment #95
thulenb commentedUnderstand, thanks.
So I tried to do this with a subtheme of Olivero. Is there any other way to build css besides using Yarn. My hosting provider just told me that I can’t use it. How can I build CSS in order to get my color changes active?