@angular/material 17.0.0-next.0 → 17.0.0-next.2

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 (204) hide show
  1. package/_index.scss +3 -4
  2. package/autocomplete/_autocomplete-theme.scss +12 -18
  3. package/autocomplete/index.d.ts +15 -24
  4. package/badge/_badge-theme.scss +15 -27
  5. package/badge/index.d.ts +9 -17
  6. package/bottom-sheet/_bottom-sheet-theme.scss +13 -22
  7. package/button/_button-base.scss +3 -3
  8. package/button/_button-theme-private.scss +3 -2
  9. package/button/_button-theme.scss +18 -25
  10. package/button/_fab-theme.scss +31 -49
  11. package/button/_icon-button-theme.scss +19 -26
  12. package/button/index.d.ts +22 -31
  13. package/button-toggle/_button-toggle-theme.scss +17 -28
  14. package/button-toggle/index.d.ts +15 -18
  15. package/card/_card-theme.scss +27 -38
  16. package/checkbox/_checkbox-theme.scss +28 -45
  17. package/checkbox/index.d.ts +21 -27
  18. package/chips/_chips-theme.scss +18 -56
  19. package/core/_core-theme.scss +24 -39
  20. package/core/color/_all-color.scss +7 -15
  21. package/core/density/private/_all-density.scss +34 -39
  22. package/core/focus-indicators/_focus-indicators-theme.scss +6 -8
  23. package/core/focus-indicators/_private.scss +22 -26
  24. package/core/index.d.ts +7 -11
  25. package/core/mdc-helpers/_mdc-helpers.scss +19 -22
  26. package/core/option/_optgroup-theme.scss +13 -23
  27. package/core/option/_option-theme.scss +23 -37
  28. package/core/ripple/_ripple-theme.scss +6 -10
  29. package/core/selection/pseudo-checkbox/_pseudo-checkbox-theme.scss +17 -24
  30. package/core/style/_form-common.scss +7 -7
  31. package/core/style/_private.scss +5 -7
  32. package/core/style/_sass-utils.scss +7 -0
  33. package/core/testing/index.d.ts +2 -1
  34. package/core/theming/_all-theme.scss +41 -41
  35. package/core/theming/_inspection.scss +133 -59
  36. package/core/theming/_m2-inspection.scss +268 -0
  37. package/core/theming/_theming.scss +59 -20
  38. package/core/tokens/m2/mat/_autocomplete.scss +5 -8
  39. package/core/tokens/m2/mat/_badge.scss +12 -15
  40. package/core/tokens/m2/mat/_bottom-sheet.scss +11 -17
  41. package/core/tokens/m2/mat/_card.scss +15 -21
  42. package/core/tokens/m2/mat/_datepicker.scss +28 -38
  43. package/core/tokens/m2/mat/_divider.scss +5 -8
  44. package/core/tokens/m2/mat/_expansion.scss +24 -28
  45. package/core/tokens/m2/mat/_form-field.scss +21 -25
  46. package/core/tokens/m2/mat/_grid-list.scss +8 -8
  47. package/core/tokens/m2/mat/_icon.scss +3 -3
  48. package/core/tokens/m2/mat/_legacy-button-toggle.scss +15 -19
  49. package/core/tokens/m2/mat/_menu.scss +12 -17
  50. package/core/tokens/m2/mat/_optgroup.scss +12 -17
  51. package/core/tokens/m2/mat/_option.scss +16 -28
  52. package/core/tokens/m2/mat/_paginator.scss +16 -18
  53. package/core/tokens/m2/mat/_radio.scss +7 -10
  54. package/core/tokens/m2/mat/_select.scss +15 -29
  55. package/core/tokens/m2/mat/_sidenav.scss +12 -14
  56. package/core/tokens/m2/mat/_slide-toggle.scss +9 -17
  57. package/core/tokens/m2/mat/_slider.scss +5 -5
  58. package/core/tokens/m2/mat/_snack-bar.scss +7 -8
  59. package/core/tokens/m2/mat/_standard-button-toggle.scss +23 -22
  60. package/core/tokens/m2/mat/_stepper.scss +30 -33
  61. package/core/tokens/m2/mat/_tab-header-with-background.scss +6 -8
  62. package/core/tokens/m2/mat/_tab-header.scss +13 -18
  63. package/core/tokens/m2/mat/_table.scss +19 -23
  64. package/core/tokens/m2/mat/_toolbar.scss +12 -16
  65. package/core/tokens/m2/mdc/_checkbox.scss +21 -20
  66. package/core/tokens/m2/mdc/_chip.scss +38 -24
  67. package/core/tokens/m2/mdc/_circular-progress.scss +5 -6
  68. package/core/tokens/m2/mdc/_dialog.scss +16 -30
  69. package/core/tokens/m2/mdc/_elevated-card.scss +6 -9
  70. package/core/tokens/m2/mdc/_extended-fab.scss +8 -17
  71. package/core/tokens/m2/mdc/_fab.scss +6 -7
  72. package/core/tokens/m2/mdc/_filled-text-field.scss +16 -22
  73. package/core/tokens/m2/mdc/_icon-button.scss +3 -3
  74. package/core/tokens/m2/mdc/_linear-progress.scss +9 -10
  75. package/core/tokens/m2/mdc/_list.scss +44 -42
  76. package/core/tokens/m2/mdc/_outlined-card.scss +7 -10
  77. package/core/tokens/m2/mdc/_outlined-text-field.scss +14 -20
  78. package/core/tokens/m2/mdc/_plain-tooltip.scss +9 -22
  79. package/core/tokens/m2/mdc/_radio.scss +11 -11
  80. package/core/tokens/m2/mdc/_slider.scss +16 -23
  81. package/core/tokens/m2/mdc/_snack-bar.scss +10 -23
  82. package/core/tokens/m2/mdc/_switch.scss +16 -19
  83. package/core/tokens/m2/mdc/_tab-indicator.scss +5 -8
  84. package/core/tokens/m2/mdc/_tab.scss +5 -4
  85. package/core/typography/_all-typography.scss +44 -47
  86. package/core/typography/_definition.scss +258 -0
  87. package/core/typography/_property-getters.scss +63 -0
  88. package/core/typography/_typography-utils.scss +9 -69
  89. package/core/typography/_typography.scss +38 -494
  90. package/core/typography/_versioning.scss +91 -0
  91. package/datepicker/_datepicker-theme.scss +20 -34
  92. package/datepicker/index.d.ts +3 -3
  93. package/dialog/_dialog-theme.scss +22 -23
  94. package/dialog/_mdc-dialog-structure-overrides.scss +12 -10
  95. package/dialog/index.d.ts +2 -0
  96. package/divider/_divider-theme.scss +12 -18
  97. package/esm2022/autocomplete/autocomplete-trigger.mjs +5 -17
  98. package/esm2022/autocomplete/autocomplete.mjs +23 -50
  99. package/esm2022/badge/badge.mjs +11 -29
  100. package/esm2022/button/button-base.mjs +32 -27
  101. package/esm2022/button/button.mjs +6 -6
  102. package/esm2022/button/fab.mjs +23 -31
  103. package/esm2022/button/icon-button.mjs +6 -6
  104. package/esm2022/button/testing/button-harness.mjs +3 -3
  105. package/esm2022/button-toggle/button-toggle.mjs +25 -33
  106. package/esm2022/checkbox/checkbox.mjs +32 -39
  107. package/esm2022/core/option/optgroup.mjs +10 -11
  108. package/esm2022/core/option/option.mjs +6 -6
  109. package/esm2022/core/testing/option-harness.mjs +3 -3
  110. package/esm2022/core/version.mjs +1 -1
  111. package/esm2022/datepicker/calendar.mjs +1 -1
  112. package/esm2022/datepicker/datepicker-base.mjs +2 -2
  113. package/esm2022/datepicker/datepicker-toggle.mjs +1 -1
  114. package/esm2022/datepicker/month-view.mjs +2 -2
  115. package/esm2022/datepicker/multi-year-view.mjs +2 -2
  116. package/esm2022/datepicker/year-view.mjs +2 -2
  117. package/esm2022/dialog/dialog-container.mjs +16 -3
  118. package/esm2022/form-field/form-field.mjs +3 -3
  119. package/esm2022/menu/menu-item.mjs +15 -11
  120. package/esm2022/menu/menu.mjs +9 -22
  121. package/esm2022/paginator/paginator.mjs +1 -1
  122. package/esm2022/select/select.mjs +3 -3
  123. package/esm2022/slide-toggle/slide-toggle.mjs +33 -37
  124. package/esm2022/slider/slider-input.mjs +19 -9
  125. package/esm2022/slider/slider.mjs +2 -2
  126. package/esm2022/snack-bar/simple-snack-bar.mjs +1 -1
  127. package/esm2022/tabs/tab-group.mjs +3 -3
  128. package/expansion/_expansion-theme.scss +16 -24
  129. package/fesm2022/autocomplete.mjs +25 -63
  130. package/fesm2022/autocomplete.mjs.map +1 -1
  131. package/fesm2022/badge.mjs +11 -28
  132. package/fesm2022/badge.mjs.map +1 -1
  133. package/fesm2022/button/testing.mjs +2 -2
  134. package/fesm2022/button/testing.mjs.map +1 -1
  135. package/fesm2022/button-toggle.mjs +25 -32
  136. package/fesm2022/button-toggle.mjs.map +1 -1
  137. package/fesm2022/button.mjs +59 -61
  138. package/fesm2022/button.mjs.map +1 -1
  139. package/fesm2022/checkbox.mjs +31 -38
  140. package/fesm2022/checkbox.mjs.map +1 -1
  141. package/fesm2022/core/testing.mjs +2 -2
  142. package/fesm2022/core/testing.mjs.map +1 -1
  143. package/fesm2022/core.mjs +14 -13
  144. package/fesm2022/core.mjs.map +1 -1
  145. package/fesm2022/datepicker.mjs +6 -6
  146. package/fesm2022/datepicker.mjs.map +1 -1
  147. package/fesm2022/dialog.mjs +15 -2
  148. package/fesm2022/dialog.mjs.map +1 -1
  149. package/fesm2022/form-field.mjs +2 -2
  150. package/fesm2022/form-field.mjs.map +1 -1
  151. package/fesm2022/menu.mjs +23 -31
  152. package/fesm2022/menu.mjs.map +1 -1
  153. package/fesm2022/paginator.mjs +1 -1
  154. package/fesm2022/paginator.mjs.map +1 -1
  155. package/fesm2022/select.mjs +2 -2
  156. package/fesm2022/select.mjs.map +1 -1
  157. package/fesm2022/slide-toggle.mjs +33 -36
  158. package/fesm2022/slide-toggle.mjs.map +1 -1
  159. package/fesm2022/slider.mjs +20 -10
  160. package/fesm2022/slider.mjs.map +1 -1
  161. package/fesm2022/snack-bar.mjs +1 -1
  162. package/fesm2022/snack-bar.mjs.map +1 -1
  163. package/fesm2022/tabs.mjs +2 -2
  164. package/fesm2022/tabs.mjs.map +1 -1
  165. package/form-field/_form-field-density.scss +3 -4
  166. package/form-field/_form-field-focus-overlay.scss +1 -1
  167. package/form-field/_form-field-sizing.scss +1 -1
  168. package/form-field/_form-field-theme.scss +24 -34
  169. package/grid-list/_grid-list-theme.scss +12 -19
  170. package/icon/_icon-theme.scss +17 -25
  171. package/input/_input-theme.scss +11 -23
  172. package/list/_list-theme.scss +27 -42
  173. package/menu/_menu-theme.scss +13 -22
  174. package/menu/index.d.ts +12 -18
  175. package/package.json +2 -2
  176. package/paginator/_paginator-theme.scss +15 -24
  177. package/prebuilt-themes/deeppurple-amber.css +1 -1
  178. package/prebuilt-themes/indigo-pink.css +1 -1
  179. package/prebuilt-themes/pink-bluegrey.css +1 -1
  180. package/prebuilt-themes/purple-green.css +1 -1
  181. package/progress-bar/_progress-bar-theme.scss +17 -24
  182. package/progress-spinner/_progress-spinner-theme.scss +18 -24
  183. package/radio/_radio-theme.scss +23 -38
  184. package/schematics/ng-add/index.js +1 -1
  185. package/schematics/ng-add/index.mjs +1 -1
  186. package/schematics/ng-generate/mdc-migration/index_bundled.js +44 -44
  187. package/schematics/ng-generate/mdc-migration/index_bundled.js.map +1 -1
  188. package/schematics/ng-update/index_bundled.js +25 -25
  189. package/select/_select-theme.scss +17 -31
  190. package/sidenav/_sidenav-theme.scss +12 -18
  191. package/slide-toggle/_slide-toggle-theme.scss +23 -40
  192. package/slide-toggle/index.d.ts +20 -23
  193. package/slider/_slider-theme.scss +25 -42
  194. package/snack-bar/_snack-bar-theme.scss +17 -26
  195. package/sort/_sort-theme.scss +13 -22
  196. package/stepper/_stepper-theme.scss +16 -34
  197. package/table/_table-theme.scss +14 -25
  198. package/tabs/_tabs-theme.scss +31 -45
  199. package/toolbar/_toolbar-theme.scss +22 -31
  200. package/tooltip/_tooltip-theme.scss +15 -23
  201. package/tree/_tree-theme.scss +20 -29
  202. package/button-toggle/_button-toggle-variables.scss +0 -16
  203. package/core/typography/_typography-deprecated.scss +0 -39
  204. package/paginator/_paginator-variables.scss +0 -15
@@ -1,5 +1,6 @@
1
1
  @use 'sass:map';
2
2
  @use '../../../theming/theming';
3
+ @use '../../../theming/inspection';
3
4
  @use '../../../style/sass-utils';
4
5
  @use '../../token-utils';
5
6
 
@@ -50,18 +51,18 @@ $prefix: (mdc, tab);
50
51
  }
51
52
 
52
53
  // Tokens that can be configured through Angular Material's color theming API.
53
- @function get-color-tokens($config) {
54
+ @function get-color-tokens($theme, $palette-name: primary) {
54
55
  @return ();
55
56
  }
56
57
 
57
58
  // Tokens that can be configured through Angular Material's typography theming API.
58
- @function get-typography-tokens($config) {
59
+ @function get-typography-tokens($theme) {
59
60
  @return ();
60
61
  }
61
62
 
62
63
  // Tokens that can be configured through Angular Material's density theming API.
63
- @function get-density-tokens($config) {
64
- $scale: theming.clamp-density($config, -4);
64
+ @function get-density-tokens($theme) {
65
+ $scale: theming.clamp-density(inspection.get-theme-density($theme), -4);
65
66
 
66
67
  @return (
67
68
  container-height: map.get((
@@ -35,17 +35,14 @@
35
35
  @use '../../snack-bar/snack-bar-theme';
36
36
  @use '../../form-field/form-field-theme';
37
37
  @use '../../tree/tree-theme';
38
- @use '../theming/theming';
38
+ @use '../theming/inspection';
39
39
  @use '../core-theme';
40
40
 
41
41
  // Includes all of the typographic styles.
42
- @mixin all-component-typographies($config-or-theme: null) {
43
- $config: if(theming.private-is-theme-object($config-or-theme),
44
- theming.get-typography-config($config-or-theme), $config-or-theme);
45
-
42
+ @mixin all-component-typographies($theme: null) {
46
43
  // If no actual color configuration has been specified, create a default one.
47
- @if not $config {
48
- $config: typography.define-typography-config();
44
+ @if not inspection.theme-has($theme, typography) {
45
+ $theme: typography.define-typography-config();
49
46
  }
50
47
 
51
48
  // TODO: COMP-309: Do not use individual mixins. Instead, use the all-theme mixin and only
@@ -53,47 +50,47 @@
53
50
  // not possible as it would introduce a circular dependency for typography because the `mat-core`
54
51
  // mixin that is transitively loaded by the `all-theme` file, imports `all-typography` which
55
52
  // would then load `all-theme` again. This ultimately results a circular dependency.
56
- @include badge-theme.typography($config);
57
- @include typography.typography-hierarchy($config);
58
- @include bottom-sheet-theme.typography($config);
59
- @include button-toggle-theme.typography($config);
60
- @include divider-theme.typography($config);
61
- @include datepicker-theme.typography($config);
62
- @include expansion-theme.typography($config);
63
- @include grid-list-theme.typography($config);
64
- @include icon-theme.typography($config);
65
- @include progress-spinner-theme.typography($config);
66
- @include sidenav-theme.typography($config);
67
- @include stepper-theme.typography($config);
68
- @include sort-theme.typography($config);
69
- @include toolbar-theme.typography($config);
70
- @include tree-theme.typography($config);
71
- @include core-theme.typography($config);
72
- @include card-theme.typography($config);
73
- @include progress-bar-theme.typography($config);
74
- @include tooltip-theme.typography($config);
75
- @include form-field-theme.typography($config);
76
- @include input-theme.typography($config);
77
- @include select-theme.typography($config);
78
- @include autocomplete-theme.typography($config);
79
- @include dialog-theme.typography($config);
80
- @include chips-theme.typography($config);
81
- @include slide-toggle-theme.typography($config);
82
- @include radio-theme.typography($config);
83
- @include slider-theme.typography($config);
84
- @include menu-theme.typography($config);
85
- @include list-theme.typography($config);
86
- @include paginator-theme.typography($config);
87
- @include tabs-theme.typography($config);
88
- @include checkbox-theme.typography($config);
89
- @include button-theme.typography($config);
90
- @include icon-button-theme.typography($config);
91
- @include fab-theme.typography($config);
92
- @include snack-bar-theme.typography($config);
93
- @include table-theme.typography($config);
53
+ @include badge-theme.typography($theme);
54
+ @include typography.typography-hierarchy($theme);
55
+ @include bottom-sheet-theme.typography($theme);
56
+ @include button-toggle-theme.typography($theme);
57
+ @include divider-theme.typography($theme);
58
+ @include datepicker-theme.typography($theme);
59
+ @include expansion-theme.typography($theme);
60
+ @include grid-list-theme.typography($theme);
61
+ @include icon-theme.typography($theme);
62
+ @include progress-spinner-theme.typography($theme);
63
+ @include sidenav-theme.typography($theme);
64
+ @include stepper-theme.typography($theme);
65
+ @include sort-theme.typography($theme);
66
+ @include toolbar-theme.typography($theme);
67
+ @include tree-theme.typography($theme);
68
+ @include core-theme.typography($theme);
69
+ @include card-theme.typography($theme);
70
+ @include progress-bar-theme.typography($theme);
71
+ @include tooltip-theme.typography($theme);
72
+ @include form-field-theme.typography($theme);
73
+ @include input-theme.typography($theme);
74
+ @include select-theme.typography($theme);
75
+ @include autocomplete-theme.typography($theme);
76
+ @include dialog-theme.typography($theme);
77
+ @include chips-theme.typography($theme);
78
+ @include slide-toggle-theme.typography($theme);
79
+ @include radio-theme.typography($theme);
80
+ @include slider-theme.typography($theme);
81
+ @include menu-theme.typography($theme);
82
+ @include list-theme.typography($theme);
83
+ @include paginator-theme.typography($theme);
84
+ @include tabs-theme.typography($theme);
85
+ @include checkbox-theme.typography($theme);
86
+ @include button-theme.typography($theme);
87
+ @include icon-button-theme.typography($theme);
88
+ @include fab-theme.typography($theme);
89
+ @include snack-bar-theme.typography($theme);
90
+ @include table-theme.typography($theme);
94
91
  }
95
92
 
96
93
  // @deprecated Use `all-component-typographies`.
97
- @mixin angular-material-typography($config-or-theme: null) {
98
- @include all-component-typographies($config-or-theme);
94
+ @mixin angular-material-typography($theme: null) {
95
+ @include all-component-typographies($theme);
99
96
  }
@@ -0,0 +1,258 @@
1
+ @use 'sass:map';
2
+ @use 'sass:math';
3
+ @use 'sass:meta';
4
+ @use '@material/typography' as mdc-typography;
5
+
6
+ /// Defines a typography level from the Material Design spec.
7
+ /// @param {String} $font-size The font-size for this level.
8
+ /// @param {String | Number} $line-height The line-height for this level.
9
+ /// @param {String | Number} $font-weight The font-weight for this level.
10
+ /// @param {String} $font-family The font-family for this level.
11
+ /// @param {String} $letter-spacing The letter-spacing for this level.
12
+ /// @returns {Map} A map representing the definition of this typographic level.
13
+ @function define-typography-level(
14
+ $font-size,
15
+ $line-height: $font-size,
16
+ $font-weight: 400,
17
+ $font-family: null,
18
+ $letter-spacing: normal) {
19
+
20
+ @return (
21
+ font-size: $font-size,
22
+ line-height: $line-height,
23
+ font-weight: $font-weight,
24
+ font-family: $font-family,
25
+ letter-spacing: $letter-spacing
26
+ );
27
+ }
28
+
29
+ /// Defines a collection of typography levels to configure typography for an application.
30
+ /// Any level not specified defaults to the values defined in the Material Design specification:
31
+ /// https://material.io/guidelines/style/typography.html.
32
+ ///
33
+ /// Note that the Material Design specification does not describe explicit letter-spacing values.
34
+ /// The values here come from reverse engineering the Material Design examples.
35
+ /// @param {String} $font-family Default font-family for levels that don't specify font-family.
36
+ /// @param {Map} $display-4 Configuration for the "display-4" typographic level.
37
+ /// @param {Map} $display-3 Configuration for the "display-3" typographic level.
38
+ /// @param {Map} $display-2 Configuration for the "display-2" typographic level.
39
+ /// @param {Map} $display-1 Configuration for the "display-1" typographic level.
40
+ /// @param {Map} $headline Configuration for the "headline" typographic level.
41
+ /// @param {Map} $title Configuration for the "title" typographic level.
42
+ /// @param {Map} $subheading-2 Configuration for the "subheading-2" typographic level.
43
+ /// @param {Map} $subheading-1 Configuration for the "subheading-1" typographic level.
44
+ /// @param {Map} $body-2 Configuration for the "body-2" typographic level.
45
+ /// @param {Map} $body-1 Configuration for the "body-1" typographic level.
46
+ /// @param {Map} $caption Configuration for the "caption" typographic level.
47
+ /// @param {Map} $button Configuration for the "button" typographic level.
48
+ /// @param {Map} $input Configuration for the "input" typographic level.
49
+ /// @returns {Map} A typography config for the application.
50
+ ///
51
+ /// @deprecated Use `mat.define-typography-config` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
52
+ /// @breaking-change 17.0.0
53
+ @function define-legacy-typography-config(
54
+ $font-family: 'Roboto, "Helvetica Neue", sans-serif',
55
+ $display-4: define-typography-level(112px, 112px, 300, $letter-spacing: -0.05em),
56
+ $display-3: define-typography-level(56px, 56px, 400, $letter-spacing: -0.02em),
57
+ $display-2: define-typography-level(45px, 48px, 400, $letter-spacing: -0.005em),
58
+ $display-1: define-typography-level(34px, 40px, 400),
59
+ $headline: define-typography-level(24px, 32px, 400),
60
+ $title: define-typography-level(20px, 32px, 500),
61
+ $subheading-2: define-typography-level(16px, 28px, 400),
62
+ $subheading-1: define-typography-level(15px, 24px, 400),
63
+ $body-2: define-typography-level(14px, 24px, 500),
64
+ $body-1: define-typography-level(14px, 20px, 400),
65
+ $caption: define-typography-level(12px, 20px, 400),
66
+ $button: define-typography-level(14px, 14px, 500),
67
+ // Line-height must be unit-less fraction of the font-size.
68
+ $input: define-typography-level(inherit, 1.125, 400)
69
+ ) {
70
+
71
+ // Declare an initial map with all of the levels.
72
+ $config: (
73
+ display-4: $display-4,
74
+ display-3: $display-3,
75
+ display-2: $display-2,
76
+ display-1: $display-1,
77
+ headline: $headline,
78
+ title: $title,
79
+ subheading-2: $subheading-2,
80
+ subheading-1: $subheading-1,
81
+ body-2: $body-2,
82
+ body-1: $body-1,
83
+ caption: $caption,
84
+ button: $button,
85
+ input: $input,
86
+ );
87
+
88
+ // Loop through the levels and set the `font-family` of the ones that don't have one to the base.
89
+ // Note that Sass can't modify maps in place, which means that we need to merge and re-assign.
90
+ @each $key, $level in $config {
91
+ @if map.get($level, font-family) == null {
92
+ $new-level: map.merge($level, (font-family: $font-family));
93
+ $config: map.merge($config, ($key: $new-level));
94
+ }
95
+ }
96
+
97
+ // Add the base font family to the config.
98
+ @return map.merge($config, (font-family: $font-family));
99
+ }
100
+
101
+ /// Generates an Angular Material typography config based on values from the official Material
102
+ /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
103
+ /// the default values. The `mat-typography-level` function can be used to generate a custom
104
+ /// typography level map which can be passed to this function to override one of the default levels.
105
+ /// All default typography sizing generated by this function is in `px` units.
106
+ ///
107
+ /// @param {String} $font-family The font family to use for levels where it is not explicitly
108
+ /// specified.
109
+ /// @param {Map} $headline-1 The font settings for the headline-1 font level.
110
+ /// @param {Map} $headline-2 The font settings for the headline-2 font level.
111
+ /// @param {Map} $headline-3 The font settings for the headline-3 font level.
112
+ /// @param {Map} $headline-4 The font settings for the headline-4 font level.
113
+ /// @param {Map} $headline-5 The font settings for the headline-5 font level.
114
+ /// @param {Map} $headline-6 The font settings for the headline-6 font level.
115
+ /// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level.
116
+ /// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level.
117
+ /// @param {Map} $body-1 The font settings for the body-1 font level.
118
+ /// @param {Map} $body-2 The font settings for the body-2 font level.
119
+ /// @param {Map} $caption The font settings for the caption font level.
120
+ /// @param {Map} $button The font settings for the button font level.
121
+ /// @param {Map} $overline The font settings for the overline font level.
122
+ /// @return {Map} A map containing font settings for each of the levels in the Material Design spec.
123
+ @function define-typography-config(
124
+ // TODO(mmalerba): rename this function to define-typography-config,
125
+ // and create a predefined px based config for people that need it.
126
+ $font-family: mdc-typography.$font-family,
127
+ $headline-1: null,
128
+ $headline-2: null,
129
+ $headline-3: null,
130
+ $headline-4: null,
131
+ $headline-5: null,
132
+ $headline-6: null,
133
+ $subtitle-1: null,
134
+ $subtitle-2: null,
135
+ $body-1: null,
136
+ $body-2: null,
137
+ $caption: null,
138
+ $button: null,
139
+ $overline: null,
140
+ ) {
141
+ @return _apply-font-family($font-family, (
142
+ headline-1: $headline-1 or _rem-to-px(typography-config-level-from-mdc(headline1)),
143
+ headline-2: $headline-2 or _rem-to-px(typography-config-level-from-mdc(headline2)),
144
+ headline-3: $headline-3 or _rem-to-px(typography-config-level-from-mdc(headline3)),
145
+ headline-4: $headline-4 or _rem-to-px(typography-config-level-from-mdc(headline4)),
146
+ headline-5: $headline-5 or _rem-to-px(typography-config-level-from-mdc(headline5)),
147
+ headline-6: $headline-6 or _rem-to-px(typography-config-level-from-mdc(headline6)),
148
+ subtitle-1: $subtitle-1 or _rem-to-px(typography-config-level-from-mdc(subtitle1)),
149
+ subtitle-2: $subtitle-2 or _rem-to-px(typography-config-level-from-mdc(subtitle2)),
150
+ body-1: $body-1 or _rem-to-px(typography-config-level-from-mdc(body1)),
151
+ body-2: $body-2 or _rem-to-px(typography-config-level-from-mdc(body2)),
152
+ caption: $caption or _rem-to-px(typography-config-level-from-mdc(caption)),
153
+ button: $button or _rem-to-px(typography-config-level-from-mdc(button)),
154
+ overline: $overline or _rem-to-px(typography-config-level-from-mdc(overline)),
155
+ ));
156
+ }
157
+
158
+ /// Generates an Angular Material typography config based on values from the official Material
159
+ /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
160
+ /// the default values. The `mat-typography-level` function can be used to generate a custom
161
+ /// typography level map which can be passed to this function to override one of the default levels.
162
+ /// All default typography sizing generated by this function is in `rem` units.
163
+ ///
164
+ /// @param {String} $font-family The font family to use for levels where it is not explicitly
165
+ /// specified.
166
+ /// @param {Map} $headline-1 The font settings for the headline-1 font level.
167
+ /// @param {Map} $headline-2 The font settings for the headline-2 font level.
168
+ /// @param {Map} $headline-3 The font settings for the headline-3 font level.
169
+ /// @param {Map} $headline-4 The font settings for the headline-4 font level.
170
+ /// @param {Map} $headline-5 The font settings for the headline-5 font level.
171
+ /// @param {Map} $headline-6 The font settings for the headline-6 font level.
172
+ /// @param {Map} $subtitle-1 The font settings for the subtitle-1 font level.
173
+ /// @param {Map} $subtitle-2 The font settings for the subtitle-2 font level.
174
+ /// @param {Map} $body-1 The font settings for the body-1 font level.
175
+ /// @param {Map} $body-2 The font settings for the body-2 font level.
176
+ /// @param {Map} $caption The font settings for the caption font level.
177
+ /// @param {Map} $button The font settings for the button font level.
178
+ /// @param {Map} $overline The font settings for the overline font level.
179
+ /// @return {Map} A map containing font settings for each of the levels in the Material Design spec.
180
+ @function define-rem-typography-config(
181
+ // TODO(mmalerba): rename this function to define-typography-config,
182
+ // and create a predefined px based config for people that need it.
183
+ $font-family: mdc-typography.$font-family,
184
+ $headline-1: null,
185
+ $headline-2: null,
186
+ $headline-3: null,
187
+ $headline-4: null,
188
+ $headline-5: null,
189
+ $headline-6: null,
190
+ $subtitle-1: null,
191
+ $subtitle-2: null,
192
+ $body-1: null,
193
+ $body-2: null,
194
+ $caption: null,
195
+ $button: null,
196
+ $overline: null,
197
+ ) {
198
+ @return _apply-font-family($font-family, (
199
+ headline-1: $headline-1 or typography-config-level-from-mdc(headline1),
200
+ headline-2: $headline-2 or typography-config-level-from-mdc(headline2),
201
+ headline-3: $headline-3 or typography-config-level-from-mdc(headline3),
202
+ headline-4: $headline-4 or typography-config-level-from-mdc(headline4),
203
+ headline-5: $headline-5 or typography-config-level-from-mdc(headline5),
204
+ headline-6: $headline-6 or typography-config-level-from-mdc(headline6),
205
+ subtitle-1: $subtitle-1 or typography-config-level-from-mdc(subtitle1),
206
+ subtitle-2: $subtitle-2 or typography-config-level-from-mdc(subtitle2),
207
+ body-1: $body-1 or typography-config-level-from-mdc(body1),
208
+ body-2: $body-2 or typography-config-level-from-mdc(body2),
209
+ caption: $caption or typography-config-level-from-mdc(caption),
210
+ button: $button or typography-config-level-from-mdc(button),
211
+ overline: $overline or typography-config-level-from-mdc(overline),
212
+ ));
213
+ }
214
+
215
+ // Converts an MDC typography level config to an Angular Material one.
216
+ @function typography-config-level-from-mdc($mdc-level, $font-family: null) {
217
+ $mdc-level-config: map.get(mdc-typography.$styles, $mdc-level);
218
+
219
+ // Explicitly default the font family to null since we'll apply it globally
220
+ // through the `define-typgraphy-config`/`define-legacy-typography-config`.
221
+ @return define-typography-level(
222
+ $font-family: $font-family,
223
+ $font-size: map.get($mdc-level-config, font-size),
224
+ $line-height: map.get($mdc-level-config, line-height),
225
+ $font-weight: map.get($mdc-level-config, font-weight),
226
+ $letter-spacing: map.get($mdc-level-config, letter-spacing)
227
+ );
228
+ }
229
+
230
+ // Converts a map containing rem values to a map containing px values.
231
+ @function _rem-to-px($x, $px-per-rem: 16px) {
232
+ @if meta.type-of($x) == 'map' {
233
+ @each $key, $val in $x {
234
+ $x: map.merge($x, ($key: _rem-to-px($val)));
235
+ }
236
+ @return $x;
237
+ }
238
+ @if meta.type-of($x) == 'number' and math.unit($x) == 'rem' {
239
+ @return math.div($x, 1rem) * $px-per-rem;
240
+ }
241
+ @else {
242
+ @return $x;
243
+ }
244
+ }
245
+
246
+ // Applies the default font family to all levels in a typography config.
247
+ @function _apply-font-family($font-family, $initial-config) {
248
+ $config: $initial-config;
249
+
250
+ @each $key, $level in $config {
251
+ @if map.get($level, 'font-family') == null {
252
+ // Sass maps are immutable so we have to re-assign the variable each time.
253
+ $config: map.set($config, $key, map.set($level, 'font-family', $font-family));
254
+ }
255
+ }
256
+
257
+ @return map.set($config, 'font-family', $font-family);
258
+ }
@@ -0,0 +1,63 @@
1
+ @use 'sass:map';
2
+ @use 'sass:meta';
3
+ @use 'sass:string';
4
+
5
+ // Utility for fetching a nested value from a typography config.
6
+ @function _mat-get-type-value($config, $level, $name) {
7
+ @if meta.type-of($config) != 'map' {
8
+ @error 'Typography config must be a map. Received #{meta.type-of($config)}.';
9
+ }
10
+
11
+ @if not map.has-key($config, $level) {
12
+ @error 'Typography config does not have a level called "#{$level}". ' +
13
+ 'Available levels are: #{map.keys($config)}.';
14
+ }
15
+
16
+ @return map.get(map.get($config, $level), $name);
17
+ }
18
+
19
+ /// Gets the font size for a level inside a typography config.
20
+ /// @param {Map} $config A typography config.
21
+ /// @param {Map} $level A typography level.
22
+ @function font-size($config, $level) {
23
+ @return _mat-get-type-value($config, $level, font-size);
24
+ }
25
+
26
+ /// Gets the line height for a level inside a typography config.
27
+ /// @param {Map} $config A typography config.
28
+ /// @param {Map} $level A typography level.
29
+ @function line-height($config, $level) {
30
+ @return _mat-get-type-value($config, $level, line-height);
31
+ }
32
+
33
+ /// Gets the font weight for a level inside a typography config.
34
+ /// @param {Map} $config A typography config.
35
+ /// @param {Map} $level A typography level.
36
+ @function font-weight($config, $level) {
37
+ @return _mat-get-type-value($config, $level, font-weight);
38
+ }
39
+
40
+ /// Gets the letter spacing for a level inside a typography config.
41
+ /// @param {Map} $config A typography config.
42
+ /// @param {Map} $level A typography level.
43
+ @function letter-spacing($config, $level) {
44
+ @return _mat-get-type-value($config, $level, letter-spacing);
45
+ }
46
+
47
+ /// Gets the font-family from a typography config and removes the quotes around it.
48
+ /// @param {Map} $config A typography config.
49
+ /// @param {Map} $level A typography level.
50
+ @function font-family($config, $level: null) {
51
+ @if meta.type-of($config) != 'map' {
52
+ @error 'Typography config must be a map. Received #{meta.type-of($config)}.';
53
+ }
54
+
55
+ $font-family: map.get($config, font-family);
56
+
57
+ @if $level != null {
58
+ $font-family: _mat-get-type-value($config, $level, font-family);
59
+ }
60
+
61
+ // Guard against unquoting non-string values, because it's deprecated.
62
+ @return if(meta.type-of($font-family) == string, string.unquote($font-family), $font-family);
63
+ }
@@ -1,69 +1,10 @@
1
1
  @use 'sass:list';
2
- @use 'sass:map';
3
2
  @use 'sass:math';
4
- @use 'sass:meta';
5
- @use 'sass:string';
3
+ @use './property-getters';
6
4
 
7
-
8
- // Utility for fetching a nested value from a typography config.
9
- @function _mat-get-type-value($config, $level, $name) {
10
- @if meta.type-of($config) != 'map' {
11
- @error 'Typography config must be a map. Received #{meta.type-of($config)}.';
12
- }
13
-
14
- @if not map.has-key($config, $level) {
15
- @error 'Typography config does not have a level called "#{$level}". ' +
16
- 'Available levels are: #{map.keys($config)}.';
17
- }
18
-
19
- @return map.get(map.get($config, $level), $name);
20
- }
21
-
22
- /// Gets the font size for a level inside a typography config.
23
- /// @param {Map} $config A typography config.
24
- /// @param {Map} $level A typography level.
25
- @function font-size($config, $level) {
26
- @return _mat-get-type-value($config, $level, font-size);
27
- }
28
-
29
- /// Gets the line height for a level inside a typography config.
30
- /// @param {Map} $config A typography config.
31
- /// @param {Map} $level A typography level.
32
- @function line-height($config, $level) {
33
- @return _mat-get-type-value($config, $level, line-height);
34
- }
35
-
36
- /// Gets the font weight for a level inside a typography config.
37
- /// @param {Map} $config A typography config.
38
- /// @param {Map} $level A typography level.
39
- @function font-weight($config, $level) {
40
- @return _mat-get-type-value($config, $level, font-weight);
41
- }
42
-
43
- /// Gets the letter spacing for a level inside a typography config.
44
- /// @param {Map} $config A typography config.
45
- /// @param {Map} $level A typography level.
46
- @function letter-spacing($config, $level) {
47
- @return _mat-get-type-value($config, $level, letter-spacing);
48
- }
49
-
50
- /// Gets the font-family from a typography config and removes the quotes around it.
51
- /// @param {Map} $config A typography config.
52
- /// @param {Map} $level A typography level.
53
- @function font-family($config, $level: null) {
54
- @if meta.type-of($config) != 'map' {
55
- @error 'Typography config must be a map. Received #{meta.type-of($config)}.';
56
- }
57
-
58
- $font-family: map.get($config, font-family);
59
-
60
- @if $level != null {
61
- $font-family: _mat-get-type-value($config, $level, font-family);
62
- }
63
-
64
- // Guard against unquoting non-string values, because it's deprecated.
65
- @return if(meta.type-of($font-family) == string, string.unquote($font-family), $font-family);
66
- }
5
+ // Property getters live in their own file to avoid circular dependencies, but we re-export them
6
+ // here so that historical imports from this file continue to work without needing to be updated.
7
+ @forward './property-getters';
67
8
 
68
9
  /// Outputs the shorthand `font` CSS property, based on a set of typography values. Falls back to
69
10
  /// the individual properties if a value that isn't allowed in the shorthand is passed in.
@@ -102,12 +43,11 @@
102
43
  // we deliberately do not use the font shorthand here because it overrides
103
44
  // certain font properties that can't be configured in the current typography
104
45
  // config, e.g. the font-variant-caps or font-feature-settings property
105
- font-size: font-size($config, $level);
106
- font-weight: font-weight($config, $level);
107
- line-height: line-height($config, $level);
108
- font-family: font-family($config, $level);
109
-
110
- letter-spacing: letter-spacing($config, $level);
46
+ font-size: property-getters.font-size($config, $level);
47
+ font-weight: property-getters.font-weight($config, $level);
48
+ line-height: property-getters.line-height($config, $level);
49
+ font-family: property-getters.font-family($config, $level);
50
+ letter-spacing: property-getters.letter-spacing($config, $level);
111
51
  }
112
52
 
113
53
  /// Coerce a value to `em` if it is a unitless number, otherwise returns