Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Components: Add themeable background color #45466
Components: Add themeable background color #45466
Changes from 14 commits
0d392c9
64a2172
0c6a7fc
6d5977a
9b519d4
a9b184c
e6e12c6
8ebc4e5
ef37c95
b385609
4e91554
b6f567a
17986d4
2b74866
f2fab80
5db9b4b
90c4d51
48f50e6
9d63099
1fc450c
b490e41
e55e47e
a510318
6fd310e
64a27f3
f5f0d63
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three TODO comments in this stylesheet flag the parts that rely on Sass functions, which will not work when the underlying values are CSS variables.
There are two ways we can address these:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this would be my preferred option too — it would simplify the code and its readability too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand a bit on what the ask is here? Is it changing out of the main color?
I like to think that we can reach a point where we have a set of system colors with their known contrast properties in light and dark mode (the grays), and then provide a single accent color to a component, and whatever mode it's in defines what colors get applied. That is, ideally I should never have to feed more than a single color along with the dark or light mode prop to a component, and it handles the rest itself. Is that useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, I'm not asking for anything specific yet in this PR 🙂 We'll make follow-up PRs with more detail, suggest some alternatives, and ping the design team there for discussion.
As an overview of the problem though, we can no longer easily use Sass functions like this, which require the color to be predetermined:
gutenberg/packages/components/src/button/style.scss
Line 75 in 2b74866
☝️ This button's text color needs to be either white or black depending on the arbitrary accent color. But we can't use CSS variables as inputs to Sass functions. Things like
rgba(var(--my-color), 0.4)
are not possible.gutenberg/packages/components/src/button/style.scss
Lines 131 to 132 in 2b74866
gutenberg/packages/components/src/button/style.scss
Lines 246 to 252 in 2b74866
☝️ Similarly in these two examples, we can't do things like
lighten(var(--gray-700), 5%)
.I'm using the term "dark mode" for convenience, but we are currently working toward a more generic solution which allows consumers to pick their own background color. In theory this means any color, but in practice it means consumers should be able to choose their own shade of "dark" when doing "dark mode". An app may want
#0a0a0a
, another may want#1d1f21
, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, any reason why we don't generate a
gray-900
color?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the context of our color system,
gray-900
is always the same asforeground
. So it was redundant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these opacity values? Just curious on how the hex colors are calculated. This is cool stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are "darkness" values, i.e. the inverse of the Lightness value in HSL.
gray-100
#f0f0f0
ishsl(0, 0%, 94%)
(1 - 0.94 = 0.06, etc)gray-200
#e0e0e0
ishsl(0, 0%, 88%)
and so on...That said, we might eventually switch from HSL to LCH for internal calculations so the lightness differences are a bit more reliable than HSL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool, thank you! I like the sound of that, in the past I explored HSL for component theming, and the opportunities are pretty cool. That's not to say the approach I explored there is the right one — just that it's nice to be able to feed a single hue value, and have the rest refer to that.
Edit: Especially useful if it means we can retire light/dark versions of the spot color, so we have just a single spot color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently,
gray-100
could be the brightest or the darkest color in the scale of grays, depending on whether thebackground
color is classified as "dark" bycolord
.Could this cause confusion in the consumers of the theme? My experience as a developer has taught me that usually
100
is always associated to a brighter color, and900
to a darker.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an alternative for that problem specifically. Though, I'm expecting that most usages won't be using these gray colors directly, but instead through more semantically named variables (e.g.
border
,lightBorder
,secondaryText
, etc).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let's get a feeling for it and see if we need to make any adjustments (at most we could add a line to our docs ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next thing we should do is to take these
themeVariables
values and make them available to descendant components via Context. This will allow us to resolve the remaining TODO comments in Button, where Button needs to access the color values directly and compute its non-standard colors in JS.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a few considerations (almost a brainstorming sessions) that came to mind when thinking about using React Context:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After ruminating on this, I'll backtrack — we shouldn't use React Context in combination with the original DOM-based scoping system 😅 It would cause a lot of complications like you mention.
So I guess we really need to avoid Sass color functions as much as possible, and maybe consider exposing HSL-split CSS vars (
--h
--s
--l
) for things that are absolutely necessary 😕