Skip to content

Commit 78446e5

Browse files
committed
refactor(material/checkbox): switch touch target to tokens
Switches the checkbox touch target to use tokens.
1 parent d26a51e commit 78446e5

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ $_density-tokens: (
6868
(mat, badge): (),
6969
(mat, bottom-sheet): (),
7070
(mat, card): (),
71+
(mat, checkbox): (
72+
touch-target-display: (block, block, none, none),
73+
),
7174
(mat, datepicker): (),
7275
(mat, divider): (),
7376
(mat, expansion): (

src/material/checkbox/_checkbox-theme.scss

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
33
@use '@material/form-field/form-field-theme' as mdc-form-field-theme;
44
@use '../core/style/sass-utils';
5+
@use '../core/tokens/token-utils';
56
@use '../core/theming/theming';
67
@use '../core/theming/inspection';
78
@use '../core/typography/typography';
8-
@use '../core/mdc-helpers/mdc-helpers';
99
@use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
1010
@use '../core/tokens/m2/mdc/form-field' as tokens-mdc-form-field;
11+
@use '../core/tokens/m2/mat/checkbox' as tokens-mat-checkbox;
1112

1213
@mixin base($theme) {
1314
@if inspection.get-theme-version($theme) == 1 {
@@ -16,6 +17,8 @@
1617
@else {
1718
@include sass-utils.current-selector-or-root() {
1819
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-unthemable-tokens());
20+
@include token-utils.create-token-values(
21+
tokens-mat-checkbox.$prefix, tokens-mat-checkbox.get-unthemable-tokens());
1922
}
2023
}
2124
}
@@ -27,6 +30,8 @@
2730
@else {
2831
@include sass-utils.current-selector-or-root() {
2932
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($theme));
33+
@include token-utils.create-token-values(
34+
tokens-mat-checkbox.$prefix, tokens-mat-checkbox.get-color-tokens($theme));
3035
}
3136

3237
.mat-mdc-checkbox {
@@ -55,6 +60,8 @@
5560
@else {
5661
@include sass-utils.current-selector-or-root() {
5762
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-typography-tokens($theme));
63+
@include token-utils.create-token-values(
64+
tokens-mat-checkbox.$prefix, tokens-mat-checkbox.get-typography-tokens($theme));
5865
}
5966

6067
.mat-mdc-checkbox {
@@ -72,12 +79,8 @@
7279
@else {
7380
@include sass-utils.current-selector-or-root() {
7481
@include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-density-tokens($theme));
75-
}
76-
77-
@include mdc-helpers.if-touch-targets-unsupported($density-scale) {
78-
.mat-mdc-checkbox-touch-target {
79-
display: none;
80-
}
82+
@include token-utils.create-token-values(
83+
tokens-mat-checkbox.$prefix, tokens-mat-checkbox.get-density-tokens($theme));
8184
}
8285
}
8386
}
@@ -108,5 +111,7 @@
108111
// so this mixin is currently incomplete.
109112
@include mdc-checkbox-theme.theme(map.get($tokens, tokens-mdc-checkbox.$prefix));
110113
@include mdc-form-field-theme.theme(map.get($tokens, tokens-mdc-form-field.$prefix));
114+
@include token-utils.create-token-values(
115+
tokens-mat-checkbox.$prefix, map.get($tokens, tokens-mat-checkbox.$prefix));
111116
}
112117
}

src/material/checkbox/checkbox.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@use '../core/style/layout-common';
99
@use '../core/style/vendor-prefixes';
1010
@use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
11+
@use '../core/tokens/m2/mat/checkbox' as tokens-mat-checkbox;
1112
@use '../core/tokens/token-utils';
1213

1314
@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) {
@@ -220,6 +221,11 @@
220221
@include mdc-touch-target.touch-target(
221222
$set-width: true,
222223
$query: mdc-helpers.$mdc-base-styles-query);
224+
225+
@include token-utils.use-tokens(tokens-mat-checkbox.$prefix,
226+
tokens-mat-checkbox.get-token-slots()) {
227+
@include token-utils.create-token-slot(display, touch-target-display);
228+
}
223229
}
224230

225231
// Checkbox components have to set `border-radius: 50%` in order to support density scaling
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@use '../../token-utils';
2+
@use '../../../theming/theming';
3+
@use '../../../theming/inspection';
4+
@use '../../../style/sass-utils';
5+
6+
// The prefix used to generate the fully qualified name for tokens in this file.
7+
$prefix: (mat, checkbox);
8+
9+
// Tokens that can't be configured through Angular Material's current theming API,
10+
// but may be in a future version of the theming API.
11+
@function get-unthemable-tokens() {
12+
@return ();
13+
}
14+
15+
// Tokens that can be configured through Angular Material's color theming API.
16+
@function get-color-tokens($theme) {
17+
@return ();
18+
}
19+
20+
// Tokens that can be configured through Angular Material's typography theming API.
21+
@function get-typography-tokens($theme) {
22+
@return ();
23+
}
24+
25+
// Tokens that can be configured through Angular Material's density theming API.
26+
@function get-density-tokens($theme) {
27+
$density-scale: theming.clamp-density(inspection.get-theme-density($theme), -3);
28+
29+
@return (
30+
touch-target-display: if($density-scale < -1, none, block),
31+
);
32+
}
33+
34+
// Combines the tokens generated by the above functions into a single map with placeholder values.
35+
// This is used to create token slots.
36+
@function get-token-slots() {
37+
@return sass-utils.deep-merge-all(
38+
get-unthemable-tokens(),
39+
get-color-tokens(token-utils.$placeholder-color-config),
40+
get-typography-tokens(token-utils.$placeholder-typography-config),
41+
get-density-tokens(token-utils.$placeholder-density-config)
42+
);
43+
}

0 commit comments

Comments
 (0)