|
1 | 1 | @use 'sass:map'; |
| 2 | +@use 'sass:string'; |
2 | 3 | @use '../core/style/sass-utils'; |
3 | 4 | @use '../core/theming/theming'; |
4 | 5 | @use '../core/theming/inspection'; |
5 | 6 | @use '../core/theming/validation'; |
6 | 7 | @use '../core/typography/typography'; |
7 | 8 | @use '../core/tokens/token-utils'; |
8 | | -@use '../core/tokens/m2/mat/card' as tokens-mat-card; |
9 | | -@use '../core/tokens/m2/mdc/elevated-card' as tokens-mdc-elevated-card; |
10 | | -@use '../core/tokens/m2/mdc/outlined-card' as tokens-mdc-outlined-card; |
| 9 | +@use 'm2-tokens' as m2-tokens; |
| 10 | +@use 'm3-tokens' as m3-tokens; |
11 | 11 |
|
12 | 12 | @mixin base($theme) { |
13 | 13 | @if inspection.get-theme-version($theme) == 1 { |
14 | | - @include _theme-from-tokens(inspection.get-theme-tokens($theme, base)); |
| 14 | + @include token-utils.define-token-values( |
| 15 | + m3-tokens.get-unthemable-tokens($theme) |
| 16 | + ); |
15 | 17 | } @else { |
16 | 18 | @include sass-utils.current-selector-or-root() { |
17 | | - @include token-utils.create-token-values-mixed( |
18 | | - tokens-mdc-elevated-card.$prefix, |
19 | | - tokens-mdc-elevated-card.get-unthemable-tokens() |
20 | | - ); |
21 | | - @include token-utils.create-token-values-mixed( |
22 | | - tokens-mdc-outlined-card.$prefix, |
23 | | - tokens-mdc-outlined-card.get-unthemable-tokens() |
24 | | - ); |
25 | | - @include token-utils.create-token-values-mixed( |
26 | | - tokens-mat-card.$prefix, |
27 | | - tokens-mat-card.get-unthemable-tokens() |
| 19 | + @include token-utils.define-token-values-mixed( |
| 20 | + m2-tokens.get-unthemable-tokens() |
28 | 21 | ); |
29 | 22 | } |
30 | 23 | } |
31 | 24 | } |
32 | 25 |
|
33 | 26 | @mixin color($theme) { |
34 | 27 | @if inspection.get-theme-version($theme) == 1 { |
35 | | - @include _theme-from-tokens(inspection.get-theme-tokens($theme, color)); |
| 28 | + @include token-utils.define-token-values( |
| 29 | + m3-tokens.get-color-tokens($theme) |
| 30 | + ); |
36 | 31 | } @else { |
37 | 32 | @include sass-utils.current-selector-or-root() { |
38 | | - @include token-utils.create-token-values-mixed( |
39 | | - tokens-mdc-elevated-card.$prefix, |
40 | | - tokens-mdc-elevated-card.get-color-tokens($theme) |
41 | | - ); |
42 | | - @include token-utils.create-token-values-mixed( |
43 | | - tokens-mdc-outlined-card.$prefix, |
44 | | - tokens-mdc-outlined-card.get-color-tokens($theme) |
45 | | - ); |
46 | | - @include token-utils.create-token-values-mixed( |
47 | | - tokens-mat-card.$prefix, |
48 | | - tokens-mat-card.get-color-tokens($theme) |
| 33 | + @include token-utils.define-token-values-mixed( |
| 34 | + m2-tokens.get-color-tokens($theme) |
49 | 35 | ); |
50 | 36 | } |
51 | 37 | } |
52 | 38 | } |
53 | 39 |
|
54 | 40 | @mixin typography($theme) { |
55 | 41 | @if inspection.get-theme-version($theme) == 1 { |
56 | | - @include _theme-from-tokens(inspection.get-theme-tokens($theme, typography)); |
| 42 | + @include token-utils.define-token-values( |
| 43 | + m3-tokens.get-typography-tokens($theme) |
| 44 | + ); |
57 | 45 | } @else { |
58 | 46 | @include sass-utils.current-selector-or-root() { |
59 | | - @include token-utils.create-token-values-mixed( |
60 | | - tokens-mdc-elevated-card.$prefix, |
61 | | - tokens-mdc-elevated-card.get-typography-tokens($theme) |
62 | | - ); |
63 | | - @include token-utils.create-token-values-mixed( |
64 | | - tokens-mdc-outlined-card.$prefix, |
65 | | - tokens-mdc-outlined-card.get-typography-tokens($theme) |
66 | | - ); |
67 | | - @include token-utils.create-token-values-mixed( |
68 | | - tokens-mat-card.$prefix, |
69 | | - tokens-mat-card.get-typography-tokens($theme) |
| 47 | + @include token-utils.define-token-values-mixed( |
| 48 | + m2-tokens.get-typography-tokens($theme) |
70 | 49 | ); |
71 | 50 | } |
72 | 51 | } |
73 | 52 | } |
74 | 53 |
|
75 | 54 | @mixin density($theme) { |
76 | 55 | @if inspection.get-theme-version($theme) == 1 { |
77 | | - @include _theme-from-tokens(inspection.get-theme-tokens($theme, density)); |
| 56 | + @include token-utils.define-token-values( |
| 57 | + m3-tokens.get-density-tokens($theme) |
| 58 | + ); |
78 | 59 | } @else { |
79 | 60 | @include sass-utils.current-selector-or-root() { |
80 | | - @include token-utils.create-token-values-mixed( |
81 | | - tokens-mdc-elevated-card.$prefix, |
82 | | - tokens-mdc-elevated-card.get-density-tokens($theme) |
83 | | - ); |
84 | | - @include token-utils.create-token-values-mixed( |
85 | | - tokens-mdc-outlined-card.$prefix, |
86 | | - tokens-mdc-outlined-card.get-density-tokens($theme) |
87 | | - ); |
88 | | - @include token-utils.create-token-values-mixed( |
89 | | - tokens-mat-card.$prefix, |
90 | | - tokens-mat-card.get-density-tokens($theme) |
| 61 | + @include token-utils.define-token-values-mixed( |
| 62 | + m2-tokens.get-density-tokens($theme) |
91 | 63 | ); |
92 | 64 | } |
93 | 65 | } |
|
97 | 69 | @function _define-overrides() { |
98 | 70 | @return ( |
99 | 71 | ( |
100 | | - namespace: tokens-mat-card.$prefix, |
101 | | - tokens: tokens-mat-card.get-token-slots(), |
102 | | - ), |
103 | | - ( |
104 | | - namespace: tokens-mdc-elevated-card.$prefix, |
105 | | - tokens: tokens-mdc-elevated-card.get-token-slots(), |
106 | | - prefix: 'elevated-', |
107 | | - ), |
108 | | - ( |
109 | | - namespace: tokens-mdc-outlined-card.$prefix, |
110 | | - tokens: tokens-mdc-outlined-card.get-token-slots(), |
111 | | - prefix: 'outlined-', |
| 72 | + component: card, |
| 73 | + namespace: (mat), |
| 74 | + tokens: m3-tokens.get-system-fallbacks(), |
| 75 | + overrideTransforms: $overrideTransforms, |
112 | 76 | ), |
113 | 77 | ); |
114 | 78 | } |
115 | 79 |
|
| 80 | +/// Map of override keys that should be transformed to their corresponding token name |
| 81 | +$overrideTransforms: ( |
| 82 | + elevated-container-shape: elevated-card-container-shape, |
| 83 | + outlined-container-shape: outlined-card-container-shape, |
| 84 | + outlined-outline-width: outlined-card-outline-width, |
| 85 | + elevated-container-color: elevated-card-container-color, |
| 86 | + elevated-container-elevation: elevated-card-container-elevation, |
| 87 | + outlined-container-color: outlined-card-container-color, |
| 88 | + outlined-outline-color: outlined-card-outline-color, |
| 89 | + outlined-container-elevation: outlined-card-container-elevation |
| 90 | +); |
| 91 | + |
116 | 92 | @mixin overrides($tokens: ()) { |
117 | | - @include token-utils.batch-create-token-values($tokens, _define-overrides()...); |
| 93 | + $override-tokens: (); |
| 94 | + @each $key, $value in $tokens { |
| 95 | + $token: map.get($overrideTransforms, $key) or $key; |
| 96 | + $override-tokens: map.set($override-tokens, $token, $value); |
| 97 | + } |
| 98 | + |
| 99 | + @include token-utils.batch-create-token-values($override-tokens, _define-overrides()...); |
118 | 100 | } |
119 | 101 |
|
120 | 102 | @mixin theme($theme) { |
121 | 103 | @include theming.private-check-duplicate-theme-styles($theme, 'mat-card') { |
122 | | - @if inspection.get-theme-version($theme) == 1 { |
123 | | - @include _theme-from-tokens(inspection.get-theme-tokens($theme)); |
124 | | - } @else { |
125 | | - @include base($theme); |
126 | | - @if inspection.theme-has($theme, color) { |
127 | | - @include color($theme); |
128 | | - } |
129 | | - @if inspection.theme-has($theme, density) { |
130 | | - @include density($theme); |
131 | | - } |
132 | | - @if inspection.theme-has($theme, typography) { |
133 | | - @include typography($theme); |
134 | | - } |
| 104 | + @include base($theme); |
| 105 | + @if inspection.theme-has($theme, color) { |
| 106 | + @include color($theme); |
| 107 | + } |
| 108 | + @if inspection.theme-has($theme, density) { |
| 109 | + @include density($theme); |
| 110 | + } |
| 111 | + @if inspection.theme-has($theme, typography) { |
| 112 | + @include typography($theme); |
135 | 113 | } |
136 | | - } |
137 | | -} |
138 | | - |
139 | | -@mixin _theme-from-tokens($tokens) { |
140 | | - @include validation.selector-defined( |
141 | | - 'Calls to Angular Material theme mixins with an M3 theme must be wrapped in a selector' |
142 | | - ); |
143 | | - @if ($tokens != ()) { |
144 | | - @include token-utils.create-token-values( |
145 | | - tokens-mdc-elevated-card.$prefix, |
146 | | - map.get($tokens, tokens-mdc-elevated-card.$prefix) |
147 | | - ); |
148 | | - @include token-utils.create-token-values( |
149 | | - tokens-mdc-outlined-card.$prefix, |
150 | | - map.get($tokens, tokens-mdc-outlined-card.$prefix) |
151 | | - ); |
152 | | - @include token-utils.create-token-values( |
153 | | - tokens-mat-card.$prefix, |
154 | | - map.get($tokens, tokens-mat-card.$prefix) |
155 | | - ); |
156 | 114 | } |
157 | 115 | } |
0 commit comments