@angular/material 16.0.1 → 16.0.3

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 (115) hide show
  1. package/_index.scss +4 -4
  2. package/button/index.d.ts +3 -2
  3. package/checkbox/_checkbox-theme.scss +9 -3
  4. package/core/mdc-helpers/_mdc-helpers.scss +13 -28
  5. package/core/style/_sass-utils.scss +7 -0
  6. package/core/tokens/_token-utils.scss +2 -2
  7. package/core/tokens/m2/mdc/_linear-progress.scss +3 -5
  8. package/core/typography/_all-typography.scss +1 -154
  9. package/core/typography/_typography.scss +162 -0
  10. package/esm2022/autocomplete/autocomplete.mjs +3 -3
  11. package/esm2022/button/button-base.mjs +7 -11
  12. package/esm2022/button/button.mjs +3 -3
  13. package/esm2022/button/fab.mjs +5 -5
  14. package/esm2022/button/icon-button.mjs +3 -3
  15. package/esm2022/checkbox/checkbox.mjs +2 -2
  16. package/esm2022/chips/chip-grid.mjs +2 -2
  17. package/esm2022/chips/chip-listbox.mjs +5 -5
  18. package/esm2022/chips/chip-option.mjs +3 -3
  19. package/esm2022/chips/chip-set.mjs +2 -2
  20. package/esm2022/core/version.mjs +1 -1
  21. package/esm2022/datepicker/calendar-body.mjs +29 -16
  22. package/esm2022/datepicker/datepicker-toggle.mjs +3 -3
  23. package/esm2022/icon/testing/icon-harness.mjs +7 -2
  24. package/esm2022/legacy-autocomplete/autocomplete.mjs +3 -3
  25. package/esm2022/legacy-chips/chip-list.mjs +3 -3
  26. package/esm2022/legacy-core/option/optgroup.mjs +3 -3
  27. package/esm2022/legacy-form-field/form-field.mjs +3 -3
  28. package/esm2022/legacy-menu/menu-item.mjs +3 -3
  29. package/esm2022/legacy-menu/menu.mjs +3 -3
  30. package/esm2022/legacy-paginator/paginator.mjs +3 -3
  31. package/esm2022/legacy-select/select.mjs +3 -3
  32. package/esm2022/legacy-table/table.mjs +3 -3
  33. package/esm2022/legacy-tabs/tab-group.mjs +3 -3
  34. package/esm2022/list/list-base.mjs +2 -1
  35. package/esm2022/menu/menu-item.mjs +3 -3
  36. package/esm2022/menu/menu.mjs +3 -3
  37. package/esm2022/paginator/paginator.mjs +3 -3
  38. package/esm2022/progress-bar/progress-bar.mjs +2 -2
  39. package/esm2022/select/select.mjs +5 -5
  40. package/esm2022/sidenav/drawer.mjs +7 -7
  41. package/esm2022/sidenav/sidenav.mjs +7 -7
  42. package/esm2022/slide-toggle/slide-toggle.mjs +3 -3
  43. package/esm2022/slider/slider-input.mjs +21 -9
  44. package/esm2022/stepper/stepper.mjs +3 -3
  45. package/esm2022/table/row.mjs +2 -2
  46. package/esm2022/table/table.mjs +3 -3
  47. package/esm2022/tabs/tab-group.mjs +3 -3
  48. package/esm2022/tooltip/tooltip.mjs +5 -1
  49. package/fesm2022/autocomplete.mjs +2 -2
  50. package/fesm2022/autocomplete.mjs.map +1 -1
  51. package/fesm2022/button.mjs +14 -18
  52. package/fesm2022/button.mjs.map +1 -1
  53. package/fesm2022/checkbox.mjs +2 -2
  54. package/fesm2022/checkbox.mjs.map +1 -1
  55. package/fesm2022/chips.mjs +10 -10
  56. package/fesm2022/chips.mjs.map +1 -1
  57. package/fesm2022/core.mjs +1 -1
  58. package/fesm2022/core.mjs.map +1 -1
  59. package/fesm2022/datepicker.mjs +30 -17
  60. package/fesm2022/datepicker.mjs.map +1 -1
  61. package/fesm2022/icon/testing.mjs +6 -1
  62. package/fesm2022/icon/testing.mjs.map +1 -1
  63. package/fesm2022/legacy-autocomplete.mjs +2 -2
  64. package/fesm2022/legacy-autocomplete.mjs.map +1 -1
  65. package/fesm2022/legacy-chips.mjs +2 -2
  66. package/fesm2022/legacy-chips.mjs.map +1 -1
  67. package/fesm2022/legacy-core.mjs +2 -2
  68. package/fesm2022/legacy-core.mjs.map +1 -1
  69. package/fesm2022/legacy-form-field.mjs +2 -2
  70. package/fesm2022/legacy-form-field.mjs.map +1 -1
  71. package/fesm2022/legacy-menu.mjs +4 -4
  72. package/fesm2022/legacy-menu.mjs.map +1 -1
  73. package/fesm2022/legacy-paginator.mjs +2 -2
  74. package/fesm2022/legacy-paginator.mjs.map +1 -1
  75. package/fesm2022/legacy-select.mjs +2 -2
  76. package/fesm2022/legacy-select.mjs.map +1 -1
  77. package/fesm2022/legacy-table.mjs +2 -2
  78. package/fesm2022/legacy-table.mjs.map +1 -1
  79. package/fesm2022/legacy-tabs.mjs +2 -2
  80. package/fesm2022/legacy-tabs.mjs.map +1 -1
  81. package/fesm2022/list.mjs +1 -0
  82. package/fesm2022/list.mjs.map +1 -1
  83. package/fesm2022/menu.mjs +4 -4
  84. package/fesm2022/menu.mjs.map +1 -1
  85. package/fesm2022/paginator.mjs +2 -2
  86. package/fesm2022/paginator.mjs.map +1 -1
  87. package/fesm2022/progress-bar.mjs +2 -2
  88. package/fesm2022/progress-bar.mjs.map +1 -1
  89. package/fesm2022/select.mjs +4 -4
  90. package/fesm2022/select.mjs.map +1 -1
  91. package/fesm2022/sidenav.mjs +12 -12
  92. package/fesm2022/sidenav.mjs.map +1 -1
  93. package/fesm2022/slide-toggle.mjs +2 -2
  94. package/fesm2022/slide-toggle.mjs.map +1 -1
  95. package/fesm2022/slider.mjs +20 -8
  96. package/fesm2022/slider.mjs.map +1 -1
  97. package/fesm2022/stepper.mjs +2 -2
  98. package/fesm2022/stepper.mjs.map +1 -1
  99. package/fesm2022/table.mjs +3 -3
  100. package/fesm2022/table.mjs.map +1 -1
  101. package/fesm2022/tabs.mjs +2 -2
  102. package/fesm2022/tabs.mjs.map +1 -1
  103. package/fesm2022/tooltip.mjs +4 -0
  104. package/fesm2022/tooltip.mjs.map +1 -1
  105. package/list/index.d.ts +2 -1
  106. package/package.json +49 -49
  107. package/prebuilt-themes/deeppurple-amber.css +1 -1
  108. package/prebuilt-themes/indigo-pink.css +1 -1
  109. package/prebuilt-themes/pink-bluegrey.css +1 -1
  110. package/prebuilt-themes/purple-green.css +1 -1
  111. package/schematics/ng-add/index.js +1 -1
  112. package/schematics/ng-add/index.mjs +1 -1
  113. package/slider/index.d.ts +10 -1
  114. package/table/index.d.ts +1 -1
  115. package/tooltip/index.d.ts +4 -0
package/_index.scss CHANGED
@@ -9,8 +9,9 @@
9
9
  $amber-palette, $orange-palette, $deep-orange-palette, $brown-palette, $grey-palette,
10
10
  $gray-palette, $blue-grey-palette, $blue-gray-palette, $light-theme-background-palette,
11
11
  $dark-theme-background-palette, $light-theme-foreground-palette, $dark-theme-foreground-palette;
12
- @forward './core/typography/typography' show define-typography-level,
13
- define-legacy-typography-config, legacy-typography-hierarchy, typography-hierarchy;
12
+ @forward './core/typography/typography' show define-typography-level, define-rem-typography-config,
13
+ define-typography-config, typography-hierarchy, define-legacy-typography-config,
14
+ legacy-typography-hierarchy;
14
15
  @forward './core/typography/typography-utils' show typography-level,
15
16
  font-size, line-height, font-weight, letter-spacing, font-family, font-shorthand;
16
17
 
@@ -48,8 +49,7 @@
48
49
  // Theme bundles
49
50
  @forward './core/theming/all-theme' show all-component-themes;
50
51
  @forward './core/color/all-color' show all-component-colors;
51
- @forward './core/typography/all-typography' show all-component-typographies,
52
- define-rem-typography-config, define-typography-config;
52
+ @forward './core/typography/all-typography' show all-component-typographies;
53
53
  @forward './legacy-core/theming/all-theme' show all-legacy-component-themes;
54
54
  @forward './legacy-core/color/all-color' show all-legacy-component-colors;
55
55
  @forward './legacy-core/typography/all-typography' show all-legacy-component-typographies;
package/button/index.d.ts CHANGED
@@ -12,6 +12,7 @@ import * as i4 from '@angular/material/core';
12
12
  import { InjectionToken } from '@angular/core';
13
13
  import { MatRipple } from '@angular/material/core';
14
14
  import { NgZone } from '@angular/core';
15
+ import { OnChanges } from '@angular/core';
15
16
  import { OnDestroy } from '@angular/core';
16
17
  import { OnInit } from '@angular/core';
17
18
  import { Platform } from '@angular/cdk/platform';
@@ -94,7 +95,7 @@ export declare class MatButton extends MatButtonBase {
94
95
  }
95
96
 
96
97
  /** Base class for all buttons. */
97
- declare class MatButtonBase extends _MatButtonMixin implements CanDisable, CanColor, CanDisableRipple, AfterViewInit, OnDestroy {
98
+ declare class MatButtonBase extends _MatButtonMixin implements CanDisable, CanColor, CanDisableRipple, AfterViewInit, OnChanges, OnDestroy {
98
99
  _platform: Platform;
99
100
  _ngZone: NgZone;
100
101
  _animationMode?: string | undefined;
@@ -117,12 +118,12 @@ declare class MatButtonBase extends _MatButtonMixin implements CanDisable, CanCo
117
118
  protected _ripple?: MatRipple;
118
119
  constructor(elementRef: ElementRef, _platform: Platform, _ngZone: NgZone, _animationMode?: string | undefined);
119
120
  ngAfterViewInit(): void;
121
+ ngOnChanges(): void;
120
122
  ngOnDestroy(): void;
121
123
  /** Focuses the button. */
122
124
  focus(_origin?: FocusOrigin, options?: FocusOptions): void;
123
125
  /** Gets whether the button has one of the given attributes. */
124
126
  private _hasHostAttributes;
125
- _isRippleDisabled(): void;
126
127
  static ɵfac: i0.ɵɵFactoryDeclaration<MatButtonBase, never>;
127
128
  static ɵdir: i0.ɵɵDirectiveDeclaration<MatButtonBase, never, never, {}, {}, never, never, false, never>;
128
129
  }
@@ -1,6 +1,7 @@
1
1
  @use 'sass:map';
2
2
  @use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
3
3
  @use '@material/form-field' as mdc-form-field;
4
+ @use '../core/style/sass-utils';
4
5
  @use '../core/theming/theming';
5
6
  @use '../core/typography/typography';
6
7
  @use '../core/mdc-helpers/mdc-helpers';
@@ -12,9 +13,11 @@
12
13
  $warn: map.get($config, warn);
13
14
  $foreground: map.get($config, foreground);
14
15
 
15
- .mat-mdc-checkbox {
16
+ @include sass-utils.current-selector-or-root() {
16
17
  @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($config));
18
+ }
17
19
 
20
+ .mat-mdc-checkbox {
18
21
  &.mat-primary {
19
22
  $primary-config: map.merge($config, (accent: $primary));
20
23
  @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-color-tokens($primary-config));
@@ -40,9 +43,12 @@
40
43
  @mixin typography($config-or-theme) {
41
44
  $config: typography.private-typography-to-2018-config(
42
45
  theming.get-typography-config($config-or-theme));
43
- .mat-mdc-checkbox {
46
+
47
+ @include sass-utils.current-selector-or-root() {
44
48
  @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-typography-tokens($config));
49
+ }
45
50
 
51
+ .mat-mdc-checkbox {
46
52
  @include mdc-helpers.using-mdc-typography($config) {
47
53
  // TODO(mmalerba): Switch to static-styles, theme-styles, and theme once they're available.
48
54
  @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query);
@@ -53,7 +59,7 @@
53
59
  @mixin density($config-or-theme) {
54
60
  $density-scale: theming.get-density-config($config-or-theme);
55
61
 
56
- .mat-mdc-checkbox {
62
+ @include sass-utils.current-selector-or-root() {
57
63
  @include mdc-checkbox-theme.theme(tokens-mdc-checkbox.get-density-tokens($density-scale));
58
64
  }
59
65
 
@@ -83,21 +83,6 @@ $mat-typography-mdc-level-mappings: (
83
83
  @return $mdc-config;
84
84
  }
85
85
 
86
- // Converts an MDC typography level config to an Angular Material one.
87
- @function typography-config-level-from-mdc($mdc-level, $font-family: null) {
88
- $mdc-level-config: map.get(mdc-typography.$styles, $mdc-level);
89
-
90
- // Explicitly default the font family to null since we'll apply it globally
91
- // through the `define-typgraphy-config`/`define-legacy-typography-config`.
92
- @return typography.define-typography-level(
93
- $font-family: $font-family,
94
- $font-size: map.get($mdc-level-config, font-size),
95
- $line-height: map.get($mdc-level-config, line-height),
96
- $font-weight: map.get($mdc-level-config, font-weight),
97
- $letter-spacing: map.get($mdc-level-config, letter-spacing)
98
- );
99
- }
100
-
101
86
  // MDC logs a warning if the `contrast-tone` function is called with a CSS variable.
102
87
  // This function falls back to determining the tone based on whether the theme is light or dark.
103
88
  @function _variable-safe-contrast-tone($value, $is-dark) {
@@ -238,19 +223,19 @@ $mat-typography-mdc-level-mappings: (
238
223
  $font-family: mdc-typography.$font-family;
239
224
  @return (
240
225
  font-family: $font-family,
241
- headline-1: typography-config-level-from-mdc(headline1, $font-family),
242
- headline-2: typography-config-level-from-mdc(headline2, $font-family),
243
- headline-3: typography-config-level-from-mdc(headline3, $font-family),
244
- headline-4: typography-config-level-from-mdc(headline4, $font-family),
245
- headline-5: typography-config-level-from-mdc(headline5, $font-family),
246
- headline-6: typography-config-level-from-mdc(headline6, $font-family),
247
- subtitle-1: typography-config-level-from-mdc(subtitle1, $font-family),
248
- subtitle-2: typography-config-level-from-mdc(subtitle2, $font-family),
249
- body-1: typography-config-level-from-mdc(body1, $font-family),
250
- body-2: typography-config-level-from-mdc(body2, $font-family),
251
- caption: typography-config-level-from-mdc(caption, $font-family),
252
- button: typography-config-level-from-mdc(button, $font-family),
253
- overline: typography-config-level-from-mdc(overline, $font-family),
226
+ headline-1: typography.typography-config-level-from-mdc(headline1, $font-family),
227
+ headline-2: typography.typography-config-level-from-mdc(headline2, $font-family),
228
+ headline-3: typography.typography-config-level-from-mdc(headline3, $font-family),
229
+ headline-4: typography.typography-config-level-from-mdc(headline4, $font-family),
230
+ headline-5: typography.typography-config-level-from-mdc(headline5, $font-family),
231
+ headline-6: typography.typography-config-level-from-mdc(headline6, $font-family),
232
+ subtitle-1: typography.typography-config-level-from-mdc(subtitle1, $font-family),
233
+ subtitle-2: typography.typography-config-level-from-mdc(subtitle2, $font-family),
234
+ body-1: typography.typography-config-level-from-mdc(body1, $font-family),
235
+ body-2: typography.typography-config-level-from-mdc(body2, $font-family),
236
+ caption: typography.typography-config-level-from-mdc(caption, $font-family),
237
+ button: typography.typography-config-level-from-mdc(button, $font-family),
238
+ overline: typography.typography-config-level-from-mdc(overline, $font-family),
254
239
  );
255
240
  }
256
241
 
@@ -0,0 +1,7 @@
1
+ // Include content under the current selector (&) or the document root if there is no current
2
+ // selector.
3
+ @mixin current-selector-or-root($root: html) {
4
+ @at-root #{& or $root} {
5
+ @content;
6
+ }
7
+ }
@@ -3,9 +3,9 @@
3
3
  @use '@material/theme/custom-properties' as mdc-custom-properties;
4
4
  @use '@material/theme/theme' as mdc-theme;
5
5
  @use '@material/theme/keys' as mdc-keys;
6
- @use '../mdc-helpers/mdc-helpers';
7
6
  @use '../theming/palette';
8
7
  @use '../theming/theming';
8
+ @use '../typography/typography';
9
9
 
10
10
  $_placeholder-color-palette: theming.define-palette(palette.$red-palette);
11
11
 
@@ -20,7 +20,7 @@ $placeholder-color-config: (
20
20
  background: palette.$light-theme-background-palette,
21
21
  );
22
22
 
23
- $_placeholder-typography-level-config: mdc-helpers.typography-config-level-from-mdc(body1);
23
+ $_placeholder-typography-level-config: typography.typography-config-level-from-mdc(body1);
24
24
 
25
25
  // Placeholder typography config that can be passed to token getter functions when generating token
26
26
  // slots.
@@ -17,13 +17,11 @@ $prefix: (mdc, linear-progress);
17
17
  $height: 4px;
18
18
 
19
19
  @return (
20
- // The height of the progress bar. MDC has three tokens with the goal
21
- // of having `track-height` apply only to the track. In our case, all three
22
- // are always the same. Specify all three while the transition is in
23
- // progress.
20
+ // The height of the progress bar. `active-indicator-height` applies to the
21
+ // bar and `track-height` applies to the track.
24
22
  active-indicator-height: $height,
25
- bar-and-track-height: $height,
26
23
  track-height: $height,
24
+ track-shape: 0,
27
25
  );
28
26
  }
29
27
 
@@ -1,7 +1,3 @@
1
- @use '@material/typography' as mdc-typography;
2
- @use 'sass:map';
3
- @use 'sass:math';
4
- @use 'sass:meta';
5
1
  @use './typography';
6
2
  @use '../../autocomplete/autocomplete-theme';
7
3
  @use '../../badge/badge-theme';
@@ -41,155 +37,6 @@
41
37
  @use '../../tree/tree-theme';
42
38
  @use '../theming/theming';
43
39
  @use '../core-theme';
44
- @use '../mdc-helpers/mdc-helpers';
45
-
46
- // TODO(mmalerba): define-mdc-typography-config is defined here rather than in _typography.scss
47
- // (where define-typography-config is defined) because putting it there would cause a circular
48
- // dependency with mdc-helpers. We should refactor so these can live in the same place.
49
-
50
- // Converts a map containing rem values to a map containing px values.
51
- @function _rem-to-px($x, $px-per-rem: 16px) {
52
- @if meta.type-of($x) == 'map' {
53
- @each $key, $val in $x {
54
- $x: map.merge($x, ($key: _rem-to-px($val)));
55
- }
56
- @return $x;
57
- }
58
- @if meta.type-of($x) == 'number' and math.unit($x) == 'rem' {
59
- @return math.div($x, 1rem) * $px-per-rem;
60
- }
61
- @else {
62
- @return $x;
63
- }
64
- }
65
-
66
- // Applies the default font family to all levels in a typography config.
67
- @function _apply-font-family($font-family, $initial-config) {
68
- $config: $initial-config;
69
-
70
- @each $key, $level in $config {
71
- @if map.get($level, 'font-family') == null {
72
- // Sass maps are immutable so we have to re-assign the variable each time.
73
- $config: map.set($config, $key, map.set($level, 'font-family', $font-family));
74
- }
75
- }
76
-
77
- @return map.set($config, 'font-family', $font-family);
78
- }
79
-
80
- /// Generates an Angular Material typography config based on values from the official Material
81
- /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
82
- /// the default values. The `mat-typography-level` function can be used to generate a custom
83
- /// typography level map which can be passed to this function to override one of the default levels.
84
- /// All default typography sizing generated by this function is in `px` units.
85
- ///
86
- /// @param {String} $font-family The font family to use for levels where it is not explicitly
87
- /// specified.
88
- /// @param {Map} $headline-1 The font settings for the headline-1 font level.
89
- /// @param {Map} $headline-2 The font settings for the headline-2 font level.
90
- /// @param {Map} $headline-3 The font settings for the headline-3 font level.
91
- /// @param {Map} $headline-4 The font settings for the headline-4 font level.
92
- /// @param {Map} $headline-5 The font settings for the headline-5 font level.
93
- /// @param {Map} $headline-6 The font settings for the headline-6 font level.
94
- /// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level.
95
- /// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level.
96
- /// @param {Map} $body-1 The font settings for the body-1 font level.
97
- /// @param {Map} $body-2 The font settings for the body-2 font level.
98
- /// @param {Map} $caption The font settings for the caption font level.
99
- /// @param {Map} $button The font settings for the button font level.
100
- /// @param {Map} $overline The font settings for the overline font level.
101
- /// @return {Map} A map containing font settings for each of the levels in the Material Design spec.
102
- @function define-typography-config(
103
- // TODO(mmalerba): rename this function to define-typography-config,
104
- // and create a predefined px based config for people that need it.
105
- $font-family: mdc-typography.$font-family,
106
- $headline-1: null,
107
- $headline-2: null,
108
- $headline-3: null,
109
- $headline-4: null,
110
- $headline-5: null,
111
- $headline-6: null,
112
- $subtitle-1: null,
113
- $subtitle-2: null,
114
- $body-1: null,
115
- $body-2: null,
116
- $caption: null,
117
- $button: null,
118
- $overline: null,
119
- ) {
120
- @return _apply-font-family($font-family, (
121
- headline-1: $headline-1 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(headline1)),
122
- headline-2: $headline-2 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(headline2)),
123
- headline-3: $headline-3 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(headline3)),
124
- headline-4: $headline-4 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(headline4)),
125
- headline-5: $headline-5 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(headline5)),
126
- headline-6: $headline-6 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(headline6)),
127
- subtitle-1: $subtitle-1 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(subtitle1)),
128
- subtitle-2: $subtitle-2 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(subtitle2)),
129
- body-1: $body-1 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(body1)),
130
- body-2: $body-2 or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(body2)),
131
- caption: $caption or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(caption)),
132
- button: $button or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(button)),
133
- overline: $overline or _rem-to-px(mdc-helpers.typography-config-level-from-mdc(overline)),
134
- ));
135
- }
136
-
137
- /// Generates an Angular Material typography config based on values from the official Material
138
- /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
139
- /// the default values. The `mat-typography-level` function can be used to generate a custom
140
- /// typography level map which can be passed to this function to override one of the default levels.
141
- /// All default typography sizing generated by this function is in `rem` units.
142
- ///
143
- /// @param {String} $font-family The font family to use for levels where it is not explicitly
144
- /// specified.
145
- /// @param {Map} $headline-1 The font settings for the headline-1 font level.
146
- /// @param {Map} $headline-2 The font settings for the headline-2 font level.
147
- /// @param {Map} $headline-3 The font settings for the headline-3 font level.
148
- /// @param {Map} $headline-4 The font settings for the headline-4 font level.
149
- /// @param {Map} $headline-5 The font settings for the headline-5 font level.
150
- /// @param {Map} $headline-6 The font settings for the headline-6 font level.
151
- /// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level.
152
- /// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level.
153
- /// @param {Map} $body-1 The font settings for the body-1 font level.
154
- /// @param {Map} $body-2 The font settings for the body-2 font level.
155
- /// @param {Map} $caption The font settings for the caption font level.
156
- /// @param {Map} $button The font settings for the button font level.
157
- /// @param {Map} $overline The font settings for the overline font level.
158
- /// @return {Map} A map containing font settings for each of the levels in the Material Design spec.
159
- @function define-rem-typography-config(
160
- // TODO(mmalerba): rename this function to define-typography-config,
161
- // and create a predefined px based config for people that need it.
162
- $font-family: mdc-typography.$font-family,
163
- $headline-1: null,
164
- $headline-2: null,
165
- $headline-3: null,
166
- $headline-4: null,
167
- $headline-5: null,
168
- $headline-6: null,
169
- $subtitle-1: null,
170
- $subtitle-2: null,
171
- $body-1: null,
172
- $body-2: null,
173
- $caption: null,
174
- $button: null,
175
- $overline: null,
176
- ) {
177
- @return _apply-font-family($font-family, (
178
- headline-1: $headline-1 or mdc-helpers.typography-config-level-from-mdc(headline1),
179
- headline-2: $headline-2 or mdc-helpers.typography-config-level-from-mdc(headline2),
180
- headline-3: $headline-3 or mdc-helpers.typography-config-level-from-mdc(headline3),
181
- headline-4: $headline-4 or mdc-helpers.typography-config-level-from-mdc(headline4),
182
- headline-5: $headline-5 or mdc-helpers.typography-config-level-from-mdc(headline5),
183
- headline-6: $headline-6 or mdc-helpers.typography-config-level-from-mdc(headline6),
184
- subtitle-1: $subtitle-1 or mdc-helpers.typography-config-level-from-mdc(subtitle1),
185
- subtitle-2: $subtitle-2 or mdc-helpers.typography-config-level-from-mdc(subtitle2),
186
- body-1: $body-1 or mdc-helpers.typography-config-level-from-mdc(body1),
187
- body-2: $body-2 or mdc-helpers.typography-config-level-from-mdc(body2),
188
- caption: $caption or mdc-helpers.typography-config-level-from-mdc(caption),
189
- button: $button or mdc-helpers.typography-config-level-from-mdc(button),
190
- overline: $overline or mdc-helpers.typography-config-level-from-mdc(overline),
191
- ));
192
- }
193
40
 
194
41
  // Includes all of the typographic styles.
195
42
  @mixin all-component-typographies($config-or-theme: null) {
@@ -198,7 +45,7 @@
198
45
 
199
46
  // If no actual color configuration has been specified, create a default one.
200
47
  @if not $config {
201
- $config: define-typography-config();
48
+ $config: typography.define-typography-config();
202
49
  }
203
50
 
204
51
  // TODO: COMP-309: Do not use individual mixins. Instead, use the all-theme mixin and only
@@ -1,6 +1,9 @@
1
1
  @use 'sass:map';
2
+ @use 'sass:math';
3
+ @use 'sass:meta';
2
4
  @use 'typography-utils';
3
5
  @use '../theming/theming';
6
+ @use '@material/typography' as mdc-typography;
4
7
 
5
8
  /// Defines a typography level from the Material Design spec.
6
9
  /// @param {String} $font-size The font-size for this level.
@@ -97,6 +100,165 @@
97
100
  @return map.merge($config, (font-family: $font-family));
98
101
  }
99
102
 
103
+ // Converts a map containing rem values to a map containing px values.
104
+ @function _rem-to-px($x, $px-per-rem: 16px) {
105
+ @if meta.type-of($x) == 'map' {
106
+ @each $key, $val in $x {
107
+ $x: map.merge($x, ($key: _rem-to-px($val)));
108
+ }
109
+ @return $x;
110
+ }
111
+ @if meta.type-of($x) == 'number' and math.unit($x) == 'rem' {
112
+ @return math.div($x, 1rem) * $px-per-rem;
113
+ }
114
+ @else {
115
+ @return $x;
116
+ }
117
+ }
118
+
119
+ // Applies the default font family to all levels in a typography config.
120
+ @function _apply-font-family($font-family, $initial-config) {
121
+ $config: $initial-config;
122
+
123
+ @each $key, $level in $config {
124
+ @if map.get($level, 'font-family') == null {
125
+ // Sass maps are immutable so we have to re-assign the variable each time.
126
+ $config: map.set($config, $key, map.set($level, 'font-family', $font-family));
127
+ }
128
+ }
129
+
130
+ @return map.set($config, 'font-family', $font-family);
131
+ }
132
+
133
+ // Converts an MDC typography level config to an Angular Material one.
134
+ @function typography-config-level-from-mdc($mdc-level, $font-family: null) {
135
+ $mdc-level-config: map.get(mdc-typography.$styles, $mdc-level);
136
+
137
+ // Explicitly default the font family to null since we'll apply it globally
138
+ // through the `define-typgraphy-config`/`define-legacy-typography-config`.
139
+ @return define-typography-level(
140
+ $font-family: $font-family,
141
+ $font-size: map.get($mdc-level-config, font-size),
142
+ $line-height: map.get($mdc-level-config, line-height),
143
+ $font-weight: map.get($mdc-level-config, font-weight),
144
+ $letter-spacing: map.get($mdc-level-config, letter-spacing)
145
+ );
146
+ }
147
+
148
+ /// Generates an Angular Material typography config based on values from the official Material
149
+ /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
150
+ /// the default values. The `mat-typography-level` function can be used to generate a custom
151
+ /// typography level map which can be passed to this function to override one of the default levels.
152
+ /// All default typography sizing generated by this function is in `px` units.
153
+ ///
154
+ /// @param {String} $font-family The font family to use for levels where it is not explicitly
155
+ /// specified.
156
+ /// @param {Map} $headline-1 The font settings for the headline-1 font level.
157
+ /// @param {Map} $headline-2 The font settings for the headline-2 font level.
158
+ /// @param {Map} $headline-3 The font settings for the headline-3 font level.
159
+ /// @param {Map} $headline-4 The font settings for the headline-4 font level.
160
+ /// @param {Map} $headline-5 The font settings for the headline-5 font level.
161
+ /// @param {Map} $headline-6 The font settings for the headline-6 font level.
162
+ /// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level.
163
+ /// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level.
164
+ /// @param {Map} $body-1 The font settings for the body-1 font level.
165
+ /// @param {Map} $body-2 The font settings for the body-2 font level.
166
+ /// @param {Map} $caption The font settings for the caption font level.
167
+ /// @param {Map} $button The font settings for the button font level.
168
+ /// @param {Map} $overline The font settings for the overline font level.
169
+ /// @return {Map} A map containing font settings for each of the levels in the Material Design spec.
170
+ @function define-typography-config(
171
+ // TODO(mmalerba): rename this function to define-typography-config,
172
+ // and create a predefined px based config for people that need it.
173
+ $font-family: mdc-typography.$font-family,
174
+ $headline-1: null,
175
+ $headline-2: null,
176
+ $headline-3: null,
177
+ $headline-4: null,
178
+ $headline-5: null,
179
+ $headline-6: null,
180
+ $subtitle-1: null,
181
+ $subtitle-2: null,
182
+ $body-1: null,
183
+ $body-2: null,
184
+ $caption: null,
185
+ $button: null,
186
+ $overline: null,
187
+ ) {
188
+ @return _apply-font-family($font-family, (
189
+ headline-1: $headline-1 or _rem-to-px(typography-config-level-from-mdc(headline1)),
190
+ headline-2: $headline-2 or _rem-to-px(typography-config-level-from-mdc(headline2)),
191
+ headline-3: $headline-3 or _rem-to-px(typography-config-level-from-mdc(headline3)),
192
+ headline-4: $headline-4 or _rem-to-px(typography-config-level-from-mdc(headline4)),
193
+ headline-5: $headline-5 or _rem-to-px(typography-config-level-from-mdc(headline5)),
194
+ headline-6: $headline-6 or _rem-to-px(typography-config-level-from-mdc(headline6)),
195
+ subtitle-1: $subtitle-1 or _rem-to-px(typography-config-level-from-mdc(subtitle1)),
196
+ subtitle-2: $subtitle-2 or _rem-to-px(typography-config-level-from-mdc(subtitle2)),
197
+ body-1: $body-1 or _rem-to-px(typography-config-level-from-mdc(body1)),
198
+ body-2: $body-2 or _rem-to-px(typography-config-level-from-mdc(body2)),
199
+ caption: $caption or _rem-to-px(typography-config-level-from-mdc(caption)),
200
+ button: $button or _rem-to-px(typography-config-level-from-mdc(button)),
201
+ overline: $overline or _rem-to-px(typography-config-level-from-mdc(overline)),
202
+ ));
203
+ }
204
+
205
+ /// Generates an Angular Material typography config based on values from the official Material
206
+ /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
207
+ /// the default values. The `mat-typography-level` function can be used to generate a custom
208
+ /// typography level map which can be passed to this function to override one of the default levels.
209
+ /// All default typography sizing generated by this function is in `rem` units.
210
+ ///
211
+ /// @param {String} $font-family The font family to use for levels where it is not explicitly
212
+ /// specified.
213
+ /// @param {Map} $headline-1 The font settings for the headline-1 font level.
214
+ /// @param {Map} $headline-2 The font settings for the headline-2 font level.
215
+ /// @param {Map} $headline-3 The font settings for the headline-3 font level.
216
+ /// @param {Map} $headline-4 The font settings for the headline-4 font level.
217
+ /// @param {Map} $headline-5 The font settings for the headline-5 font level.
218
+ /// @param {Map} $headline-6 The font settings for the headline-6 font level.
219
+ /// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level.
220
+ /// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level.
221
+ /// @param {Map} $body-1 The font settings for the body-1 font level.
222
+ /// @param {Map} $body-2 The font settings for the body-2 font level.
223
+ /// @param {Map} $caption The font settings for the caption font level.
224
+ /// @param {Map} $button The font settings for the button font level.
225
+ /// @param {Map} $overline The font settings for the overline font level.
226
+ /// @return {Map} A map containing font settings for each of the levels in the Material Design spec.
227
+ @function define-rem-typography-config(
228
+ // TODO(mmalerba): rename this function to define-typography-config,
229
+ // and create a predefined px based config for people that need it.
230
+ $font-family: mdc-typography.$font-family,
231
+ $headline-1: null,
232
+ $headline-2: null,
233
+ $headline-3: null,
234
+ $headline-4: null,
235
+ $headline-5: null,
236
+ $headline-6: null,
237
+ $subtitle-1: null,
238
+ $subtitle-2: null,
239
+ $body-1: null,
240
+ $body-2: null,
241
+ $caption: null,
242
+ $button: null,
243
+ $overline: null,
244
+ ) {
245
+ @return _apply-font-family($font-family, (
246
+ headline-1: $headline-1 or typography-config-level-from-mdc(headline1),
247
+ headline-2: $headline-2 or typography-config-level-from-mdc(headline2),
248
+ headline-3: $headline-3 or typography-config-level-from-mdc(headline3),
249
+ headline-4: $headline-4 or typography-config-level-from-mdc(headline4),
250
+ headline-5: $headline-5 or typography-config-level-from-mdc(headline5),
251
+ headline-6: $headline-6 or typography-config-level-from-mdc(headline6),
252
+ subtitle-1: $subtitle-1 or typography-config-level-from-mdc(subtitle1),
253
+ subtitle-2: $subtitle-2 or typography-config-level-from-mdc(subtitle2),
254
+ body-1: $body-1 or typography-config-level-from-mdc(body1),
255
+ body-2: $body-2 or typography-config-level-from-mdc(body2),
256
+ caption: $caption or typography-config-level-from-mdc(caption),
257
+ button: $button or typography-config-level-from-mdc(button),
258
+ overline: $overline or typography-config-level-from-mdc(overline),
259
+ ));
260
+ }
261
+
100
262
  // Whether a config is for the Material Design 2018 typography system.
101
263
  @function private-typography-is-2018-config($config) {
102
264
  @return map.get($config, headline-1) != null;