Skip to content

Commit 4d50c38

Browse files
authored
feat(material-experimental/theming): add M3 icon support (#28126)
1 parent 8fb5b6b commit 4d50c38

File tree

6 files changed

+76
-23
lines changed

6 files changed

+76
-23
lines changed

src/dev-app/theme-m3.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ html {
4040
@include mat.checkbox-theme($light-theme);
4141
@include mat.form-field-theme($light-theme);
4242
@include mat.grid-list-theme($light-theme);
43+
@include mat.icon-theme($light-theme);
4344
@include mat.input-theme($light-theme);
4445
@include mat.list-theme($light-theme);
4546
@include mat.progress-bar-theme($light-theme);
@@ -68,6 +69,7 @@ html {
6869
@include mat.checkbox-color($dark-theme);
6970
@include mat.form-field-color($dark-theme);
7071
@include mat.grid-list-color($dark-theme);
72+
@include mat.icon-color($dark-theme);
7173
@include mat.input-color($dark-theme);
7274
@include mat.list-color($dark-theme);
7375
@include mat.progress-bar-color($dark-theme);
@@ -95,6 +97,7 @@ html {
9597
@include mat.checkbox-density($scale-theme);
9698
@include mat.form-field-density($scale-theme);
9799
@include mat.grid-list-density($scale-theme);
100+
@include mat.icon-density($scale-theme);
98101
@include mat.input-density($scale-theme);
99102
@include mat.list-density($scale-theme);
100103
@include mat.progress-bar-density($scale-theme);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@
7575
);
7676
}
7777

78+
/// Generates custom tokens for the mat-icon.
79+
/// @param {Map} $systems The MDC system tokens
80+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
81+
/// @return {Map} A set of custom tokens for the mat-icon
82+
@function icon($systems, $exclude-hardcoded) {
83+
@return (
84+
color: _hardcode(inherit, $exclude-hardcoded),
85+
);
86+
}
87+
7888
/// Generates custom tokens for the mat-toolbar.
7989
/// @param {Map} $systems The MDC system tokens
8090
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ $_density-tokens: (
4646
(mat, card): (),
4747
(mat, form-fild): (),
4848
(mat, grid-list): (),
49+
(mat, icon): (),
4950
(mat, toolbar): (
5051
standard-height: (64px, 60px, 56px, 52px),
5152
mobile-height: (56px, 52px, 48px, 44px),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@
264264
custom-tokens.grid-list($systems, $exclude-hardcoded),
265265
$token-slots
266266
),
267+
_namespace-tokens(
268+
(mat, icon),
269+
custom-tokens.icon($systems, $exclude-hardcoded),
270+
$token-slots
271+
),
267272
_namespace-tokens(
268273
(mat, toolbar),
269274
custom-tokens.toolbar($systems, $exclude-hardcoded),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@use './mat/card' as tokens-mat-card;
55
@use './mat/form-field' as tokens-mat-form-field;
66
@use './mat/grid-list' as tokens-mat-grid-list;
7+
@use './mat/icon' as tokens-mat-icon;
78
@use './mat/radio' as tokens-mat-radio;
89
@use './mat/ripple' as tokens-mat-ripple;
910
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
@@ -80,6 +81,7 @@
8081
_get-tokens-for-module($theme, tokens-mat-card),
8182
_get-tokens-for-module($theme, tokens-mat-form-field),
8283
_get-tokens-for-module($theme, tokens-mat-grid-list),
84+
_get-tokens-for-module($theme, tokens-mat-icon),
8385
_get-tokens-for-module($theme, tokens-mat-radio),
8486
_get-tokens-for-module($theme, tokens-mat-ripple),
8587
_get-tokens-for-module($theme, tokens-mat-slide-toggle),

src/material/icon/_icon-theme.scss

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use 'sass:map';
12
@use '../core/theming/theming';
23
@use '../core/theming/inspection';
34
@use '../core/tokens/m2/mat/icon' as tokens-mat-icon;
@@ -10,45 +11,76 @@
1011
@include token-utils.create-token-values(tokens-mat-icon.$prefix, $tokens);
1112
}
1213

13-
@mixin base($theme) {}
14+
@mixin base($theme) {
15+
@if inspection.get-theme-version($theme) == 1 {
16+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
17+
}
18+
@else {}
19+
}
1420

1521
@mixin color($theme) {
16-
@include sass-utils.current-selector-or-root() {
17-
@include token-utils.create-token-values(tokens-mat-icon.$prefix,
18-
tokens-mat-icon.get-color-tokens($theme));
22+
@if inspection.get-theme-version($theme) == 1 {
23+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
1924
}
20-
21-
.mat-icon {
22-
&.mat-primary {
23-
@include _palette-colors($theme, primary);
25+
@else {
26+
@include sass-utils.current-selector-or-root() {
27+
@include token-utils.create-token-values(tokens-mat-icon.$prefix,
28+
tokens-mat-icon.get-color-tokens($theme));
2429
}
2530

26-
&.mat-accent {
27-
@include _palette-colors($theme, accent);
28-
}
31+
.mat-icon {
32+
&.mat-primary {
33+
@include _palette-colors($theme, primary);
34+
}
35+
36+
&.mat-accent {
37+
@include _palette-colors($theme, accent);
38+
}
2939

30-
&.mat-warn {
31-
@include _palette-colors($theme, warn);
40+
&.mat-warn {
41+
@include _palette-colors($theme, warn);
42+
}
3243
}
3344
}
3445
}
3546

36-
@mixin typography($theme) {}
47+
@mixin typography($theme) {
48+
@if inspection.get-theme-version($theme) == 1 {
49+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
50+
}
51+
@else {}
52+
}
3753

38-
@mixin density($theme) {}
54+
@mixin density($theme) {
55+
@if inspection.get-theme-version($theme) == 1 {
56+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
57+
}
58+
@else {}
59+
}
3960

4061
@mixin theme($theme) {
4162
@include theming.private-check-duplicate-theme-styles($theme, 'mat-icon') {
42-
@include base($theme);
43-
@if inspection.theme-has($theme, color) {
44-
@include color($theme);
63+
@if inspection.get-theme-version($theme) == 1 {
64+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
4565
}
46-
@if inspection.theme-has($theme, density) {
47-
@include density($theme);
48-
}
49-
@if inspection.theme-has($theme, typography) {
50-
@include typography($theme);
66+
@else {
67+
@include base($theme);
68+
@if inspection.theme-has($theme, color) {
69+
@include color($theme);
70+
}
71+
@if inspection.theme-has($theme, density) {
72+
@include density($theme);
73+
}
74+
@if inspection.theme-has($theme, typography) {
75+
@include typography($theme);
76+
}
5177
}
5278
}
5379
}
5480

81+
@mixin _theme-from-tokens($tokens) {
82+
@if ($tokens != ()) {
83+
@include token-utils.create-token-values(
84+
tokens-mat-icon.$prefix, map.get($tokens, tokens-mat-icon.$prefix));
85+
}
86+
}

0 commit comments

Comments
 (0)