Skip to content

Commit 596d994

Browse files
devversionjelbourn
authored andcommitted
fix(slide-toggle): update colors to match spec (#1612)
1 parent 8e7f80d commit 596d994

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/lib/slide-toggle/_slide-toggle-theme.scss

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,67 @@
22
@import '../core/theming/theming';
33

44

5-
@mixin _md-slide-toggle-checked($palette) {
5+
@mixin _md-slide-toggle-checked($palette, $thumb-checked-hue) {
66
// Do not apply the checked colors if the toggle is disabled, because the specificity would be to high for
77
// the disabled styles.
88
&.md-checked:not(.md-disabled) {
99
.md-slide-toggle-thumb {
10-
background-color: md-color($palette);
10+
background-color: md-color($palette, $thumb-checked-hue);
1111
}
1212

1313
.md-slide-toggle-bar {
14-
background-color: md-color($palette, 0.5);
14+
background-color: md-color($palette, $thumb-checked-hue, 0.5);
1515
}
1616
}
1717
}
1818

1919
// TODO(jelbourn): remove this when the real ripple has been applied to slide-toggle.
20-
@mixin _md-slide-toggle-ripple($palette, $foreground) {
20+
@mixin _md-slide-toggle-ripple($palette, $foreground, $thumb-checked-hue) {
21+
2122
&.md-slide-toggle-focused {
2223
&:not(.md-checked) .md-ink-ripple {
2324
// When the slide-toggle is not checked and it shows its focus indicator, it should use a 12% opacity
2425
// of black in light themes and 12% of white in dark themes.
2526
background-color: md-color($foreground, divider);
2627
}
27-
}
2828

29-
&.md-slide-toggle-focused .md-ink-ripple {
30-
background-color: md-color($palette, 0.26);
29+
.md-ink-ripple {
30+
background-color: md-color($palette, $thumb-checked-hue, 0.26);
31+
}
3132
}
33+
3234
}
3335

3436
@mixin md-slide-toggle-theme($theme) {
37+
$is-dark: map_get($theme, is-dark);
3538
$primary: map-get($theme, primary);
3639
$accent: map-get($theme, accent);
3740
$warn: map-get($theme, warn);
3841
$background: map-get($theme, background);
3942
$foreground: map-get($theme, foreground);
4043

44+
// Color hues based on the specs, which prescribe different hues for dark and light themes
45+
// https://material.google.com/components/selection-controls.html#selection-controls-switch
46+
$thumb-normal-hue: if($is-dark, 400, 50);
47+
$thumb-checked-hue: if($is-dark, 200, 500);
48+
$thumb-disabled-hue: if($is-dark, 800, 400);
49+
50+
$bar-normal-color: md-color($foreground, disabled);
51+
$bar-disabled-color: if($is-dark, rgba(white, 0.12), rgba(black, 0.1));
52+
4153
md-slide-toggle {
42-
@include _md-slide-toggle-checked($accent);
43-
@include _md-slide-toggle-ripple($accent, $foreground);
54+
@include _md-slide-toggle-checked($accent, $thumb-checked-hue);
55+
@include _md-slide-toggle-ripple($accent, $foreground, $thumb-checked-hue);
4456

4557

4658
&.md-primary {
47-
@include _md-slide-toggle-checked($primary);
48-
@include _md-slide-toggle-ripple($primary, $foreground);
59+
@include _md-slide-toggle-checked($primary, $thumb-checked-hue);
60+
@include _md-slide-toggle-ripple($primary, $foreground, $thumb-checked-hue);
4961
}
5062

5163
&.md-warn {
52-
@include _md-slide-toggle-checked($warn);
53-
@include _md-slide-toggle-ripple($warn, $foreground);
64+
@include _md-slide-toggle-checked($warn, $thumb-checked-hue);
65+
@include _md-slide-toggle-ripple($warn, $foreground, $thumb-checked-hue);
5466
}
5567

5668
}
@@ -60,20 +72,18 @@
6072
// The thumb of the slide-toggle always uses the hue 400 of the grey palette in dark or light themes.
6173
// Since this is very specific to the slide-toggle component, we're not providing
6274
// it in the background palette.
63-
background-color: md-color($md-grey, 400);
75+
background-color: md-color($md-grey, $thumb-disabled-hue);
6476
}
6577
.md-slide-toggle-bar {
66-
background-color: md-color($foreground, divider);
78+
background-color: $bar-disabled-color;
6779
}
6880
}
6981

7082
.md-slide-toggle-thumb {
71-
background-color: md-color($background, background);
83+
background-color: md-color($md-grey, $thumb-normal-hue);
7284
}
7385

7486
.md-slide-toggle-bar {
75-
// The slide-toggle bar always uses grey-500 for both dark and light themes.
76-
// Since this is very specific to slide-toggle, it's not part of the common background palette.
77-
background-color: md-color($md-grey, 500);
87+
background-color: $bar-normal-color;
7888
}
7989
}

0 commit comments

Comments
 (0)