Skip to content

Commit 76eeaaf

Browse files
authored
fix(material/checkbox): refactor to depend on @angular/material/core/tokens (#26744)
* fix(material/checkbox): refactor to depend on @angular/material/core/tokens * add checkbox tokens with placeholder values * add styles for token slots and values to checkbox * fill in real token values and fix checkbox appearance * clean up unnecessary code * fix mat-list * fix ci
1 parent 7e9878c commit 76eeaaf

11 files changed

+358
-218
lines changed

src/material/_index.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
$private-ease-in-out-curve-function, $private-swift-ease-out-duration, $private-xsmall;
3232
@forward './core/typography/typography' show private-typography-to-2014-config,
3333
private-typography-to-2018-config;
34-
@forward './checkbox/checkbox-private' show private-checkbox-styles-with-color,
35-
$private-checkbox-theme-config;
3634
@forward './table/table-flex-styles' show private-table-flex-styles;
3735
@forward './core/style/menu-common' as private-menu-common-*;
3836
@forward './core/style/button-common' as private-button-common-*;

src/material/checkbox/_checkbox-private.scss

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/material/checkbox/_checkbox-theme.scss

Lines changed: 31 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,36 @@
1-
@use '@material/checkbox/checkbox' as mdc-checkbox;
1+
@use 'sass:map';
22
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
33
@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';
94
@use '../core/theming/theming';
105
@use '../core/typography/typography';
116
@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;
318

329
@mixin color($config-or-theme) {
3310
$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);
3713
$foreground: map.get($config, foreground);
3814

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));
4717

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+
}
5922

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+
}
6427

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);
6931
}
7032

71-
.mat-mdc-checkbox-disabled label {
33+
&.mat-mdc-checkbox-disabled label {
7234
// MDC should set the disabled color on the label, but doesn't, so we do it here instead.
7335
color: theming.get-color-from-palette($foreground, disabled-text);
7436
}
@@ -78,27 +40,26 @@
7840
@mixin typography($config-or-theme) {
7941
$config: typography.private-typography-to-2018-config(
8042
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+
}
8450
}
8551
}
8652

8753
@mixin density($config-or-theme) {
8854
$density-scale: theming.get-density-config($config-or-theme);
8955

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+
}
9759

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;
10263
}
10364
}
10465
}

0 commit comments

Comments
 (0)