|
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';
|
|
47 | 43 | // (where define-typography-config is defined) because putting it there would cause a circular
|
48 | 44 | // dependency with mdc-helpers. We should refactor so these can live in the same place.
|
49 | 45 |
|
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 |
| - |
194 | 46 | // Includes all of the typographic styles.
|
195 | 47 | @mixin all-component-typographies($config-or-theme: null) {
|
196 | 48 | $config: if(theming.private-is-theme-object($config-or-theme),
|
|
0 commit comments