Skip to content
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

Make it easier to have different colors per tenant #5021

Merged
merged 10 commits into from
Nov 21, 2022
Merged

Conversation

javierm
Copy link
Member

@javierm javierm commented Oct 23, 2022

References

Objectives

  • Simplify the custom code necessary to have different colors per tenant

Notes

This code uses CSS variables, which means it will work on (as of October 2022) about 97% of the browsers. We're providing fallbacks so the other 3% of the browsers see the default colors instead. For single-tenant applications, we recommend using SCSS variables instead, which will work on 100% of the browsers and will allow using SCSS functions like lighten or darken.

With this pull request, the main header, top links, subnavigation, footer, links and brand/button colors can be customized using CSS variables.

@javierm javierm self-assigned this Oct 23, 2022
@javierm javierm added this to Doing in Consul Democracy Oct 23, 2022
@javierm javierm changed the base branch from master to multitenancy October 23, 2022 17:37
@javierm javierm changed the base branch from multitenancy to unify_color_variables October 23, 2022 17:38
config/sitemap.rb Outdated Show resolved Hide resolved
@javierm javierm force-pushed the unify_color_variables branch 6 times, most recently from 2ea4dde to 42caf03 Compare October 27, 2022 13:18
@taitus taitus added the 1.6.0 label Oct 28, 2022
Base automatically changed from unify_color_variables to master October 28, 2022 12:44
@javierm javierm changed the base branch from master to multitenancy October 28, 2022 12:46
@javierm javierm force-pushed the tenant_colors branch 2 times, most recently from 51da408 to 7f99331 Compare October 28, 2022 19:19
@javierm javierm force-pushed the multitenancy branch 4 times, most recently from 4ca56a1 to e38b860 Compare November 19, 2022 16:49
Base automatically changed from multitenancy to master November 19, 2022 17:07
@javierm javierm force-pushed the tenant_colors branch 2 times, most recently from 44181d8 to d6b76b1 Compare November 19, 2022 23:28
Until now, we didn't have specific variables for the headers and were
using the brand colors instead. Now we maintain the brand colors as
default values, but allow overwriting them.

For the navigation and footer, we didn't even have variables.
So now inverting the selection for brand-secondary backgrounds will
depend on the value of brand-secondary.
We don't need the color parameter anymore since we can now use a more
generic mixin for any background, like brand-secondary.
This is consistent with the `body-colors` mixin and with other mixins
we're about to add, like `anchor-color`.
Until now, overwriting the styles for a certain tenant was a very
tedious task. For example, if we wanted to use a different brand color
for a tenant, we had to manually overwrite the styles for every element
using that color.

It isn't possible to use different SCSS variables per tenant unless we
generate a different stylesheet per tenant. However, doing so would make
the CSS compilation take way too long on installations with more than a
couple of tenants, and it wouldn't allow to get the colors dynamically
from the database, which we intend to support in the future.

So we're using CSS variables instead. These variables are supported by
97% of the browsers (as of October 2022), and for the other 3% of the
browsers we're using the default colors (SCSS variables) instead.

CSS variables have some limitations: for instance, it isn't possible to
use functions like `lighten`, `darken` or `scale-color` with CSS
variables, so the application might behave in a strange way when we use
these functions.

It also isn't possible to automatically get whether black or white text
makes a better contrast with a certain background color. To overcome
this limitation, we're providing variables ending with `-contrast`. For
instance, since the default `$brand` color is a dark one, when assigning
a light color to `--brand`, we probably want to assign
`--brand-contrast: #{$black}` as well, so the text is still readable.
Just like we did with SCSS variables, we use the `--main-header` CSS
variable and, if it isn't defined, we use the `--brand` CSS variable
instead.

Note that we're still using the `inverted-selection` mixin based on the
default `$main-header` color, so it's possible that we get the inverted
selection in the main header when using a dark color with `$main-header`
but a light color with `--main-header`, which doesn't make much sense.
Not sure whether there's anything we can do about it.
Just like we did with SCSS variables, we use the --anchor-color CSS
variable and, if it isn't defined, we use the --brand CSS variable
instead.
We were already doing the same for the main header color; now we also
make it easier to use different top links, subnavigation and footer
colors per tenant.

Just like we do with SCSS variables, we use the brand-secondary color
for the top links when the `--top-links` variable isn't defined.
@javierm javierm changed the base branch from master to revert_hollow_color November 19, 2022 23:32
Consul Democracy automation moved this from Reviewing to Testing Nov 21, 2022
Base automatically changed from revert_hollow_color to master November 21, 2022 17:42
@javierm javierm merged commit 662cc26 into master Nov 21, 2022
Consul Democracy automation moved this from Testing to Release 1.6.0 Nov 21, 2022
@javierm javierm deleted the tenant_colors branch November 21, 2022 18:01
@javierm javierm removed the 1.6 label Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants