@acontplus/ng-components 2.1.30 → 2.1.31

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.
Files changed (54) hide show
  1. package/fesm2022/acontplus-ng-components.mjs +5713 -3552
  2. package/fesm2022/acontplus-ng-components.mjs.map +1 -1
  3. package/package.json +19 -18
  4. package/src/_index.scss +22 -0
  5. package/src/core/color/_all-color.scss +16 -0
  6. package/src/core/density/_all-density.scss +38 -0
  7. package/src/core/style/_elevation.scss +207 -0
  8. package/src/core/theming/_all-theme.scss +50 -0
  9. package/src/core/theming/_config-validation.scss +171 -0
  10. package/src/core/theming/_definition.scss +158 -0
  11. package/src/core/theming/_palettes.scss +1060 -0
  12. package/src/core/tokens/_m3-tokens.scss +141 -0
  13. package/src/core/tokens/_m3-utils.scss +36 -0
  14. package/src/core/tokens/_system.scss +395 -0
  15. package/src/core/tokens/_token-utils.scss +117 -0
  16. package/src/core/tokens/m3/_index.scss +7 -0
  17. package/src/core/tokens/m3/_md-sys-color.scss +150 -0
  18. package/src/core/tokens/m3/_md-sys-elevation.scss +8 -0
  19. package/src/core/tokens/m3/_md-sys-motion.scss +35 -0
  20. package/src/core/tokens/m3/_md-sys-shape.scss +31 -0
  21. package/src/core/tokens/m3/_md-sys-state.scss +13 -0
  22. package/src/core/tokens/m3/_md-sys-typescale.scss +131 -0
  23. package/src/core/tokens/m3/_theme.scss +41 -0
  24. package/src/core/typography/_all-typography.scss +34 -0
  25. package/src/lib/components/alert/_alert-theme.scss +57 -0
  26. package/src/lib/components/alert/_m3-alert.scss +72 -0
  27. package/src/lib/components/alert/alert.scss +60 -0
  28. package/src/lib/components/autocomplete-wrapper/autocomplete-wrapper.scss +667 -0
  29. package/src/lib/components/button/button.scss +297 -0
  30. package/src/lib/components/cards/dynamic-card/dynamic-card.scss +131 -0
  31. package/src/lib/components/data-grid/_grid-theme.scss +53 -0
  32. package/src/lib/components/data-grid/_m3-grid.scss +34 -0
  33. package/src/lib/components/data-grid/cell/cell.scss +38 -0
  34. package/src/lib/components/data-grid/column-menu/column-menu.scss +117 -0
  35. package/src/lib/components/data-grid/column-resize/_column-resize.scss +126 -0
  36. package/src/lib/components/data-grid/grid.scss +245 -0
  37. package/src/lib/components/date-range-input/calendar/date-range-calendar.scss +29 -0
  38. package/src/lib/components/date-range-input/date-range-input.scss +194 -0
  39. package/src/lib/components/dialog-wrapper/dialog-wrapper.scss +36 -0
  40. package/src/lib/components/drawer/_drawer-theme.scss +57 -0
  41. package/src/lib/components/drawer/_m3-drawer.scss +24 -0
  42. package/src/lib/components/drawer/drawer-container.scss +97 -0
  43. package/src/lib/components/icons/svg-icon/svg-icon.scss +16 -0
  44. package/src/lib/components/icons/user-icon/user-icon.scss +0 -0
  45. package/src/lib/components/input-chip/input-chip.scss +0 -0
  46. package/src/lib/components/popover/_m3-popover.scss +24 -0
  47. package/src/lib/components/popover/_popover-theme.scss +57 -0
  48. package/src/lib/components/popover/popover.scss +239 -0
  49. package/src/lib/components/spinner/spinner.scss +6 -0
  50. package/src/lib/components/tables/tabulator-table/tabulator-table.scss +68 -0
  51. package/src/lib/components/theme-toggle/theme-toggle.scss +3 -0
  52. package/src/lib/styles/_elevation.scss +168 -0
  53. package/src/lib/styles/_token-utils.scss +115 -0
  54. package/types/acontplus-ng-components.d.ts +920 -536
@@ -0,0 +1,141 @@
1
+ @use 'sass:map';
2
+ @use '@angular/material' as mat;
3
+ @use './m3';
4
+
5
+ /// Generates a set of namespaced tokens for all components.
6
+ /// @param {Map} $systems The MDC system tokens
7
+ /// @param {Boolean} $include-non-systemized Whether to include non-systemized tokens
8
+ /// @param {Boolean} $include-density Whether to include density tokens
9
+ /// @return {Map} A map of namespaced tokens
10
+ @function generate-tokens($systems, $include-non-systemized: false, $include-density: false) {
11
+ $systems: map.merge(
12
+ (
13
+ md-sys-color: (),
14
+ md-sys-elevation: (),
15
+ md-sys-motion: (),
16
+ md-sys-shape: (),
17
+ md-sys-state: (),
18
+ md-sys-typescale: (),
19
+ ),
20
+ $systems
21
+ );
22
+ $exclude-hardcoded: not $include-non-systemized;
23
+
24
+ // TODO(mmalerba): Fill in remaining tokens.
25
+ $result: mat.private-deep-merge-all(
26
+ // Add the system color & typography tokens (so we can give users access via an API).
27
+ (
28
+ (mat, theme): map.get($systems, md-sys-color),
29
+ (mat, typography): map.get($systems, md-sys-typescale),
30
+ )
31
+ );
32
+
33
+ @return $result;
34
+ }
35
+
36
+ @function create-map($keys, $prefix) {
37
+ $result: ();
38
+ @each $key in $keys {
39
+ $result: map.merge(
40
+ $result,
41
+ (
42
+ $key: var(--#{$prefix}-#{$key}),
43
+ )
44
+ );
45
+ }
46
+ @return $result;
47
+ }
48
+
49
+ @function get-sys-color($type, $palettes, $prefix) {
50
+ $sys-color: null;
51
+
52
+ @if ($type == dark) {
53
+ $sys-color: m3.md-sys-color-values-dark($palettes);
54
+ } @else {
55
+ $sys-color: m3.md-sys-color-values-light($palettes);
56
+ }
57
+
58
+ @if (mat.$private-use-system-color-variables) {
59
+ $var-values: ();
60
+ @each $key in map.keys($sys-color) {
61
+ $var-values: map.set($var-values, $key, var(--#{$prefix}-#{$key}));
62
+ }
63
+ $var-values: map.set($var-values, shadow, map.get($sys-color, shadow));
64
+ @return $var-values;
65
+ }
66
+
67
+ @return $sys-color;
68
+ }
69
+
70
+ @function get-sys-typeface($typography, $prefix) {
71
+ $sys-typography: m3.md-sys-typescale-values($typography);
72
+ @if (mat.$private-use-system-typography-variables) {
73
+ $var-values: ();
74
+ @each $key in map.keys($sys-typography) {
75
+ $var-values: map.set($var-values, $key, var(--#{$prefix}-#{$key}));
76
+ }
77
+ @return $var-values;
78
+ }
79
+
80
+ @return $sys-typography;
81
+ }
82
+
83
+ /// Generates a set of namespaced color tokens for all components.
84
+ /// @param {String} $type The type of theme system (light or dark)
85
+ /// @param {Map} $primary The primary palette
86
+ /// @param {Map} $tertiary The tertiary palette
87
+ /// @param {Map} $error The error palette
88
+ /// @param {String} $system-variables-prefix The prefix of system tokens
89
+ /// @return {Map} A map of namespaced color tokens
90
+ @function generate-color-tokens($type, $palettes, $system-variables-prefix) {
91
+ $sys-color: get-sys-color($type, $palettes, $system-variables-prefix);
92
+
93
+ @return generate-tokens(
94
+ (
95
+ md-sys-color: $sys-color,
96
+ md-ref-palette: (
97
+ neutral-10: map.get($palettes, neutral, 10),
98
+ neutral-variant20: map.get($palettes, neutral-variant, 20),
99
+ ),
100
+ // Because the elevation values are always combined with color values to create the box shadow,
101
+ // elevation needs to be part of the color dimension.
102
+ md-sys-elevation: m3.md-sys-elevation-values(),
103
+ // Because the state values are sometimes combined with color values to create rgba colors,
104
+ // state needs to be part of color dimension.
105
+ // TODO(mmalerba): If at some point we remove the need for these combined values, we can move
106
+ // state to the base dimension.
107
+ md-sys-state: m3.md-sys-state-values(),
108
+ )
109
+ );
110
+ }
111
+
112
+ /// Generates a set of namespaced color tokens for all components.
113
+ /// @param {String|List} $brand The brand font-family
114
+ /// @param {String|List} $plain The plain fort-family
115
+ /// @param {String|Number} $bold The bold font-weight
116
+ /// @param {String|Number} $medium The medium font-weight
117
+ /// @param {String|Number} $regular The regular font-weight
118
+ /// @param {String} $system-variables-prefix The prefix of system tokens
119
+ /// @return {Map} A map of namespaced typography tokens
120
+ @function generate-typography-tokens($typography, $system-variables-prefix) {
121
+ $sys-typeface: get-sys-typeface($typography, $system-variables-prefix);
122
+ @return generate-tokens(
123
+ (
124
+ md-sys-typescale: $sys-typeface,
125
+ )
126
+ );
127
+ }
128
+
129
+ /// Generates a set of namespaced tokens not related to color, typography, or density for all
130
+ /// components.
131
+ /// @return {Map} A map of namespaced tokens not related to color, typography, or density
132
+ @function generate-base-tokens() {
133
+ // TODO(mmalerba): Exclude density tokens once implemented.
134
+ @return generate-tokens(
135
+ (
136
+ md-sys-motion: m3.md-sys-motion-values(),
137
+ md-sys-shape: m3.md-sys-shape-values(),
138
+ ),
139
+ $include-non-systemized: true
140
+ );
141
+ }
@@ -0,0 +1,36 @@
1
+ @use 'sass:map';
2
+ @use 'sass:meta';
3
+ @use 'sass:string';
4
+
5
+ // Replaces color tokens in the map with those defined as the variant color.
6
+ @function replace-colors-with-variant($system, $color, $variant) {
7
+ $system: map.set($system, on-#{$color}, map.get($system, on-#{$variant}));
8
+ $system: map.set($system, on-#{$color}-container, map.get($system, on-#{$variant}-container));
9
+ $system: map.set($system, #{$color}, map.get($system, #{$variant}));
10
+ $system: map.set($system, #{$color}-container, map.get($system, #{$variant}-container));
11
+ $system: map.set($system, inverse-#{$color}, map.get($system, inverse-#{$variant}));
12
+ @return $system;
13
+ }
14
+
15
+ // Gets the theme's system values as a flat map.
16
+ @function get-system($theme) {
17
+ @return map.get($theme, _mat-system);
18
+ }
19
+
20
+ // Returns the color with an opacity value using color-mix. If the color is a variable name, it
21
+ // will wrap it with `var()`.
22
+ @function color-with-opacity($color, $opacity) {
23
+ @if (meta.type-of($color) == string and string.index($color, '--') == 1) {
24
+ $color: var($color);
25
+ }
26
+
27
+ // Opacity may be a system level value less than 1, instead of the intended
28
+ // whole percentage, e.g. 38%. Remove this support when possible.
29
+ @if (meta.type-of($opacity) == string and string.index($opacity, '--') == 1) {
30
+ $opacity: 'calc(var(#{$opacity}) * 100%)';
31
+ } @else if (meta.type-of($opacity) == number and $opacity < 1) {
32
+ $opacity: '#{$opacity * 100}%';
33
+ }
34
+
35
+ @return color-mix(in srgb, #{$color} #{$opacity}, transparent);
36
+ }
@@ -0,0 +1,395 @@
1
+ @use 'sass:list';
2
+ @use 'sass:map';
3
+ @use 'sass:meta';
4
+ @use '@angular/material' as mat;
5
+ @use '../../../../lib/components/alert/m3-alert';
6
+ // @use '../../colorpicker/m3-colorpicker';
7
+ // @use '../../datetimepicker/m3-datetimepicker';
8
+ @use '../../../../lib/components/drawer/m3-drawer';
9
+ @use '../../../../lib/components/grid/m3-grid';
10
+ // @use '../../loader/m3-loader';
11
+ @use '../../../../lib/components/popover/m3-popover';
12
+ // @use '../../progress/m3-progress';
13
+ // @use '../../select/m3-select';
14
+ // @use '../../split/m3-split';
15
+ // @use '../../tooltip/m3-tooltip';
16
+ @use '../style/elevation';
17
+ @use '../theming/config-validation';
18
+ @use '../theming/definition';
19
+ @use '../theming/palettes';
20
+ @use './m3';
21
+
22
+ /// Emits necessary CSS variables for Material's system level values for the values defined in the
23
+ /// config map. The config map can have values color, typography, and/or density.
24
+ ///
25
+ /// If the config map's color value is an Angular Material color palette, it will be used as the
26
+ /// primary and tertiary colors with a `color-scheme` theme type. Otherwise if the color value is a
27
+ /// map, it must have a `primary` value containing an Angular Material color palette, and
28
+ /// optionally a different `tertiary` palette (defaults to primary palette) and `theme-type` that
29
+ /// is either `light`, `dark`, or 'color-scheme` (defaults to `color-scheme`). Color variable
30
+ /// definitions will not be emitted if there are no color values in the config.
31
+ ///
32
+ /// If the config map's typography value is a font family string, it will be used as the
33
+ /// plain and brand font family with default bold, medium, and regular weights of 700, 500, and 400,
34
+ /// respectfully. Otherwise if the typography value is a map, it must have a `plain-family` font
35
+ /// family value, and optionally a different `brand-family` font family (defaults to the plain
36
+ /// value) and weights for `bold-weight` (default: 700), `bold-weight` (default: 500), and
37
+ /// `bold-weight` (default: 400). Typography variable definitions will not be emitted if there are
38
+ /// no typography values in the config.
39
+ ///
40
+ /// If the config map's density value is a number, it will be used as the density scale. Otherwise
41
+ /// if the density value is a map, it must have a `scale` value. Density variable definitions will
42
+ /// not be emitted if there are no density values in the config.
43
+ ///
44
+ /// The application variables emitted use the namespace prefix "--mat-sys".
45
+ /// e.g. --mat-sys-surface: #E5E5E5
46
+ ///
47
+ /// @param {Map} $config The color configuration with optional keys color, typography, or density.
48
+ @mixin theme($config, $overrides: ()) {
49
+ $color: map.get($config, color);
50
+ $color-config: null;
51
+ @if ($color) {
52
+ // validate-palette returns null if it is a valid M3 palette
53
+ $is-palette: config-validation.validate-palette($color) == null;
54
+
55
+ // Default to "color-scheme" theme type if the config's color does not provide one.
56
+ @if (not $is-palette and not map.has-key($color, theme-type)) {
57
+ $color: map.set($color, theme-type, color-scheme);
58
+ }
59
+
60
+ $color-config: $color;
61
+ @if ($is-palette) {
62
+ $color: map.set($color, tertiary, $color);
63
+ $color-config: (
64
+ definition.$internals: (
65
+ palettes: (
66
+ primary: map.remove($color, neutral, neutral-variant, secondary),
67
+ secondary: map.get($color, secondary),
68
+ tertiary: map.remove($color, neutral, neutral-variant, secondary, error),
69
+ neutral: map.get($color, neutral),
70
+ neutral-variant: map.get($color, neutral-variant),
71
+ error: map.get($color, error),
72
+ ),
73
+ theme-type: color-scheme,
74
+ ),
75
+ );
76
+ } @else {
77
+ $primary: map.get($color, primary) or palettes.$violet-palette;
78
+ $tertiary: map.get($color, tertiary) or $primary;
79
+ $color-config: (
80
+ definition.$internals: (
81
+ palettes: (
82
+ primary: map.remove($primary, neutral, neutral-variant, secondary),
83
+ secondary: map.get($primary, secondary),
84
+ tertiary: map.remove($tertiary, neutral, neutral-variant, secondary, error),
85
+ neutral: map.get($primary, neutral),
86
+ neutral-variant: map.get($primary, neutral-variant),
87
+ error: map.get($primary, error),
88
+ ),
89
+ theme-type: map.get($color, theme-type),
90
+ ),
91
+ );
92
+ }
93
+
94
+ @include system-level-colors($color-config, $overrides, definition.$system-fallback-prefix);
95
+ @include system-level-elevation($color-config, $overrides, definition.$system-fallback-prefix);
96
+ }
97
+
98
+ $typography: map.get($config, typography);
99
+ $typography-config: null;
100
+ @if ($typography) {
101
+ $plain: (Roboto, sans-serif);
102
+ $brand: $plain;
103
+ $bold: 700;
104
+ $medium: 500;
105
+ $regular: 400;
106
+ @if (meta.type-of($typography) == map) {
107
+ $plain: map.get($typography, plain-family);
108
+ $brand: map.get($typography, brand-family) or $plain;
109
+ $bold: map.get($typography, bold-weight) or $bold;
110
+ $medium: map.get($typography, medium-weight) or $medium;
111
+ $regular: map.get($typography, regular-weight) or $regular;
112
+ } @else {
113
+ $plain: $typography;
114
+ $brand: $typography;
115
+ }
116
+ $typography-config: (
117
+ definition.$internals: (
118
+ font-definition: (
119
+ plain: $plain,
120
+ brand: $brand,
121
+ bold: $bold,
122
+ medium: $medium,
123
+ regular: $regular,
124
+ ),
125
+ ),
126
+ );
127
+ @include system-level-typography(
128
+ $typography-config,
129
+ $overrides,
130
+ definition.$system-fallback-prefix
131
+ );
132
+ }
133
+
134
+ $density: map.get($config, density);
135
+ $density-config: null;
136
+ @if ($density) {
137
+ $scale: 0;
138
+ @if (meta.type-of($density) == map) {
139
+ $scale: map.get($density, scale);
140
+ } @else {
141
+ $scale: $density;
142
+ }
143
+ @if ($scale != 0) {
144
+ // Emit component-level density tokens if the scale is lower than 0. The density tokens
145
+ // do not fallback to any system-level values and must be defined if the scale is different.
146
+ $density-tokens: get-density-tokens($scale);
147
+ @each $tokens in $density-tokens {
148
+ @each $token-name, $token-value in $tokens {
149
+ --mat-#{$token-name}: #{$token-value};
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ @include system-level-shape($overrides: $overrides, $prefix: definition.$system-fallback-prefix);
156
+ @include system-level-state($overrides: $overrides, $prefix: definition.$system-fallback-prefix);
157
+ }
158
+
159
+ // Gets all density-related tokens from the components.
160
+ @function get-density-tokens($scale) {
161
+ @return (
162
+ m3-alert.get-density-tokens($scale),
163
+ m3-colorpicker.get-density-tokens($scale),
164
+ m3-datetimepicker.get-density-tokens($scale),
165
+ m3-drawer.get-density-tokens($scale),
166
+ m3-grid.get-density-tokens($scale),
167
+ m3-loader.get-density-tokens($scale),
168
+ m3-popover.get-density-tokens($scale),
169
+ m3-progress.get-density-tokens($scale),
170
+ m3-select.get-density-tokens($scale),
171
+ m3-split.get-density-tokens($scale),
172
+ m3-tooltip.get-density-tokens($scale)
173
+ );
174
+ }
175
+
176
+ /// Emits the system-level CSS variables for each of the provided override values. E.g. to
177
+ /// change the primary color to red, use `mat.theme-overrides((primary: red));`
178
+ @mixin theme-overrides($overrides, $prefix: definition.$system-fallback-prefix) {
179
+ $sys-names: map-merge-all(
180
+ m3.md-sys-color-values-light(palettes.$blue-palette),
181
+ m3.md-sys-typescale-values(
182
+ (
183
+ brand: (
184
+ Roboto,
185
+ ),
186
+ plain: (
187
+ Roboto,
188
+ ),
189
+ bold: 700,
190
+ medium: 500,
191
+ regular: 400,
192
+ )
193
+ ),
194
+ m3.md-sys-elevation-values(),
195
+ m3.md-sys-shape-values(),
196
+ m3.md-sys-state-values()
197
+ );
198
+
199
+ @include mat.private-current-selector-or-root {
200
+ @each $name, $value in $overrides {
201
+ @if (map.has-key($sys-names, $name)) {
202
+ --#{$prefix}-#{$name}: #{map.get($overrides, $name)};
203
+ }
204
+ }
205
+ }
206
+ }
207
+
208
+ @mixin system-level-colors($theme, $overrides: (), $prefix: null) {
209
+ $palettes: map.get($theme, definition.$internals, palettes);
210
+ $type: map.get($theme, definition.$internals, theme-type);
211
+
212
+ @if (not $prefix) {
213
+ $prefix: map.get($theme, definition.$internals, color-system-variables-prefix) or
214
+ definition.$system-level-prefix;
215
+ }
216
+
217
+ $sys-colors: _generate-sys-colors($palettes, $type);
218
+
219
+ // Manually insert a subset of palette values that are used directly by components
220
+ // instead of system variables.
221
+ $sys-colors: map.set($sys-colors, neutral-variant20, map.get($palettes, neutral-variant, 20));
222
+ $sys-colors: map.set($sys-colors, neutral10, map.get($palettes, neutral, 10));
223
+
224
+ @include mat.private-current-selector-or-root {
225
+ @each $name, $value in $sys-colors {
226
+ --#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
227
+ }
228
+ }
229
+ }
230
+
231
+ @function _generate-sys-colors($palettes, $type) {
232
+ $light-sys-colors: m3.md-sys-color-values-light($palettes);
233
+ @if ($type == light) {
234
+ @return $light-sys-colors;
235
+ }
236
+
237
+ $dark-sys-colors: m3.md-sys-color-values-dark($palettes);
238
+ @if ($type == dark) {
239
+ @return $dark-sys-colors;
240
+ }
241
+
242
+ @if ($type == color-scheme) {
243
+ $light-dark-sys-colors: ();
244
+ @each $name, $light-value in $light-sys-colors {
245
+ $dark-value: map.get($dark-sys-colors, $name);
246
+ $light-dark-sys-colors: map.set(
247
+ $light-dark-sys-colors,
248
+ $name,
249
+ light-dark($light-value, $dark-value)
250
+ );
251
+ }
252
+ @return $light-dark-sys-colors;
253
+ }
254
+
255
+ @error 'Unknown theme-type provided: #{$type}';
256
+ }
257
+
258
+ @mixin system-level-typography($theme, $overrides: (), $prefix: null) {
259
+ $font-definition: map.get($theme, definition.$internals, font-definition);
260
+
261
+ @if (not $prefix) {
262
+ $prefix: map.get($theme, definition.$internals, typography-system-variables-prefix) or
263
+ definition.$system-level-prefix;
264
+ }
265
+
266
+ @include mat.private-current-selector-or-root {
267
+ @each $name, $value in m3.md-sys-typescale-values($font-definition) {
268
+ --#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
269
+ }
270
+ }
271
+ }
272
+
273
+ @mixin system-level-elevation($theme, $overrides: (), $prefix: definition.$system-level-prefix) {
274
+ $shadow-color: map.get($theme, definition.$internals, palettes, neutral, 0);
275
+
276
+ @include mat.private-current-selector-or-root {
277
+ @each $name, $value in m3.md-sys-elevation-values() {
278
+ $level: map.get($overrides, $name) or $value;
279
+ $value: elevation.get-box-shadow($level, $shadow-color);
280
+
281
+ --#{$prefix}-#{$name}: #{$value};
282
+ }
283
+ }
284
+ }
285
+
286
+ @mixin system-level-shape($theme: (), $overrides: (), $prefix: definition.$system-level-prefix) {
287
+ @include mat.private-current-selector-or-root {
288
+ @each $name, $value in m3.md-sys-shape-values() {
289
+ --#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
290
+ }
291
+ }
292
+ }
293
+
294
+ @mixin system-level-state($theme: (), $overrides: (), $prefix: definition.$system-level-prefix) {
295
+ @include mat.private-current-selector-or-root {
296
+ @each $name, $value in m3.md-sys-state-values() {
297
+ --#{$prefix}-#{$name}: #{map.get($overrides, $name) or $value};
298
+ }
299
+ }
300
+ }
301
+
302
+ /// Creates a single merged map from the provided variable-length map arguments
303
+ @function map-merge-all($maps...) {
304
+ $result: ();
305
+ @each $map in $maps {
306
+ $result: map.merge($result, $map);
307
+ }
308
+ @return $result;
309
+ }
310
+
311
+ // Defines Angular Material system variables using M2 values provided by
312
+ // an M2 theme config created with `mat.m2-define-light-theme` or `mat.m2-define-dark-theme`.
313
+ //
314
+ // This enables applications to style custom components with system-level CSS
315
+ // variables instead of creating a separate component theme mixin that relies on
316
+ // the theme config.
317
+ //
318
+ // For example, use `var(--mat-sys-primary)` to get a theme's primary color instead of
319
+ // pulling it from the theme with `m2-get-color-from-palette($primary-palette, default)`.
320
+ //
321
+ // Unlike M3's `mat.theme()`, this mixin does not replace the need to call
322
+ // individual component theme mixins for Angular Material components.
323
+ @mixin m2-theme($theme-config, $overrides: ()) {
324
+ @if mat.get-theme-version($theme-config) == 1 {
325
+ @error '`m2-theme` mixin should only be called for M2 theme ' +
326
+ 'configs created with define-light-theme or define-dark-theme';
327
+ }
328
+
329
+ // Check whether any override keys do not match keys in the theme
330
+ // config system map.
331
+ $invalid-keys: ();
332
+ $config-system: map.get($theme-config, _mat-system);
333
+ @each $key, $value in $overrides {
334
+ @if (not map.has-key($config-system, $key)) {
335
+ $invalid-keys: list.append($invalid-keys, $key);
336
+ }
337
+ }
338
+ @if (list.length($invalid-keys) > 0) {
339
+ @error 'The following overrides are not valid system variables: #{$invalid-keys}. ' +
340
+ 'Valid keys are: #{map.keys($config-system)}';
341
+ }
342
+
343
+ $config: m2-inspection.get-m2-config($theme-config);
344
+
345
+ $color: map.get($config, color);
346
+ @if (m2-inspection.theme-has($theme-config, color)) {
347
+ $system-colors: null;
348
+
349
+ @if (map.get($color, is-dark)) {
350
+ $system-colors: m2.md-sys-color-values-dark($color);
351
+ } @else {
352
+ $system-colors: m2.md-sys-color-values-light($color);
353
+ }
354
+
355
+ @include _define-m2-system-vars($system-colors, $overrides);
356
+
357
+ $shadow: map.get($theme-config, _mat-system, shadow);
358
+ $system-elevations: ();
359
+ @each $name, $value in m2.md-sys-elevation-values() {
360
+ $level: map.get($overrides, $name) or $value;
361
+ $value: elevation.get-box-shadow($level, $shadow);
362
+ $system-elevations: map.set($system-elevations, $name, $value);
363
+ }
364
+ @include _define-m2-system-vars($system-elevations, $overrides);
365
+ }
366
+
367
+ $typography: map.get($config, typography);
368
+ @if ($typography) {
369
+ $system-typography: m2.md-sys-typescale-values($typography);
370
+ @include _define-m2-system-vars($system-typography, $overrides);
371
+ }
372
+
373
+ @include _define-m2-system-vars(m2.md-sys-shape-values(), $overrides);
374
+ @include _define-m2-system-vars(m2.md-sys-state-values(), $overrides);
375
+
376
+ // The icon button's color token is set to `inherit` for M2 and intended to display
377
+ // the color inherited from its parent element. This is crucial because it's unknown
378
+ // whether the icon button sits on a container with background like "surface" or "primary",
379
+ // where both may have different contrast colors like white or black.
380
+ // However, variables set to inherit AND define a fallback will always use the fallback,
381
+ // which is "on-surface-variant". This mixin now defines this value.
382
+ // To avoid this, and continue using `inherit` for the icon button color, set the color explicitly
383
+ // to the token without a fallback.
384
+ .mat-mdc-button-base.mat-mdc-icon-button:not(.mat-mdc-button-disabled) {
385
+ color: var(--mat-icon-button-icon-color);
386
+ }
387
+ }
388
+
389
+ @mixin _define-m2-system-vars($vars, $overrides) {
390
+ @include mat.private-current-selector-or-root {
391
+ @each $name, $value in $vars {
392
+ --#{definition.$system-fallback-prefix}-#{$name}: #{map.get($overrides, $name) or $value};
393
+ }
394
+ }
395
+ }
@@ -0,0 +1,117 @@
1
+ @use 'sass:list';
2
+ @use 'sass:map';
3
+ @use 'sass:string';
4
+ @use '@angular/material' as mat;
5
+
6
+ // Creates a CSS variable, including the fallback if provided.
7
+ @function _create-var($name, $fallback: null) {
8
+ @if ($fallback) {
9
+ @return var($name, $fallback);
10
+ } @else {
11
+ @return var($name);
12
+ }
13
+ }
14
+
15
+ // Returns a list of overrides for the given M3 get-tokens mixin and prefix. Each token has its
16
+ // prefix removed since the overrides API expects its absence. The returned map includes "all" for
17
+ // all override tokens, and also the subsets with keys base, color, typography, and density.
18
+ @function get-overrides($tokens, $prefix) {
19
+ $base: remove-token-prefixes(map.get($tokens, base), $prefix);
20
+ $color: remove-token-prefixes(map.get($tokens, color), $prefix);
21
+ $typography: remove-token-prefixes(map.get($tokens, typography), $prefix);
22
+ $density: remove-token-prefixes(map.get($tokens, density), $prefix);
23
+ $all: ();
24
+ @each $map in ($base, $color, $typography, $density) {
25
+ $all: map.merge($all, $map);
26
+ }
27
+
28
+ @return (all: $all, base: $base, color: $color, typography: $typography, density: $density);
29
+ }
30
+
31
+ // Removes a prefix from each component token in the provided map of prefixed tokens.
32
+ @function remove-token-prefixes($prefixed-tokens: (), $prefix) {
33
+ $tokens: ();
34
+ @each $prefixed-token, $value in $prefixed-tokens {
35
+ $token: string.slice($prefixed-token, string.length($prefix) + 2);
36
+ $tokens: map.set($tokens, $token, $value);
37
+ }
38
+ @return $tokens;
39
+ }
40
+
41
+ // Returns the token slot value.
42
+ // Accepts an optional fallback parameter to include in the CSS variable.
43
+ // If $fallback is `true`, then use the tokens map to get the fallback.
44
+ @function slot($token, $fallbacks, $fallback: null) {
45
+ // Fallbacks are a map of base, color, typography, and density tokens. To simplify
46
+ // lookup, flatten these token groups into a single map.
47
+ $fallbacks-flattened: ();
48
+ @each $tokens in map.values($fallbacks) {
49
+ @each $token, $value in $tokens {
50
+ $fallbacks-flattened: map.set($fallbacks-flattened, $token, $value);
51
+ }
52
+ }
53
+ @if not map.has-key($fallbacks-flattened, $token) {
54
+ @error 'Token #{$token} does not exist. Configured tokens are:' +
55
+ #{map.keys($fallbacks-flattened)};
56
+ }
57
+
58
+ $sys-fallback: map.get($fallbacks-flattened, $token);
59
+ @if (mat.private-is-css-var-name($sys-fallback)) {
60
+ $sys-fallback: _create-var($sys-fallback, $fallback);
61
+ }
62
+
63
+ @return _create-var(--acp-#{$token}, $sys-fallback);
64
+ }
65
+
66
+ // Outputs a map of token values as CSS variable definitions.
67
+ @mixin values($tokens) {
68
+ @include mat.private-current-selector-or-root() {
69
+ @each $key, $value in $tokens {
70
+ @if $value != null {
71
+ --acp-#{$key}: #{$value};
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ /// Emits new token values for the given token overrides.
78
+ /// Verifies that the overrides passed in are valid tokens.
79
+ /// New token values are emitted under the current selector or root.
80
+ @mixin batch-create-token-values($overrides: (), $namespace-configs) {
81
+ @include mat.private-current-selector-or-root() {
82
+ $prefixed-name-data: ();
83
+ $all-names: ();
84
+
85
+ @each $config in $namespace-configs {
86
+ $namespace: map.get($config, namespace);
87
+ $tokens: map.get(map.get($config, tokens), all);
88
+ $prefix: '';
89
+
90
+ @if (map.has-key($config, prefix)) {
91
+ $prefix: map.get($config, prefix);
92
+ }
93
+
94
+ @each $name, $value in $tokens {
95
+ $prefixed-name: $prefix + $name;
96
+ $all-names: list.append($all-names, $prefixed-name, $separator: comma);
97
+ $prefixed-name-data: map.set($prefixed-name-data, $prefixed-name, ($namespace, $name));
98
+ }
99
+ }
100
+
101
+ @each $name, $value in $overrides {
102
+ @if map.has-key($prefixed-name-data, $name) {
103
+ $data: map.get($prefixed-name-data, $name);
104
+ $namespace: list.nth($data, 1);
105
+ $name: list.nth($data, 2);
106
+ $prefixed-name: $namespace + '-' + $name;
107
+ @include values(
108
+ (
109
+ $prefixed-name: $value,
110
+ )
111
+ );
112
+ } @else {
113
+ @error #{'Invalid token name `'}#{$name}#{'`. '}#{'Valid tokens are: '}#{$all-names};
114
+ }
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,7 @@
1
+ @forward './md-sys-color';
2
+ @forward './md-sys-elevation';
3
+ @forward './md-sys-motion';
4
+ @forward './md-sys-shape';
5
+ @forward './md-sys-state';
6
+ @forward './md-sys-typescale';
7
+ @forward './theme';