@angular/material-experimental 16.2.1 → 17.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,10 @@
1
1
  @use 'sass:map';
2
2
  @use '@angular/material' as mat;
3
3
  @use '@material/tokens/v0_161' as mdc-tokens;
4
+ @use './m3-density';
5
+ @use './custom-tokens';
6
+
7
+ // TODO(mmalerba): Split up this file into smaller pieces.
4
8
 
5
9
  /// Picks a submap containing only the given keys out the given map.
6
10
  /// @param {Map} $map The map to pick from.
@@ -29,49 +33,82 @@
29
33
  @return $result;
30
34
  }
31
35
 
36
+ /// Renames the keys in a map
37
+ /// @param {Map} $map The map whose keys should be renamed
38
+ /// @param {Map} $rename-keys A map of original key to renamed key to apply to $map
39
+ /// @return {Map} The result of applying the given key renames to the given map.
40
+ @function _rename-map-keys($map, $rename-keys) {
41
+ $result: $map;
42
+ @each $old-key-name, $new-key-name in $rename-keys {
43
+ @if map.has-key($map, $old-key-name) {
44
+ $result: map.set($result, $new-key-name, map.get($map, $old-key-name));
45
+ }
46
+ }
47
+ @return $result;
48
+ }
49
+
32
50
  /// Gets the MDC tokens for the given prefix, M3 token values, and supported token slots.
33
51
  /// @param {List} $prefix The token prefix for the given tokens.
34
52
  /// @param {Map} $m3-values A map of M3 token values for the given prefix.
35
53
  /// @param {Map} $slots A map of token slots, with null value indicating the token is not supported.
36
54
  /// @return {Map} A map of fully qualified token names to values, for only the supported tokens.
37
- @function _get-mdc-tokens($prefix, $m3-values, $slots) {
55
+ @function _namespace-tokens($prefix, $m3-values, $slots) {
38
56
  $used-token-names: map.keys(_filter-nulls(map.get($slots, $prefix)));
39
- $used-m3-tokens: _pick($m3-values, $used-token-names);
57
+ $used-m3-tokens: _pick(_filter-nulls($m3-values), $used-token-names);
40
58
  @return (
41
59
  $prefix: $used-m3-tokens,
42
60
  );
43
61
  }
44
62
 
45
- /// Sets all of the standard typography tokens for the given token base name to the given typography
46
- /// level.
47
- /// @param {Map} $typography-tokens The MDC system-typescale tokens.
48
- /// @param {String} $base-name The token base name to get the typography tokens for
49
- /// @param {String} $typography-level The typography level to base the token values on.
50
- /// @return {Map} A map containing the typography tokens for the given base token name.
51
- @function _get-typography-tokens($typography-tokens, $base-name, $typography-level) {
63
+ /// Generates tokens for the given palette with the given prefix.
64
+ /// @param {Map} $palette The palette to generate tokens for
65
+ /// @param {String} $prefix The key prefix used to name the tokens
66
+ /// @return {Map} A set of tokens for the given palette
67
+ @function _generate-palette-tokens($palette, $prefix) {
68
+ $palette: map.remove($palette, neutral-variant);
52
69
  $result: ();
53
- @each $prop in (font, line-height, size, tracking, weight) {
54
- $result: map.set(
55
- $result,
56
- #{$base-name}-#{$prop},
57
- map.get($typography-tokens, #{$typography-level}-#{$prop}
58
- ));
70
+ @each $hue, $value in $palette {
71
+ $result: map.set($result, '#{$prefix}#{$hue}', $value);
59
72
  }
60
73
  @return $result;
61
74
  }
62
75
 
63
- /// Renames the keys in a map
64
- /// @param {Map} $map The map whose keys should be renamed
65
- /// @param {Map} $rename-keys A map of original key to renamed key to apply to $map
66
- /// @return {Map} The result of applying the given key renames to the given map.
67
- @function _rename-map-keys($map, $rename-keys) {
68
- $result: $map;
69
- @each $old-key-name, $new-key-name in $rename-keys {
70
- @if map.has-key($map, $old-key-name) {
71
- $result: map.set($result, $new-key-name, map.get($map, $old-key-name));
72
- }
73
- }
74
- @return $result;
76
+ /// Creates a set of `md-ref-palette` tokens from the given palettes. (See
77
+ /// https://github.com/material-components/material-components-web/blob/master/packages/mdc-tokens/v0_161/_md-ref-palette.scss)
78
+ /// @param {Map} $primary The primary palette
79
+ /// @param {Map} $secondary The secondary palette
80
+ /// @param {Map} $tertiary The tertiary palette
81
+ /// @param {Map} $neutral The neutral palette
82
+ /// @param {Map} $error The error palette
83
+ /// @return {Map} A set of `md-ref-palette` tokens
84
+ @function _generate-ref-palette-tokens($primary, $secondary, $tertiary, $neutral, $error) {
85
+ @return mat.private-merge-all(
86
+ (black: #000, white: #fff),
87
+ _generate-palette-tokens($primary, primary),
88
+ _generate-palette-tokens($secondary, secondary),
89
+ _generate-palette-tokens($tertiary, tertiary),
90
+ _generate-palette-tokens($neutral, neutral),
91
+ _generate-palette-tokens(map.get($primary, neutral-variant), neutral-variant),
92
+ _generate-palette-tokens($error, error),
93
+ );
94
+ }
95
+
96
+ /// Creates a set of `md-ref-typeface` tokens from the given palettes. (See
97
+ /// https://github.com/material-components/material-components-web/blob/master/packages/mdc-tokens/v0_161/_md-ref-typeface.scss)
98
+ /// @param {List|String} $brand The font-family to use for brand text
99
+ /// @param {List|String} $plain The font-family to use for plain text
100
+ /// @param {String} $bold The font-weight to use for bold text
101
+ /// @param {String} $medium The font-weight to use for medium text
102
+ /// @param {String} $regular The font-weight to use for regular text
103
+ /// @return {Map} A set of `md-ref-typeface` tokens
104
+ @function _generate-ref-typeface-tokens($brand, $plain, $bold, $medium, $regular) {
105
+ @return (
106
+ brand: $brand,
107
+ plain: $plain,
108
+ weight-bold: $bold,
109
+ weight-medium: $medium,
110
+ weight-regular: $regular,
111
+ );
75
112
  }
76
113
 
77
114
  /// Renames the official checkbox tokens to match the names actually used in MDC's code (which are
@@ -79,38 +116,44 @@
79
116
  /// tokens.
80
117
  /// @param {Map} $tokens The map of checkbox tokens with the official tokens names
81
118
  /// @return {Map} The given tokens, renamed to be compatible with MDC's token implementation.
82
- @function _fix-checkbox-token-names($tokens) {
119
+ @function _fix-checkbox-tokens($tokens) {
83
120
  $rename-keys: (
84
- 'selected-icon-color': 'selected-checkmark-color',
85
- 'selected-disabled-icon-color': 'disabled-selected-checkmark-color',
86
- 'selected-container-color': 'selected-icon-color',
87
- 'selected-hover-container-color': 'selected-hover-icon-color',
88
- 'selected-disabled-container-color': 'disabled-selected-icon-color',
89
- 'selected-disabled-container-opacity': 'disabled-selected-icon-opacity',
90
- 'selected-focus-container-color': 'selected-focus-icon-color',
91
- 'selected-pressed-container-color': 'selected-pressed-icon-color',
92
- 'unselected-disabled-outline-color': 'disabled-unselected-icon-color',
93
- 'unselected-disabled-container-opacity': 'disabled-unselected-icon-opacity',
94
- 'unselected-focus-outline-color': 'unselected-focus-icon-color',
95
- 'unselected-hover-outline-color': 'unselected-hover-icon-color',
96
- 'unselected-outline-color': 'unselected-icon-color',
97
- 'unselected-pressed-outline-color': 'unselected-pressed-icon-color'
121
+ selected-icon-color: selected-checkmark-color,
122
+ selected-disabled-icon-color: disabled-selected-checkmark-color,
123
+ selected-container-color: selected-icon-color,
124
+ selected-hover-container-color: selected-hover-icon-color,
125
+ selected-disabled-container-color: disabled-selected-icon-color,
126
+ selected-disabled-container-opacity: disabled-selected-icon-opacity,
127
+ selected-focus-container-color: selected-focus-icon-color,
128
+ selected-pressed-container-color: selected-pressed-icon-color,
129
+ unselected-disabled-outline-color: disabled-unselected-icon-color,
130
+ unselected-disabled-container-opacity: disabled-unselected-icon-opacity,
131
+ unselected-focus-outline-color: unselected-focus-icon-color,
132
+ unselected-hover-outline-color: unselected-hover-icon-color,
133
+ unselected-outline-color: unselected-icon-color,
134
+ unselected-pressed-outline-color: unselected-pressed-icon-color
98
135
  );
99
136
  @return _rename-map-keys($tokens, $rename-keys);
100
137
  }
101
138
 
102
- // TODO(mmalerba): We need a way to accept custom M3 token values generated from MDCs theme builder
103
- // or other means. We can't just use them directly without processing them first because we need to
104
- // add our made up tokens,
105
- /// Gets the default token values for M3.
106
- /// @return The default set of M3 tokens.
107
- @function get-m3-tokens() {
108
- $typography: mdc-tokens.md-sys-typescale-values();
109
- $colors: mdc-tokens.md-sys-color-values-light();
110
-
111
- // TODO(mmalerba): Refactor this to not depend on the legacy theme. This is a hack for now because
112
- // there is no good way to get the token slots in material-experimental without exposing them all
113
- // from material.
139
+ /// Generates a set of namespaced tokens for all components.
140
+ /// @param {Map} $systems The MDC system tokens
141
+ /// @param {Boolean} $include-non-systemized Whether to include non-systemized tokens
142
+ /// @return {Map} A map of namespaced tokens
143
+ @function _generate-tokens($systems, $include-non-systemized: false) {
144
+ $systems: map.merge((
145
+ md-sys-color: (),
146
+ md-sys-elevation: (),
147
+ md-sys-motion: (),
148
+ md-sys-shape: (),
149
+ md-sys-state: (),
150
+ md-sys-typescale: ()
151
+ ), $systems);
152
+ $exclude-hardcoded: not $include-non-systemized;
153
+
154
+ // TODO(mmalerba): Refactor this to not depend on the legacy theme when moving out of
155
+ // material-experimental. This is a hack for now because there is no good way to get the token
156
+ // slots in material-experimental without exposing them all from material.
114
157
  $fake-theme: mat.define-light-theme((
115
158
  color: (
116
159
  primary: mat.define-palette(mat.$red-palette),
@@ -123,24 +166,101 @@
123
166
  $token-slots: mat.m2-tokens-from-theme($fake-theme);
124
167
 
125
168
  // TODO(mmalerba): Fill in remaining tokens.
126
- @return mat.private-merge-all(
127
- // Fill in official MDC tokens.
128
- _get-mdc-tokens((mdc, checkbox),
129
- _fix-checkbox-token-names(mdc-tokens.md-comp-checkbox-values()), $token-slots),
130
- _get-mdc-tokens((mdc, elevated-card), mdc-tokens.md-comp-elevated-card-values(),
131
- $token-slots),
132
- _get-mdc-tokens((mdc, outlined-card), mdc-tokens.md-comp-outlined-card-values(),
133
- $token-slots),
169
+ $result: mat.private-merge-all(
170
+ // Add the system color & typography tokens (so we can give users access via an API).
171
+ (
172
+ (mdc, theme): map.get($systems, md-sys-color),
173
+ (mdc, typography): map.get($systems, md-sys-typescale),
174
+ ),
175
+ // Get the official MDC component tokens
176
+ _namespace-tokens(
177
+ (mdc, checkbox),
178
+ _fix-checkbox-tokens(mdc-tokens.md-comp-checkbox-values($systems, $exclude-hardcoded)),
179
+ $token-slots
180
+ ),
181
+ _namespace-tokens(
182
+ (mdc, elevated-card),
183
+ mdc-tokens.md-comp-elevated-card-values($systems, $exclude-hardcoded),
184
+ $token-slots
185
+ ),
186
+ _namespace-tokens(
187
+ (mdc, outlined-card),
188
+ mdc-tokens.md-comp-outlined-card-values($systems, $exclude-hardcoded),
189
+ $token-slots
190
+ ),
134
191
  // Choose values for our made up tokens based on MDC system tokens or sensible hardcoded
135
192
  // values.
136
- (
137
- (mat, card): mat.private-merge-all(
138
- _get-typography-tokens($typography, title-text, title-large),
139
- _get-typography-tokens($typography, subtitle-text, title-medium),
140
- (
141
- subtitle-text-color: map.get($colors, on-surface)
142
- )
143
- )
193
+ _namespace-tokens(
194
+ (mat, card),
195
+ custom-tokens.card($systems, $exclude-hardcoded),
196
+ $token-slots
144
197
  ),
145
198
  );
199
+
200
+ // Strip out tokens that are systemized by our made up density system.
201
+ @each $namespace, $tokens in $result {
202
+ @each $token, $value in $tokens {
203
+ @if m3-density.is-systemized($namespace, $token) {
204
+ $tokens: map.remove($tokens, $token);
205
+ }
206
+ }
207
+ $result: map.set($result, $namespace, $tokens);
208
+ }
209
+ @return $result;
210
+ }
211
+
212
+ /// Generates a set of namespaced color tokens for all components.
213
+ /// @param {String} $type The type of theme system (light or dark)
214
+ /// @param {Map} $primary The primary palette
215
+ /// @param {Map} $secondary The secondary palette
216
+ /// @param {Map} $tertiary The tertiary palette
217
+ /// @param {Map} $neutral The neutral palette
218
+ /// @param {Map} $error The error palette
219
+ /// @return {Map} A map of namespaced color tokens
220
+ @function generate-color-tokens($type, $primary, $secondary, $tertiary, $neutral, $error) {
221
+ $ref: (
222
+ md-ref-palette: _generate-ref-palette-tokens($primary, $secondary, $tertiary, $neutral, $error)
223
+ );
224
+ $sys-color: if($type == dark,
225
+ mdc-tokens.md-sys-color-values-dark($ref),
226
+ mdc-tokens.md-sys-color-values-light($ref));
227
+ @return _generate-tokens((
228
+ md-sys-color: $sys-color,
229
+ md-sys-elevation: mdc-tokens.md-sys-elevation-values(),
230
+ ));
231
+ }
232
+
233
+ /// Generates a set of namespaced color tokens for all components.
234
+ /// @param {String|List} $brand The brand font-family
235
+ /// @param {String|List} $plain The plain fort-family
236
+ /// @param {String|Number} $bold The bold font-weight
237
+ /// @param {String|Number} $medium The medium font-weight
238
+ /// @param {String|Number} $regular The regular font-weight
239
+ /// @return {Map} A map of namespaced typography tokens
240
+ @function generate-typography-tokens($brand, $plain, $bold, $medium, $regular) {
241
+ $ref: (
242
+ md-ref-typeface: _generate-ref-typeface-tokens($brand, $plain, $bold, $medium, $regular)
243
+ );
244
+ @return _generate-tokens((
245
+ md-sys-typescale: mdc-tokens.md-sys-typescale-values($ref)
246
+ ));
247
+ }
248
+
249
+ /// Generates a set of namespaced density tokens for all components.
250
+ /// @param {String|Number} $scale The regular font-weight
251
+ /// @return {Map} A map of namespaced density tokens
252
+ @function generate-density-tokens($scale) {
253
+ @return m3-density.get-tokens-for-scale($scale);
254
+ }
255
+
256
+ /// Generates a set of namespaced tokens not related to color, typography, or density for all
257
+ /// components.
258
+ /// @return {Map} A map of namespaced tokens not related to color, typography, or density
259
+ @function generate-base-tokens() {
260
+ // TODO(mmalerba): Exclude density tokens once implemented.
261
+ @return _generate-tokens((
262
+ md-sys-motion: mdc-tokens.md-sys-motion-values(),
263
+ md-sys-shape: mdc-tokens.md-sys-shape-values(),
264
+ md-sys-state: mdc-tokens.md-sys-state-values(),
265
+ ), $include-non-systemized: true);
146
266
  }
@@ -0,0 +1,146 @@
1
+ @use 'sass:map';
2
+ @use '@angular/material' as mat;
3
+ @use '@material/tokens/v0_161' as mdc-tokens;
4
+
5
+ /// Picks a submap containing only the given keys out the given map.
6
+ /// @param {Map} $map The map to pick from.
7
+ /// @param {List} $keys The map keys to pick.
8
+ /// @return {Map} A submap containing only the given keys.
9
+ @function _pick($map, $keys) {
10
+ $result: ();
11
+ @each $key in $keys {
12
+ @if map.has-key($map, $key) {
13
+ $result: map.set($result, $key, map.get($map, $key));
14
+ }
15
+ }
16
+ @return $result;
17
+ }
18
+
19
+ /// Filters keys with a null value out of the map.
20
+ /// @param {Map} $map The map to filter.
21
+ /// @return {Map} The given map with all of the null keys filtered out.
22
+ @function _filter-nulls($map) {
23
+ $result: ();
24
+ @each $key, $val in $map {
25
+ @if $val != null {
26
+ $result: map.set($result, $key, $val);
27
+ }
28
+ }
29
+ @return $result;
30
+ }
31
+
32
+ /// Gets the MDC tokens for the given prefix, M3 token values, and supported token slots.
33
+ /// @param {List} $prefix The token prefix for the given tokens.
34
+ /// @param {Map} $m3-values A map of M3 token values for the given prefix.
35
+ /// @param {Map} $slots A map of token slots, with null value indicating the token is not supported.
36
+ /// @return {Map} A map of fully qualified token names to values, for only the supported tokens.
37
+ @function _get-mdc-tokens($prefix, $m3-values, $slots) {
38
+ $used-token-names: map.keys(_filter-nulls(map.get($slots, $prefix)));
39
+ $used-m3-tokens: _pick($m3-values, $used-token-names);
40
+ @return (
41
+ $prefix: $used-m3-tokens,
42
+ );
43
+ }
44
+
45
+ /// Sets all of the standard typography tokens for the given token base name to the given typography
46
+ /// level.
47
+ /// @param {Map} $typography-tokens The MDC system-typescale tokens.
48
+ /// @param {String} $base-name The token base name to get the typography tokens for
49
+ /// @param {String} $typography-level The typography level to base the token values on.
50
+ /// @return {Map} A map containing the typography tokens for the given base token name.
51
+ @function _get-typography-tokens($typography-tokens, $base-name, $typography-level) {
52
+ $result: ();
53
+ @each $prop in (font, line-height, size, tracking, weight) {
54
+ $result: map.set(
55
+ $result,
56
+ #{$base-name}-#{$prop},
57
+ map.get($typography-tokens, #{$typography-level}-#{$prop}
58
+ ));
59
+ }
60
+ @return $result;
61
+ }
62
+
63
+ /// Renames the keys in a map
64
+ /// @param {Map} $map The map whose keys should be renamed
65
+ /// @param {Map} $rename-keys A map of original key to renamed key to apply to $map
66
+ /// @return {Map} The result of applying the given key renames to the given map.
67
+ @function _rename-map-keys($map, $rename-keys) {
68
+ $result: $map;
69
+ @each $old-key-name, $new-key-name in $rename-keys {
70
+ @if map.has-key($map, $old-key-name) {
71
+ $result: map.set($result, $new-key-name, map.get($map, $old-key-name));
72
+ }
73
+ }
74
+ @return $result;
75
+ }
76
+
77
+ /// Renames the official checkbox tokens to match the names actually used in MDC's code (which are
78
+ /// different). This is a temporary workaround until MDC updates to use the correct names for the
79
+ /// tokens.
80
+ /// @param {Map} $tokens The map of checkbox tokens with the official tokens names
81
+ /// @return {Map} The given tokens, renamed to be compatible with MDC's token implementation.
82
+ @function _fix-checkbox-token-names($tokens) {
83
+ $rename-keys: (
84
+ 'selected-icon-color': 'selected-checkmark-color',
85
+ 'selected-disabled-icon-color': 'disabled-selected-checkmark-color',
86
+ 'selected-container-color': 'selected-icon-color',
87
+ 'selected-hover-container-color': 'selected-hover-icon-color',
88
+ 'selected-disabled-container-color': 'disabled-selected-icon-color',
89
+ 'selected-disabled-container-opacity': 'disabled-selected-icon-opacity',
90
+ 'selected-focus-container-color': 'selected-focus-icon-color',
91
+ 'selected-pressed-container-color': 'selected-pressed-icon-color',
92
+ 'unselected-disabled-outline-color': 'disabled-unselected-icon-color',
93
+ 'unselected-disabled-container-opacity': 'disabled-unselected-icon-opacity',
94
+ 'unselected-focus-outline-color': 'unselected-focus-icon-color',
95
+ 'unselected-hover-outline-color': 'unselected-hover-icon-color',
96
+ 'unselected-outline-color': 'unselected-icon-color',
97
+ 'unselected-pressed-outline-color': 'unselected-pressed-icon-color'
98
+ );
99
+ @return _rename-map-keys($tokens, $rename-keys);
100
+ }
101
+
102
+ // TODO(mmalerba): We need a way to accept custom M3 token values generated from MDCs theme builder
103
+ // or other means. We can't just use them directly without processing them first because we need to
104
+ // add our made up tokens,
105
+ /// Gets the default token values for M3.
106
+ /// @return The default set of M3 tokens.
107
+ @function get-m3-tokens() {
108
+ $typography: mdc-tokens.md-sys-typescale-values();
109
+ $colors: mdc-tokens.md-sys-color-values-light();
110
+
111
+ // TODO(mmalerba): Refactor this to not depend on the legacy theme. This is a hack for now because
112
+ // there is no good way to get the token slots in material-experimental without exposing them all
113
+ // from material.
114
+ $fake-theme: mat.define-light-theme((
115
+ color: (
116
+ primary: mat.define-palette(mat.$red-palette),
117
+ accent: mat.define-palette(mat.$red-palette),
118
+ warn: mat.define-palette(mat.$red-palette),
119
+ ),
120
+ typography: mat.define-typography-config(),
121
+ density: 0
122
+ ));
123
+ $token-slots: mat.m2-tokens-from-theme($fake-theme);
124
+
125
+ // TODO(mmalerba): Fill in remaining tokens.
126
+ @return mat.private-merge-all(
127
+ // Fill in official MDC tokens.
128
+ _get-mdc-tokens((mdc, checkbox),
129
+ _fix-checkbox-token-names(mdc-tokens.md-comp-checkbox-values()), $token-slots),
130
+ _get-mdc-tokens((mdc, elevated-card), mdc-tokens.md-comp-elevated-card-values(),
131
+ $token-slots),
132
+ _get-mdc-tokens((mdc, outlined-card), mdc-tokens.md-comp-outlined-card-values(),
133
+ $token-slots),
134
+ // Choose values for our made up tokens based on MDC system tokens or sensible hardcoded
135
+ // values.
136
+ (
137
+ (mat, card): mat.private-merge-all(
138
+ _get-typography-tokens($typography, title-text, title-large),
139
+ _get-typography-tokens($typography, subtitle-text, title-medium),
140
+ (
141
+ subtitle-text-color: map.get($colors, on-surface)
142
+ )
143
+ )
144
+ ),
145
+ );
146
+ }
@@ -1,9 +0,0 @@
1
- @forward '../../material/core/style/variables.import';
2
- @forward '../../material/core/theming/theming.import';
3
- @forward '../../material/core/style/vendor-prefixes.import';
4
- @forward 'column-resize-theme' as mat-column-resize-*;
5
-
6
- @import '../../material/core/style/variables';
7
- @import '../../material/core/style/vendor-prefixes';
8
- @import '../../material/core/theming/palette';
9
- @import '../../material/core/theming/theming';
@@ -1,13 +0,0 @@
1
- @forward '../../material/core/style/private.import';
2
- @forward '../../material/core/theming/theming.import';
3
- @forward '../../cdk/a11y/index.import';
4
- @forward '../../material/core/typography/typography-utils.import';
5
- @forward 'popover-edit-theme' hide color, density, theme, typography;
6
- @forward 'popover-edit-theme' as mat-popover-edit-*;
7
-
8
- @import '../../cdk/a11y';
9
- @import '../../material/core/style/variables';
10
- @import '../../material/core/style/private';
11
- @import '../../material/core/theming/palette';
12
- @import '../../material/core/theming/theming';
13
- @import '../../material/core/typography/typography-utils';
@@ -1,4 +0,0 @@
1
- @forward '../../material/core/theming/theming.import';
2
- @forward 'selection' as mat-selection-*;
3
-
4
- @import '../../material/core/theming/theming';
File without changes
File without changes
File without changes