-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(checkbox): Add color theme mixins and update default color to secondary #1365
Changes from 78 commits
2a17983
7a67684
f1c25a1
9ebe10a
4f21547
03e4a90
1425655
a6bc67a
a0049ab
e3193a9
edcf4d8
e4a029c
eb7b09f
9210191
8d56dd3
bc482bc
f56abe7
d155046
64b98fe
8b2d815
e9eb0bf
d7f60ae
d7bc30f
8a87458
9ea3c5a
6f0c688
dbe3dd5
ec26297
04e5674
6213234
56ecfc2
ccb18b7
41c7056
f19ce95
871d651
3cefd65
aa14dcd
4ecd741
1fd0642
e2b56d2
5218afa
10f2459
1784023
dc59edd
dece9ec
1ea3b49
f4df2a6
a5db090
46a67c7
0e9ce47
05fe47b
3570ef2
767eb8c
ffe9e2c
10107bf
d6e3eab
a1146bd
7a5de34
cab4db1
d7b7d8e
10dc11c
e4d4094
25682fb
2926dda
f2cef46
f741867
ac66196
b0b1729
e478b05
304f4de
6ef47f9
5388f23
219b487
875ac85
404556d
8384d03
c2ff54a
01a6636
487a7bb
e522be3
9e5dced
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,8 @@ easily position checkboxes and their labels. | |
|
||
#### Disabled Checkboxes | ||
|
||
Note that `mdc-checkbox--disabled` is necessary on the root element of CSS-only checkboxes to prevent hover states from activating. Checkboxes that use the JavaScript component do not need this class; a `disabled` attribute on the `<input>` element is sufficient. | ||
|
||
```html | ||
<div class="mdc-checkbox mdc-checkbox--disabled"> | ||
<input type="checkbox" | ||
|
@@ -111,8 +113,6 @@ easily position checkboxes and their labels. | |
<label for="basic-disabled-checkbox" id="basic-disabled-checkbox-label">This is my disabled checkbox</label> | ||
``` | ||
|
||
Note that `mdc-checkbox--disabled` is necessary on the root element to prevent hover states from activating. | ||
|
||
### Using the JS Component | ||
|
||
MDC Checkbox ships with a Component / Foundation combo which progressively enhances the checkbox | ||
|
@@ -255,8 +255,28 @@ not return an object. | |
|
||
## Theming | ||
|
||
MDC Checkboxes use the theme's primary color by default for checked and indeterminate states, and are completely dark theme | ||
aware. | ||
MDC Checkboxes use the theme's secondary color by default for "marked" states (i.e., checked or indeterminate), and are completely dark theme aware. | ||
|
||
### Sass Mixins | ||
|
||
The following mixins apply only to _enabled_ checkboxes. It is not currently possible to customize the color of a _disabled_ checkbox. | ||
|
||
Mixin | Description | ||
--- | --- | ||
`mdc-checkbox-container-colors($unmarked-stroke-color, $unmarked-fill-color, $marked-fill-color, $generate-keyframes)` | Generates CSS classes to set and animate the stroke color and/or container fill color of a checkbox | ||
`mdc-checkbox-ink-color($color)` | Sets the ink color of the checked and indeterminate icons | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really intended to be fully customizable and not just automatically text-primary-on(light|dark)? Or should we have an accessible helper that does that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question. I'll ask design on Tuesday 10/10, but I'm guessing it should be fully customizable. The dark theme section of the updated demo page in this PR shows a good use case for custom ink color. Personally, I think a dark checkmark icon is easier to see than a light icon when it's on top of a dark background. Ditto for light icons on light backgrounds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's pretty interesting...and for that matter, also makes me wonder if we're meeting contrast requirements for the white-on-green icons to begin with. Not sure offhand what the requirements are when icons are involved. Definitely worth picking designers' brains. |
||
`mdc-checkbox-focus-indicator-color($color)` | Sets the color of the focus indicator | ||
`mdc-checkbox-ripple($ripple-config)` | Sets the ripple to the given [ripple configuration][ripple-readme] | ||
|
||
[ripple-readme]: https://github.com/material-components/material-components-web/blob/master/packages/mdc-ripple/README.md | ||
|
||
#### `mdc-checkbox-container-colors($unmarked-stroke-color, $unmarked-fill-color, $marked-fill-color, $generate-keyframes)` | ||
|
||
Generates CSS classes to set the stroke color and/or container fill color of a checkbox in its marked and unmarked states. In the unmarked state, stroke and fill color may be customized independently; in the marked state, the stroke disappears, and only the fill may be customized. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds a little misleading... the stroke doesn't technically disappear, but it intentionally matches the marked fill color, they can't be customized separately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
All parameters are optional, and if left unspecified will use their default values. | ||
|
||
If you plan to use CSS-only checkboxes, set `$generate-keyframes` to `false` to prevent the mixin from generating `@keyframes` and CSS classes used by the JavaScript component. | ||
|
||
### Caveat: Edge and CSS Variables | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Copyright 2016 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@import "@material/theme/functions"; | ||
|
||
$mdc-checkbox-container-keyframes-uid_: -1; | ||
|
||
@function mdc-checkbox-transition-enter($property, $delay: 0ms, $duration: $mdc-checkbox-transition-duration) { | ||
@return mdc-animation-enter($property, $duration, $delay); | ||
} | ||
|
||
@function mdc-checkbox-transition-exit($property, $delay: 0ms, $duration: $mdc-checkbox-transition-duration) { | ||
@return mdc-animation-exit-temporary($property, $duration, $delay); | ||
} | ||
|
||
@function mdc-checkbox-container-keyframes-uid_() { | ||
$mdc-checkbox-container-keyframes-uid_: $mdc-checkbox-container-keyframes-uid_ + 1 !global; | ||
|
||
@return $mdc-checkbox-container-keyframes-uid_; | ||
} |
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 would suggest making this color different to better illustrate how this mixin's parameters work now. I was seriously confused for several minutes thinking we were applying the same stroke color to both states, but IIUC that's not what we're doing; we're making the marked stroke color match the marked fill color, which makes sense.
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.
Done