Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(checkbox): Add color theme mixins and update default color to secondary #1365

Merged
merged 81 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
2a17983
feat(checkbox): Refactor styles into themeable mixins (WIP - incomplete)
acdvorak Sep 28, 2017
7a67684
WIP: More mixin refactoring; change default color from primary to sec…
acdvorak Sep 28, 2017
f1c25a1
WIP: More refactoring; rename private vars; remove dead code
acdvorak Sep 29, 2017
9ebe10a
WIP: Consolidate redundant mixins; rename a mixin
acdvorak Sep 29, 2017
4f21547
WIP: Fix animation keyframe color; fix disabled color; add master col…
acdvorak Sep 29, 2017
03e4a90
WIP: Fix ripple size for CSS-only checkboxes
acdvorak Sep 29, 2017
1425655
WIP: Fix demo JS derp
acdvorak Sep 29, 2017
a6bc67a
WIP: Add TODO to fix jank bug
acdvorak Sep 29, 2017
a0049ab
WIP: Add dark theme examples of custom colors
acdvorak Sep 29, 2017
e3193a9
WIP: Remove redundant prefixes from checkbox labels
acdvorak Sep 29, 2017
edcf4d8
WIP: Move remaining styles to mixins
acdvorak Sep 29, 2017
e4a029c
WIP: Refactor animation mixins and add variable for default color
acdvorak Sep 29, 2017
eb7b09f
WIP: Use single master color mixin by default
acdvorak Sep 29, 2017
9210191
WIP: Refactor mixins
acdvorak Sep 29, 2017
8d56dd3
WIP: Reorder public mixins
acdvorak Sep 29, 2017
bc482bc
WIP: Fix linter errors
acdvorak Sep 29, 2017
f56abe7
WIP: Rename `animation-color` mixin to `state-transition-color`
acdvorak Sep 29, 2017
d155046
Merge remote-tracking branch 'origin/master' into feat/theme/checkbox…
acdvorak Sep 29, 2017
64b98fe
WIP: Add `$edgeOptOut` param to `container-color` mixin (added in com…
acdvorak Sep 29, 2017
8b2d815
WIP: Fix typo
acdvorak Sep 29, 2017
e9eb0bf
Merge branch 'master' into feat/theme/checkbox-mixins
acdvorak Oct 3, 2017
d7f60ae
WIP: Fix size of ripple hover circle for CSS-only checkbox
acdvorak Oct 3, 2017
d7bc30f
WIP: Rename `keyframes` mixin
acdvorak Oct 3, 2017
8a87458
WIP: Move CSS selectors to color mixins; remove master color mixin
acdvorak Oct 3, 2017
9ea3c5a
Merge branch 'master' into feat/theme/checkbox-mixins
acdvorak Oct 3, 2017
6f0c688
WIP: Add TODO to update docs
acdvorak Oct 4, 2017
dbe3dd5
Merge remote-tracking branch 'origin/master' into feat/theme/checkbox…
acdvorak Oct 4, 2017
ec26297
WIP: Refactor mixins: Flatten and restrict public API
acdvorak Oct 5, 2017
04e5674
WIP: Animation mixin accepts two colors; default ripple opacity is no…
acdvorak Oct 5, 2017
6213234
WIP: Throw error if no arguments are passed to mdc-checkbox-check-ani…
acdvorak Oct 5, 2017
56ecfc2
WIP: If only 1 param is passed, use it for both colors
acdvorak Oct 5, 2017
ccb18b7
WIP: Use single line comment to avoid outputting it in CSS
acdvorak Oct 5, 2017
41c7056
WIP: Use `:enabled` instead of `:not(:disabled)`
acdvorak Oct 5, 2017
f19ce95
WIP: Add comment
acdvorak Oct 5, 2017
871d651
WIP: Move mixins
acdvorak Oct 5, 2017
3cefd65
WIP: Use `:enabled` instead of `:not(:disabled)`
acdvorak Oct 5, 2017
aa14dcd
WIP: s/filled/marked/g
acdvorak Oct 5, 2017
4ecd741
WIP: Clean up some comments
acdvorak Oct 5, 2017
1fd0642
WIP: Add initially-indeterminate JS checkbox example
acdvorak Oct 5, 2017
e2b56d2
WIP: Minor demo JS/markup cleanup
acdvorak Oct 5, 2017
5218afa
WIP: Refactor ripple mixin to accept config object
acdvorak Oct 5, 2017
10f2459
WIP: Make demo selector more specific to avoid CSS ordering issues
acdvorak Oct 5, 2017
1784023
WIP: Add example of unmarked stroke color to demo
acdvorak Oct 5, 2017
dc59edd
WIP: Rename animation mixin for consistency
acdvorak Oct 5, 2017
dece9ec
WIP: Make both params required on animation mixin
acdvorak Oct 5, 2017
1ea3b49
Merge remote-tracking branch 'origin/master' into feat/theme/checkbox…
acdvorak Oct 5, 2017
f4df2a6
WIP: Fix pre-existing jank bug when transitioning from checked->unche…
acdvorak Oct 6, 2017
a5db090
WIP: Capitalize JavaScript
acdvorak Oct 6, 2017
46a67c7
WIP: Fix animation color by requiring params for both unmarked and ma…
acdvorak Oct 6, 2017
0e9ce47
WIP: Make first dark theme section JavaScript-enabled
acdvorak Oct 6, 2017
05fe47b
WIP: Make animation-keyframes function/mixin private
acdvorak Oct 6, 2017
3570ef2
WIP: Clean up TODOs
acdvorak Oct 6, 2017
767eb8c
WIP: Unindent line-wrapped params to fix linter errors
acdvorak Oct 6, 2017
ffe9e2c
WIP: Remove mixin that is no longer needed
acdvorak Oct 6, 2017
10107bf
WIP: Create variable for focus indicator opacity
acdvorak Oct 6, 2017
d6e3eab
WIP: Reorder mixins
acdvorak Oct 6, 2017
a1146bd
WIP: Add example of customizing ink color for dark mode
acdvorak Oct 6, 2017
7a5de34
WIP: Add mixins to README
acdvorak Oct 6, 2017
cab4db1
WIP: Rename demo variable to avoid future collisions
acdvorak Oct 6, 2017
d7b7d8e
WIP: Fix typo in README
acdvorak Oct 6, 2017
10dc11c
WIP: Move paragraph in README
acdvorak Oct 6, 2017
e4d4094
WIP: Use ripple-config to set radius instead of manually overriding it
acdvorak Oct 6, 2017
25682fb
WIP: Combine animation and stroke/container mixins into one
acdvorak Oct 9, 2017
2926dda
WIP: Rename "container-color" to "container-fill-color"
acdvorak Oct 9, 2017
f2cef46
WIP: Remove individual stroke/container color mixins
acdvorak Oct 9, 2017
f741867
WIP: Fix linter error
acdvorak Oct 9, 2017
ac66196
Merge remote-tracking branch 'origin/master' into feat/theme/checkbox…
acdvorak Oct 9, 2017
b0b1729
WIP: Fix incorrect @import
acdvorak Oct 9, 2017
e478b05
WIP: Remove unnecessary newline from README.md
acdvorak Oct 9, 2017
304f4de
WIP: Ensure that theme props can be used in keyframes
acdvorak Oct 9, 2017
6ef47f9
WIP: Rename color/animation mixins and arguments
acdvorak Oct 9, 2017
5388f23
WIP: Rename mixin param
acdvorak Oct 9, 2017
219b487
WIP: Update label text to match customizations
acdvorak Oct 10, 2017
875ac85
WIP: Make buttons a little prettier
acdvorak Oct 10, 2017
404556d
WIP: Combine stroke+fill color params in marked state
acdvorak Oct 10, 2017
8384d03
WIP: Don't animate color when checkbox is disabled
acdvorak Oct 10, 2017
c2ff54a
WIP: Allow baseline theme color var to be overridden
acdvorak Oct 11, 2017
01a6636
WIP: Fix linter errors
acdvorak Oct 11, 2017
487a7bb
WIP: Use different colors for unmarked vs. marked states in demo
acdvorak Oct 11, 2017
e522be3
WIP: Clarify marked stroke color behavior in README.md
acdvorak Oct 11, 2017
9e5dced
Merge branch 'master' into feat/theme/checkbox-mixins
acdvorak Oct 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
334 changes: 270 additions & 64 deletions demos/checkbox.html

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions demos/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
//

@import "./common";
@import "../packages/mdc-button/mdc-button";
@import "../packages/mdc-checkbox/mdc-checkbox";
@import "../packages/mdc-form-field/mdc-form-field";
@import "../packages/mdc-theme/color_palette";
@import "../packages/mdc-theme/mixins";
@import "../packages/mdc-typography/mdc-typography";

.mdc-checkbox.demo-checkbox--custom-all {
$color: $material-color-red-500;

@include mdc-checkbox-focus-indicator-color($color);
@include mdc-checkbox-ripple((base-color: $color, opacity: $mdc-checkbox-ripple-opacity));
@include mdc-checkbox-container-colors(
$unmarked-stroke-color: $color,
$unmarked-fill-color: rgba($color, .25),
$marked-fill-color: $color);

@include mdc-theme-dark(".mdc-checkbox", $compound: true) {
@include mdc-checkbox-ink-color(black);
@include mdc-checkbox-container-colors(
$unmarked-stroke-color: $color,
$unmarked-fill-color: rgba($color, .35),
$marked-fill-color: $color);
}
}

.mdc-checkbox.demo-checkbox--custom-stroke-and-fill {
$color: $material-color-blue-500;

@include mdc-checkbox-container-colors(
$unmarked-stroke-color: $color,
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

$marked-fill-color: $color);
}
28 changes: 24 additions & 4 deletions packages/mdc-checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Expand Down
33 changes: 33 additions & 0 deletions packages/mdc-checkbox/_functions.scss
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_;
}
84 changes: 33 additions & 51 deletions packages/mdc-checkbox/_keyframes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,42 @@
@import "@material/theme/mixins";
@import "./variables";

@keyframes mdc-checkbox-fade-in-background {
0% {
border-color: $mdc-checkbox-border-color;
background-color: transparent;
}

50% {
@include mdc-theme-prop(border-color, primary);
@include mdc-theme-prop(background-color, primary);
}
}

@keyframes mdc-checkbox-fade-out-background {
0%,
80% {
@include mdc-theme-prop(border-color, primary);
@include mdc-theme-prop(background-color, primary);
}

100% {
border-color: $mdc-checkbox-border-color;
background-color: transparent;
}
}

@keyframes mdc-checkbox-fade-in-background-dark {
0% {
border-color: $mdc-checkbox-border-color-dark;
background-color: transparent;
}

50% {
@include mdc-theme-prop(border-color, primary);
@include mdc-theme-prop(background-color, primary);
}
}

@keyframes mdc-checkbox-fade-out-background-dark {
0%,
80% {
@include mdc-theme-prop(border-color, primary);
@include mdc-theme-prop(background-color, primary);
}

100% {
border-color: $mdc-checkbox-border-color-dark;
background-color: transparent;
@mixin mdc-checkbox-container-keyframes_(
$from-stroke-color,
$to-stroke-color,
$from-fill-color,
$to-fill-color,
$uid) {
@keyframes mdc-checkbox-fade-in-background-#{$uid} {
0% {
@include mdc-theme-prop(border-color, $from-stroke-color);
@include mdc-theme-prop(background-color, $from-fill-color);
}

50% {
@include mdc-theme-prop(border-color, $to-stroke-color);
@include mdc-theme-prop(background-color, $to-fill-color);
}
}

@keyframes mdc-checkbox-fade-out-background-#{$uid} {
0%,
80% {
@include mdc-theme-prop(border-color, $to-stroke-color);
@include mdc-theme-prop(background-color, $to-fill-color);
}

100% {
@include mdc-theme-prop(border-color, $from-stroke-color);
@include mdc-theme-prop(background-color, $from-fill-color);
}
}
}

@keyframes mdc-checkbox-unchecked-checked-checkmark-path {
0%,
50% {
stroke-dashoffset: $_mdc-checkbox-mark-path-length;
stroke-dashoffset: $mdc-checkbox-mark-path-length_;
}

50% {
Expand Down Expand Up @@ -107,7 +89,7 @@

to {
opacity: 0;
stroke-dashoffset: $_mdc-checkbox-mark-path-length * -1;
stroke-dashoffset: $mdc-checkbox-mark-path-length_ * -1;
}
}

Expand All @@ -126,7 +108,7 @@

@keyframes mdc-checkbox-indeterminate-checked-checkmark {
from {
animation-timing-function: $_mdc-checkbox-indeterminate-checked-easing-function;
animation-timing-function: $mdc-checkbox-indeterminate-checked-easing-function_;
transform: rotate(45deg);
opacity: 0;
}
Expand All @@ -152,7 +134,7 @@

@keyframes mdc-checkbox-indeterminate-checked-mixedmark {
from {
animation-timing-function: $_mdc-checkbox-indeterminate-checked-easing-function;
animation-timing-function: $mdc-checkbox-indeterminate-checked-easing-function_;
transform: rotate(0deg);
opacity: 1;
}
Expand Down
Loading