Skip to content

Commit 3b0d6a1

Browse files
committed
feat(material-experimental/theming): add M3 icon support
1 parent d7b4543 commit 3b0d6a1

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
@@ -39,6 +39,7 @@ html {
3939
@include mat.card-theme($light-theme);
4040
@include mat.checkbox-theme($light-theme);
4141
@include mat.form-field-theme($light-theme);
42+
@include mat.icon-theme($light-theme);
4243
@include mat.input-theme($light-theme);
4344
@include mat.list-theme($light-theme);
4445
@include mat.progress-bar-theme($light-theme);
@@ -66,6 +67,7 @@ html {
6667
@include mat.card-color($dark-theme);
6768
@include mat.checkbox-color($dark-theme);
6869
@include mat.form-field-color($dark-theme);
70+
@include mat.icon-color($dark-theme);
6971
@include mat.input-color($dark-theme);
7072
@include mat.list-color($dark-theme);
7173
@include mat.progress-bar-color($dark-theme);
@@ -92,6 +94,7 @@ html {
9294
@include mat.card-density($scale-theme);
9395
@include mat.checkbox-density($scale-theme);
9496
@include mat.form-field-density($scale-theme);
97+
@include mat.icon-density($scale-theme);
9598
@include mat.input-density($scale-theme);
9699
@include mat.list-density($scale-theme);
97100
@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
@@ -62,6 +62,16 @@
6262
);
6363
}
6464

65+
/// Generates custom tokens for the mat-icon.
66+
/// @param {Map} $systems The MDC system tokens
67+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
68+
/// @return {Map} A set of custom tokens for the mat-icon
69+
@function icon($systems, $exclude-hardcoded) {
70+
@return (
71+
color: _hardcode(inherit, $exclude-hardcoded),
72+
);
73+
}
74+
6575
/// Generates custom tokens for the mat-toolbar.
6676
/// @param {Map} $systems The MDC system tokens
6777
/// @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
@@ -45,6 +45,7 @@ $_density-tokens: (
4545
// Custom Angular Material tokens
4646
(mat, card): (),
4747
(mat, form-fild): (),
48+
(mat, icon): (),
4849
(mat, toolbar): (
4950
standard-height: (64px, 60px, 56px, 52px),
5051
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
@@ -259,6 +259,11 @@
259259
custom-tokens.form-field($systems, $exclude-hardcoded),
260260
$token-slots
261261
),
262+
_namespace-tokens(
263+
(mat, icon),
264+
custom-tokens.icon($systems, $exclude-hardcoded),
265+
$token-slots
266+
),
262267
_namespace-tokens(
263268
(mat, toolbar),
264269
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
@@ -3,6 +3,7 @@
33
@use '../../style/sass-utils';
44
@use './mat/card' as tokens-mat-card;
55
@use './mat/form-field' as tokens-mat-form-field;
6+
@use './mat/icon' as tokens-mat-icon;
67
@use './mat/radio' as tokens-mat-radio;
78
@use './mat/ripple' as tokens-mat-ripple;
89
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
@@ -78,6 +79,7 @@
7879
@return sass-utils.deep-merge-all(
7980
_get-tokens-for-module($theme, tokens-mat-card),
8081
_get-tokens-for-module($theme, tokens-mat-form-field),
82+
_get-tokens-for-module($theme, tokens-mat-icon),
8183
_get-tokens-for-module($theme, tokens-mat-radio),
8284
_get-tokens-for-module($theme, tokens-mat-ripple),
8385
_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)