-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(theme): Add new mdc-theme-on-primary global variable #2483
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2483 +/- ##
=======================================
Coverage 98.68% 98.68%
=======================================
Files 98 98
Lines 4194 4194
Branches 533 533
=======================================
Hits 4139 4139
Misses 55 55 Continue to review full report at Codecov.
|
packages/mdc-theme/_variables.scss
Outdated
@@ -23,11 +23,13 @@ | |||
// | |||
|
|||
$mdc-theme-primary: #6200ee !default; // baseline purple, 500 tone | |||
$mdc-theme-on-primary: #fff !default; |
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.
Shouldn't these still be computed based on $mdc-theme-primary
or $mdc-theme-secondary
?
i.e. these values should adjust to remain correct when the corresponding variable is changed, which we were doing before and should still easily be able to do by calling a mixin here.
Also, are we really doing away with semitransparent text OOTB? I thought that was in spec. I thought on-primary/secondary were additional slots, not replacing text?
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.
mdc-theme should not compute $mdc-theme-on-primary
based on $mdc-theme-primary
because then $mdc-theme-on-primary
is always white/black. Mdc-theme should allow users to customize $mdc-theme-on-primary
to any color, like the brown color used in the shrine example.
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.
Sorry if I worded poorly; my suggestion wouldn't prevent users from customizing it, it would just provide a sane default so that things don't get weird if you change e.g. primary and not on-primary.
We'd still have !default
at the end to allow overriding it.
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 cant actually figure how to build this functionality (without probably restructuring all our mixins in mdc-theme). I tried to do this
$mdc-theme-on-primary: #fff !default;
@if mdc-theme-contrast-tone($mdc-theme-primary) == "dark" {
$mdc-theme-on-primary: #000 !default;
}
and commented out the $mdc-theme-on-primary
in theme-shrine.scss
...but it keeps setting the -on-primary color the white
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.
That will fail because the earlier assignment will always happen, and then the latter one inside the if will never happen because !default
makes the assignment only happen if that variable doesn't already have an assigned value. This is the behavior that makes redefining our globals before loading our styles work.
http://sass-lang.com/documentation/file.SASS_REFERENCE.html#variable_defaults_default
There is an if
function that can be used akin to a ternary operator in other languages which you can use to set the value in one statement:
$mdc-theme-on-primary: if(mdc-theme-contrast-tone($mdc-theme-primary) == "dark", #000, #fff) !default;
Or, you can populate a map with light
and dark
entries and simply reference that with the value returned from contrast-tone. That is what the variables that you're replacing were already doing, which makes it hard for me to understand why we're removing the logic.
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.
How would users override the -on-primary with Sass without the changes in this PR?
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.
IIUC your point is right now it's impossible to directly override, say, text-primary-on-primary, which is true. If enabling that is the goal, then I can see why this PR is changing how the variables are defined, so they can each be directly overridden.
I was specifically concerned about the existing dark/light logic that was being taken out of the picture in the process of this change, and was a little confused since in this thread you seemed to be having trouble replicating the logic that already exists.
How many text color levels are we going to end up with after this is all done (compared to the current primary/secondary/hint/disabled/icon)? Would it be cleaner to reuse the existing functions that pick the defaults out of the mdc-theme-text-colors
map, versus writing ternaries with hard-coded values on every variable we declare?
Either way, we should be able to ensure sane behavior if someone doesn't touch the on-x variables, but does touch the primary/secondary values.
Removing the entries from the map causes CSS classes to no longer be generated here: Which causes regressions in demo pages that use Are we expecting to maintain classes for this as before (e.g. now we would have Here's an example of a regression, in the theme page (the 3rd and 4th buttons should have white text): |
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.
There are other existing references to text-...-on-primary
...
- demos/icon-toggle.html (uses CSS classes)
- demos/top-app-bar.html (uses CSS classes)
- demos/drawer/temporary-drawer.html (uses CSS classes)
- docs/theming.md (documents CSS classes and custom properties, and mentions it in prose and HTML/CSS examples)
- The grid-list README mentions that it uses
text-primary-on-primary
packages/mdc-theme/README.md
Outdated
> `$mdc-theme-secondary` instead. | ||
|
||
The text color, for text placed on top of these selected theme colors, is programmatically computed based on color contrast. We follow the Web Content Accessibility Guidelines 2.0. | ||
We suggest you follow the Web Content Accessibility Guidelines 2.0 we picking the values for on-primary, on-secondary, etc. These values should be accessible on top of the corresponding value, e.g. primary and secondar. |
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.
Typos:
"we picking" -> "when picking"
"secondar." -> "secondary."
packages/mdc-theme/README.md
Outdated
|
||
https://www.w3.org/TR/WCAG20 | ||
|
||
### Advanced customization | ||
|
||
Color scheme will only get your app 80% of the way to a well designed app. Inevitably there will be some components that do not work "out of the box". To fix problems with accessbility and design, we suggest you use our SASS mixins, such as `mdc-button-filled-accessible`. For more information, consult the documentation for each component. |
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.
"your app" -> "you" (it's currently redundant of "well designed app" later in the sentence)
"well designed" -> "well-designed"
Typo: accessbility -> accessibility
SASS -> Sass (it's how they themselves capitalize it)
packages/mdc-theme/README.md
Outdated
|
||
### Non-Sass customization | ||
|
||
Only a very limited number of Material Design color customization features are supported for non-Sass clients. They are a set of CSS custom properties, and a set of CSS classes |
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.
Add period at end of sentence
text-hint-on-secondary: mdc-theme-ink-color-for-fill_(hint, $mdc-theme-secondary), | ||
text-disabled-on-secondary: mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-secondary), | ||
text-icon-on-secondary: mdc-theme-ink-color-for-fill_(icon, $mdc-theme-secondary), | ||
on-primary: $mdc-theme-on-primary, |
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.
Just to confirm... are we expecting to update/prune the rest of this map (and the readme) in other imminent PRs?
ea4f009
to
6a0c403
Compare
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.
There is still a mention of text-primary-on-primary in the grid-list README.
Note: This will need BREAKING CHANGE to note the replacement of text-x-on-primary/secondary in both Sass and CSS variables, and the removal of text-hint/disabled/icon-on-primary-secondary. (Probably just need a general note that supported Sass and CSS variables have been renamed/removed, see readme for details.)
demos/theme/theme-shrine.scss
Outdated
// TODO: Use theme mixin(s) instead | ||
$mdc-theme-primary: #fff; | ||
$mdc-theme-secondary: $material-color-orange-500; | ||
$mdc-theme-primary: #FCB8AB; |
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.
Nit: uppercase hex to lowercase hex wherever these are used, to match other styles
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.
Remember BREAKING CHANGE
Fixes #2481
BREAKING CHANGE: Removes the
--mdc-theme-text-<TEXT_STYLE>-on-<THEME_COLOR>
CSS custom properties, and themdc-theme--text-<TEXT_STYLE>-on-<THEME_COLOR>
CSS classes