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

feat(theme): Add new mdc-theme-on-primary global variable #2483

Merged
merged 9 commits into from
Apr 18, 2018

Conversation

lynnmercier
Copy link
Contributor

Fixes #2481

BREAKING CHANGE: Removes the --mdc-theme-text-<TEXT_STYLE>-on-<THEME_COLOR> CSS custom properties, and the mdc-theme--text-<TEXT_STYLE>-on-<THEME_COLOR> CSS classes

@codecov-io
Copy link

codecov-io commented Mar 28, 2018

Codecov Report

Merging #2483 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82cd6ff...08a752f. Read the comment docs.

@@ -23,11 +23,13 @@
//

$mdc-theme-primary: #6200ee !default; // baseline purple, 500 tone
$mdc-theme-on-primary: #fff !default;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@kfranqueiro kfranqueiro Mar 28, 2018

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.

Copy link
Contributor Author

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

Copy link
Contributor

@kfranqueiro kfranqueiro Mar 30, 2018

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.

https://github.com/material-components/material-components-web/blob/v0.33.0/packages/mdc-theme/_variables.scss#L42-L63

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@kfranqueiro
Copy link
Contributor

Removing the entries from the map causes CSS classes to no longer be generated here:

https://github.com/material-components/material-components-web/blob/v0.33.0/packages/mdc-theme/mdc-theme.scss#L30-L36

Which causes regressions in demo pages that use mdc-theme--x classes to apply color.

Are we expecting to maintain classes for this as before (e.g. now we would have mdc-theme--on-primary and --on-secondary)? We'll need to enumerate the new classes to generate in mdc-theme.scss.

Here's an example of a regression, in the theme page (the 3rd and 4th buttons should have white text):

image

Copy link
Contributor

@kfranqueiro kfranqueiro left a 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

> `$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.
Copy link
Contributor

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."


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.
Copy link
Contributor

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)


### 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
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Contributor

@kfranqueiro kfranqueiro left a 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.)

// TODO: Use theme mixin(s) instead
$mdc-theme-primary: #fff;
$mdc-theme-secondary: $material-color-orange-500;
$mdc-theme-primary: #FCB8AB;
Copy link
Contributor

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

@williamernest williamernest self-assigned this Apr 18, 2018
Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember BREAKING CHANGE

@williamernest williamernest merged commit 777a0fd into master Apr 18, 2018
@williamernest williamernest deleted the feat/on-primary branch April 18, 2018 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants