Skip to content

Commit d16e8ac

Browse files
authored
feat(material-experimental/theming): add M3 tokens for pseudo checkbox (#28407)
Sets up the M3 tokens for the pseudo checkbox component.
1 parent 637b8f9 commit d16e8ac

File tree

7 files changed

+93
-21
lines changed

7 files changed

+93
-21
lines changed

src/dev-app/theme-m3.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ html {
7777
@include mat.optgroup-theme($light-theme);
7878
@include mat.option-theme($light-theme);
7979
@include mat.paginator-theme($light-theme);
80+
@include mat.pseudo-checkbox-theme($light-theme);
8081
@include mat.progress-bar-theme($light-theme);
8182
@include mat.progress-spinner-theme($light-theme);
8283
@include mat.radio-theme($light-theme);
@@ -126,6 +127,7 @@ html {
126127
@include mat.optgroup-color($dark-theme);
127128
@include mat.option-color($dark-theme);
128129
@include mat.paginator-color($dark-theme);
130+
@include mat.pseudo-checkbox-color($dark-theme);
129131
@include mat.progress-bar-color($dark-theme);
130132
@include mat.progress-spinner-color($dark-theme);
131133
@include mat.radio-color($dark-theme);
@@ -174,6 +176,7 @@ html {
174176
@include mat.optgroup-density($scale-theme);
175177
@include mat.option-density($scale-theme);
176178
@include mat.paginator-density($scale-theme);
179+
@include mat.pseudo-checkbox-density($scale-theme);
177180
@include mat.progress-bar-density($scale-theme);
178181
@include mat.progress-spinner-density($scale-theme);
179182
@include mat.radio-density($scale-theme);

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,38 @@
521521
);
522522
}
523523

524+
/// Generates custom tokens for the full variant of mat-pseudo-checkbox.
525+
/// @param {Map} $systems The MDC system tokens
526+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
527+
/// @return {Map} A set of custom tokens for the full variant of mat-pseudo-checkbox
528+
@function full-pseudo-checkbox($systems, $exclude-hardcoded) {
529+
$disabled-color-base: map.get($systems, 'md-sys-color', 'on-surface');
530+
$disabled-color: if($disabled-color-base == null, null, rgba($disabled-color-base, 0.38));
531+
532+
@return (
533+
selected-icon-color: map.get($systems, 'md-sys-color', 'primary'),
534+
selected-checkmark-color: map.get($systems, 'md-sys-color', 'on-primary'),
535+
unselected-icon-color: map.get($systems, 'md-sys-color', 'on-surface-variant'),
536+
disabled-selected-checkmark-color: map.get($systems, 'md-sys-color', 'surface'),
537+
disabled-unselected-icon-color: $disabled-color,
538+
disabled-selected-icon-color: $disabled-color,
539+
);
540+
}
541+
542+
/// Generates custom tokens for the minimal variant of mat-pseudo-checkbox.
543+
/// @param {Map} $systems The MDC system tokens
544+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
545+
/// @return {Map} A set of custom tokens for the minimal variant of mat-pseudo-checkbox
546+
@function minimal-pseudo-checkbox($systems, $exclude-hardcoded) {
547+
$disabled-color-base: map.get($systems, 'md-sys-color', 'on-surface');
548+
$disabled-color: if($disabled-color-base == null, null, rgba($disabled-color-base, 0.38));
549+
550+
@return (
551+
selected-checkmark-color: map.get($systems, 'md-sys-color', 'primary'),
552+
disabled-selected-checkmark-color: $disabled-color,
553+
);
554+
}
555+
524556
/// Generates custom tokens for the mat-radio.
525557
/// @param {Map} $systems The MDC system tokens
526558
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

src/material-experimental/theming/_m3-density.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ $_density-tokens: (
8888
(mat, menu): (),
8989
(mat, optgroup): (),
9090
(mat, option): (),
91+
(mat, full-pseudo-checkbox): (),
92+
(mat, minimal-pseudo-checkbox): (),
9193
(mat, paginator): (
9294
container-size: (56px, 52px, 48px, 40px),
9395
),

src/material-experimental/theming/_m3-tokens.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,16 @@
676676
custom-tokens.paginator($systems, $exclude-hardcoded),
677677
$token-slots
678678
),
679+
_namespace-tokens(
680+
(mat, full-pseudo-checkbox),
681+
custom-tokens.full-pseudo-checkbox($systems, $exclude-hardcoded),
682+
$token-slots
683+
),
684+
_namespace-tokens(
685+
(mat, minimal-pseudo-checkbox),
686+
custom-tokens.minimal-pseudo-checkbox($systems, $exclude-hardcoded),
687+
$token-slots
688+
),
679689
_namespace-tokens(
680690
(mat, radio),
681691
custom-tokens.radio($systems, $exclude-hardcoded),

src/material/_index.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
@forward './core/option/optgroup-theme' as optgroup-* show optgroup-color, optgroup-typography,
6161
optgroup-theme, optgroup-density, optgroup-base;
6262
@forward './core/selection/pseudo-checkbox/pseudo-checkbox-theme' as pseudo-checkbox-* show
63-
pseudo-checkbox-color, pseudo-checkbox-typography, pseudo-checkbox-theme, pseudo-checkbox-base;
63+
pseudo-checkbox-color, pseudo-checkbox-typography, pseudo-checkbox-theme, pseudo-checkbox-density,
64+
pseudo-checkbox-base;
6465
@forward './core/selection/pseudo-checkbox/pseudo-checkbox-common' as pseudo-checkbox-* show
6566
pseudo-checkbox-legacy-size;
6667
@forward './core/focus-indicators/focus-indicators-theme' as strong-focus-indicators-* show
Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use 'sass:map';
12
@use '../../theming/theming';
23
@use '../../theming/inspection';
34
@use '../../style/sass-utils';
@@ -14,25 +15,39 @@
1415
}
1516
}
1617

18+
@mixin _theme-from-tokens($tokens) {
19+
@if ($tokens != ()) {
20+
@include token-utils.create-token-values(tokens-mat-full-pseudo-checkbox.$prefix,
21+
map.get($tokens, tokens-mat-full-pseudo-checkbox.$prefix));
22+
@include token-utils.create-token-values(tokens-mat-minimal-pseudo-checkbox.$prefix,
23+
map.get($tokens, tokens-mat-minimal-pseudo-checkbox.$prefix));
24+
}
25+
}
26+
1727
@mixin base($theme) {}
1828

1929
@mixin color($theme) {
20-
.mat-primary {
21-
@include _palette-styles($theme, primary);
30+
@if inspection.get-theme-version($theme) == 1 {
31+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
2232
}
33+
@else {
34+
.mat-primary {
35+
@include _palette-styles($theme, primary);
36+
}
2337

24-
// Default to the accent color. Note that the pseudo checkboxes are meant to inherit the
25-
// theme from their parent, rather than implementing their own theming, which is why we
26-
// don't attach to the `mat-*` classes. Also note that this needs to be below `.mat-primary`
27-
// in order to allow for the color to be overwritten if the checkbox is inside a parent that
28-
// has `mat-accent` and is placed inside another parent that has `mat-primary`.
29-
@include _palette-styles($theme, accent);
30-
.mat-accent {
38+
// Default to the accent color. Note that the pseudo checkboxes are meant to inherit the
39+
// theme from their parent, rather than implementing their own theming, which is why we
40+
// don't attach to the `mat-*` classes. Also note that this needs to be below `.mat-primary`
41+
// in order to allow for the color to be overwritten if the checkbox is inside a parent that
42+
// has `mat-accent` and is placed inside another parent that has `mat-primary`.
3143
@include _palette-styles($theme, accent);
32-
}
44+
.mat-accent {
45+
@include _palette-styles($theme, accent);
46+
}
3347

34-
.mat-warn {
35-
@include _palette-styles($theme, warn);
48+
.mat-warn {
49+
@include _palette-styles($theme, warn);
50+
}
3651
}
3752
}
3853

@@ -42,15 +57,20 @@
4257

4358
@mixin theme($theme) {
4459
@include theming.private-check-duplicate-theme-styles($theme, 'mat-pseudo-checkbox') {
45-
@include base($theme);
46-
@if inspection.theme-has($theme, color) {
47-
@include color($theme);
48-
}
49-
@if inspection.theme-has($theme, density) {
50-
@include density($theme);
60+
@if inspection.get-theme-version($theme) == 1 {
61+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
5162
}
52-
@if inspection.theme-has($theme, typography) {
53-
@include typography($theme);
63+
@else {
64+
@include base($theme);
65+
@if inspection.theme-has($theme, color) {
66+
@include color($theme);
67+
}
68+
@if inspection.theme-has($theme, density) {
69+
@include density($theme);
70+
}
71+
@if inspection.theme-has($theme, typography) {
72+
@include typography($theme);
73+
}
5474
}
5575
}
5676
}

src/material/core/tokens/m2/_index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
@use './mat/option' as tokens-mat-option;
2222
@use './mat/optgroup' as tokens-mat-optgroup;
2323
@use './mat/paginator' as tokens-mat-paginator;
24+
@use './mat/full-pseudo-checkbox' as tokens-mat-full-pseudo-checkbox;
25+
@use './mat/minimal-pseudo-checkbox' as tokens-mat-minimal-pseudo-checkbox;
2426
@use './mat/radio' as tokens-mat-radio;
2527
@use './mat/ripple' as tokens-mat-ripple;
2628
@use './mat/select' as tokens-mat-select;
@@ -122,6 +124,8 @@
122124
_get-tokens-for-module($theme, tokens-mat-option),
123125
_get-tokens-for-module($theme, tokens-mat-outlined-button),
124126
_get-tokens-for-module($theme, tokens-mat-paginator),
127+
_get-tokens-for-module($theme, tokens-mat-full-pseudo-checkbox),
128+
_get-tokens-for-module($theme, tokens-mat-minimal-pseudo-checkbox),
125129
_get-tokens-for-module($theme, tokens-mat-protected-button),
126130
_get-tokens-for-module($theme, tokens-mat-radio),
127131
_get-tokens-for-module($theme, tokens-mat-ripple),

0 commit comments

Comments
 (0)