|
2 | 2 | @import '../core/theming/theming';
|
3 | 3 |
|
4 | 4 |
|
5 |
| -@mixin _md-slide-toggle-checked($palette) { |
| 5 | +@mixin _md-slide-toggle-checked($palette, $thumb-checked-hue) { |
6 | 6 | // Do not apply the checked colors if the toggle is disabled, because the specificity would be to high for
|
7 | 7 | // the disabled styles.
|
8 | 8 | &.md-checked:not(.md-disabled) {
|
9 | 9 | .md-slide-toggle-thumb {
|
10 |
| - background-color: md-color($palette); |
| 10 | + background-color: md-color($palette, $thumb-checked-hue); |
11 | 11 | }
|
12 | 12 |
|
13 | 13 | .md-slide-toggle-bar {
|
14 |
| - background-color: md-color($palette, 0.5); |
| 14 | + background-color: md-color($palette, $thumb-checked-hue, 0.5); |
15 | 15 | }
|
16 | 16 | }
|
17 | 17 | }
|
18 | 18 |
|
19 | 19 | // 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 | + |
21 | 22 | &.md-slide-toggle-focused {
|
22 | 23 | &:not(.md-checked) .md-ink-ripple {
|
23 | 24 | // When the slide-toggle is not checked and it shows its focus indicator, it should use a 12% opacity
|
24 | 25 | // of black in light themes and 12% of white in dark themes.
|
25 | 26 | background-color: md-color($foreground, divider);
|
26 | 27 | }
|
27 |
| - } |
28 | 28 |
|
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 | + } |
31 | 32 | }
|
| 33 | + |
32 | 34 | }
|
33 | 35 |
|
34 | 36 | @mixin md-slide-toggle-theme($theme) {
|
| 37 | + $is-dark: map_get($theme, is-dark); |
35 | 38 | $primary: map-get($theme, primary);
|
36 | 39 | $accent: map-get($theme, accent);
|
37 | 40 | $warn: map-get($theme, warn);
|
38 | 41 | $background: map-get($theme, background);
|
39 | 42 | $foreground: map-get($theme, foreground);
|
40 | 43 |
|
| 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 | + |
41 | 53 | 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); |
44 | 56 |
|
45 | 57 |
|
46 | 58 | &.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); |
49 | 61 | }
|
50 | 62 |
|
51 | 63 | &.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); |
54 | 66 | }
|
55 | 67 |
|
56 | 68 | }
|
|
60 | 72 | // The thumb of the slide-toggle always uses the hue 400 of the grey palette in dark or light themes.
|
61 | 73 | // Since this is very specific to the slide-toggle component, we're not providing
|
62 | 74 | // it in the background palette.
|
63 |
| - background-color: md-color($md-grey, 400); |
| 75 | + background-color: md-color($md-grey, $thumb-disabled-hue); |
64 | 76 | }
|
65 | 77 | .md-slide-toggle-bar {
|
66 |
| - background-color: md-color($foreground, divider); |
| 78 | + background-color: $bar-disabled-color; |
67 | 79 | }
|
68 | 80 | }
|
69 | 81 |
|
70 | 82 | .md-slide-toggle-thumb {
|
71 |
| - background-color: md-color($background, background); |
| 83 | + background-color: md-color($md-grey, $thumb-normal-hue); |
72 | 84 | }
|
73 | 85 |
|
74 | 86 | .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; |
78 | 88 | }
|
79 | 89 | }
|
0 commit comments