|
1 | | -@use '@material/checkbox/checkbox' as mdc-checkbox; |
| 1 | +@use 'sass:map'; |
2 | 2 | @use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme; |
3 | 3 | @use '@material/form-field' as mdc-form-field; |
4 | | -@use '@material/theme/theme-color' as mdc-theme-color; |
5 | | -@use '@material/theme/theme'; |
6 | | -@use 'sass:map'; |
7 | | -@use 'sass:color'; |
8 | | -@use '../core/ripple/ripple-theme'; |
9 | 4 | @use '../core/theming/theming'; |
10 | 5 | @use '../core/typography/typography'; |
11 | 6 | @use '../core/mdc-helpers/mdc-helpers'; |
12 | | -@use './checkbox-private'; |
13 | | - |
14 | | -// Apply ripple colors to the MatRipple element and the MDC ripple element when the |
15 | | -// checkbox is selected. |
16 | | -@mixin _selected-ripple-colors($theme, $mdc-color) { |
17 | | - .mdc-checkbox--selected ~ { |
18 | | - .mat-mdc-checkbox-ripple { |
19 | | - @include ripple-theme.color(( |
20 | | - foreground: ( |
21 | | - base: mdc-theme-color.prop-value($mdc-color) |
22 | | - ), |
23 | | - )); |
24 | | - } |
25 | | - |
26 | | - .mdc-checkbox__ripple { |
27 | | - background: $theme; |
28 | | - } |
29 | | - } |
30 | | -} |
| 7 | +@use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox; |
31 | 8 |
|
32 | 9 | @mixin color($config-or-theme) { |
33 | 10 | $config: theming.get-color-config($config-or-theme); |
34 | | - $primary: theming.get-color-from-palette(map.get($config, primary)); |
35 | | - $accent: theming.get-color-from-palette(map.get($config, accent)); |
36 | | - $warn: theming.get-color-from-palette(map.get($config, warn)); |
| 11 | + $primary: map.get($config, primary); |
| 12 | + $warn: map.get($config, warn); |
37 | 13 | $foreground: map.get($config, foreground); |
38 | 14 |
|
39 | | - @include mdc-helpers.using-mdc-theme($config) { |
40 | | - .mat-mdc-checkbox { |
41 | | - @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-theme-styles-query); |
42 | | - @include ripple-theme.color(( |
43 | | - foreground: ( |
44 | | - base: mdc-theme-color.prop-value(on-surface) |
45 | | - ), |
46 | | - )); |
| 15 | + .mat-mdc-checkbox { |
| 16 | + @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($config)); |
47 | 17 |
|
48 | | - .mdc-checkbox__ripple { |
49 | | - background: mdc-theme-color.prop-value(on-surface); |
50 | | - } |
51 | | - |
52 | | - // MDC's checkbox doesn't support a `color` property. We add support for it by adding a CSS |
53 | | - // class for accent and warn style, and applying the appropriate overrides below. Since we |
54 | | - // don't use MDC's ripple, we also need to set the color for our replacement ripple. |
55 | | - &.mat-primary { |
56 | | - @include checkbox-private.private-checkbox-styles-with-color($config, $primary, primary); |
57 | | - @include _selected-ripple-colors($primary, primary); |
58 | | - } |
| 18 | + &.mat-primary { |
| 19 | + $primary-config: map.merge($config, (accent: $primary)); |
| 20 | + @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($primary-config)); |
| 21 | + } |
59 | 22 |
|
60 | | - &.mat-accent { |
61 | | - @include checkbox-private.private-checkbox-styles-with-color($config, $accent, secondary); |
62 | | - @include _selected-ripple-colors($accent, secondary); |
63 | | - } |
| 23 | + &.mat-warn { |
| 24 | + $warn-config: map.merge($config, (accent: $warn)); |
| 25 | + @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($warn-config)); |
| 26 | + } |
64 | 27 |
|
65 | | - &.mat-warn { |
66 | | - @include checkbox-private.private-checkbox-styles-with-color($config, $warn, error); |
67 | | - @include _selected-ripple-colors($warn, error); |
68 | | - } |
| 28 | + @include mdc-helpers.using-mdc-theme($config) { |
| 29 | + // TODO(mmalerba): Switch to static-styles, theme-styles, and theme once they're available. |
| 30 | + @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-theme-styles-query); |
69 | 31 | } |
70 | 32 |
|
71 | | - .mat-mdc-checkbox-disabled label { |
| 33 | + &.mat-mdc-checkbox-disabled label { |
72 | 34 | // MDC should set the disabled color on the label, but doesn't, so we do it here instead. |
73 | 35 | color: theming.get-color-from-palette($foreground, disabled-text); |
74 | 36 | } |
|
78 | 40 | @mixin typography($config-or-theme) { |
79 | 41 | $config: typography.private-typography-to-2018-config( |
80 | 42 | theming.get-typography-config($config-or-theme)); |
81 | | - @include mdc-helpers.using-mdc-typography($config) { |
82 | | - @include mdc-checkbox.without-ripple($query: mdc-helpers.$mdc-typography-styles-query); |
83 | | - @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query); |
| 43 | + .mat-mdc-checkbox { |
| 44 | + @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-typography-tokens($config)); |
| 45 | + |
| 46 | + @include mdc-helpers.using-mdc-typography($config) { |
| 47 | + // TODO(mmalerba): Switch to static-styles, theme-styles, and theme once they're available. |
| 48 | + @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query); |
| 49 | + } |
84 | 50 | } |
85 | 51 | } |
86 | 52 |
|
87 | 53 | @mixin density($config-or-theme) { |
88 | 54 | $density-scale: theming.get-density-config($config-or-theme); |
89 | 55 |
|
90 | | - @include mdc-helpers.disable-mdc-fallback-declarations { |
91 | | - .mat-mdc-checkbox .mdc-checkbox { |
92 | | - @include mdc-checkbox-theme.density( |
93 | | - $density-scale, |
94 | | - $query: mdc-helpers.$mdc-base-styles-query |
95 | | - ); |
96 | | - } |
| 56 | + .mat-mdc-checkbox { |
| 57 | + @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-density-tokens($density-scale)); |
| 58 | + } |
97 | 59 |
|
98 | | - @include mdc-helpers.if-touch-targets-unsupported($density-scale) { |
99 | | - .mat-mdc-checkbox-touch-target { |
100 | | - display: none; |
101 | | - } |
| 60 | + @include mdc-helpers.if-touch-targets-unsupported($density-scale) { |
| 61 | + .mat-mdc-checkbox-touch-target { |
| 62 | + display: none; |
102 | 63 | } |
103 | 64 | } |
104 | 65 | } |
|
0 commit comments