Skip to content

Commit 9801967

Browse files
committed
feat(material-experimental/theming): add M3 icon support
1 parent 13629b0 commit 9801967

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
@@ -38,6 +38,7 @@ $dark-theme: matx.define-theme(map.set($m3-base-config, color, theme-type, dark)
3838
html {
3939
@include mat.card-theme($light-theme);
4040
@include mat.checkbox-theme($light-theme);
41+
@include mat.icon-theme($light-theme);
4142
@include mat.progress-bar-theme($light-theme);
4243
@include mat.progress-spinner-theme($light-theme);
4344
@include mat.radio-theme($light-theme);
@@ -62,6 +63,7 @@ html {
6263

6364
@include mat.card-color($dark-theme);
6465
@include mat.checkbox-color($dark-theme);
66+
@include mat.icon-color($dark-theme);
6567
@include mat.progress-bar-color($dark-theme);
6668
@include mat.progress-spinner-color($dark-theme);
6769
@include mat.radio-color($dark-theme);
@@ -85,6 +87,7 @@ html {
8587
.demo-density-#{$scale} {
8688
@include mat.card-density($scale-theme);
8789
@include mat.checkbox-density($scale-theme);
90+
@include mat.icon-density($scale-theme);
8891
@include mat.progress-bar-density($scale-theme);
8992
@include mat.progress-spinner-density($scale-theme);
9093
@include mat.radio-density($scale-theme);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
);
3636
}
3737

38+
/// Generates custom tokens for the mat-icon.
39+
/// @param {Map} $systems The MDC system tokens
40+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
41+
/// @return {Map} A set of custom tokens for the mat-icon
42+
@function icon($systems, $exclude-hardcoded) {
43+
@return (
44+
color: _hardcode(inherit, $exclude-hardcoded),
45+
);
46+
}
47+
3848
/// Generates custom tokens for the mat-toolbar.
3949
/// @param {Map} $systems The MDC system tokens
4050
/// @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
@@ -37,6 +37,7 @@ $_density-tokens: (
3737

3838
// Custom Angular Material tokens
3939
(mat, card): (),
40+
(mat, icon): (),
4041
(mat, toolbar): (
4142
standard-height: (64px, 60px, 56px, 52px),
4243
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
@@ -240,6 +240,11 @@
240240
custom-tokens.card($systems, $exclude-hardcoded),
241241
$token-slots
242242
),
243+
_namespace-tokens(
244+
(mat, icon),
245+
custom-tokens.icon($systems, $exclude-hardcoded),
246+
$token-slots
247+
),
243248
_namespace-tokens(
244249
(mat, toolbar),
245250
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
@@ -2,6 +2,7 @@
22
@use 'sass:meta';
33
@use '../../style/sass-utils';
44
@use './mat/card' as tokens-mat-card;
5+
@use './mat/icon' as tokens-mat-icon;
56
@use './mat/radio' as tokens-mat-radio;
67
@use './mat/ripple' as tokens-mat-ripple;
78
@use './mat/slide-toggle' as tokens-mat-slide-toggle;
@@ -74,6 +75,7 @@
7475
@function m2-tokens-from-theme($theme) {
7576
@return sass-utils.deep-merge-all(
7677
_get-tokens-for-module($theme, tokens-mat-card),
78+
_get-tokens-for-module($theme, tokens-mat-icon),
7779
_get-tokens-for-module($theme, tokens-mat-radio),
7880
_get-tokens-for-module($theme, tokens-mat-ripple),
7981
_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)