|
| 1 | +@use '@material/typography' as mdc-typography; |
1 | 2 | @use 'sass:map';
|
2 | 3 | @use 'sass:math';
|
3 | 4 | @use 'sass:meta';
|
|
62 | 63 | }
|
63 | 64 | }
|
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 | + |
65 | 80 | /// Generates an Angular Material typography config based on values from the official Material
|
66 | 81 | /// Design spec implementation (MDC Web). All arguments are optional, but may be passed to override
|
67 | 82 | /// the default values. The `mat-typography-level` function can be used to generate a custom
|
|
87 | 102 | @function define-typography-config(
|
88 | 103 | // TODO(mmalerba): rename this function to define-typography-config,
|
89 | 104 | // and create a predefined px based config for people that need it.
|
90 |
| - $font-family: null, |
| 105 | + $font-family: mdc-typography.$font-family, |
91 | 106 | $headline-1: null,
|
92 | 107 | $headline-2: null,
|
93 | 108 | $headline-3: null,
|
|
102 | 117 | $button: null,
|
103 | 118 | $overline: null,
|
104 | 119 | ) {
|
105 |
| - // Declare an initial map with all of the levels. |
106 |
| - $overrides: if($font-family, (font-family: $font-family), ()); |
107 |
| - |
108 |
| - @return ( |
109 |
| - headline-1: $headline-1 or _rem-to-px( |
110 |
| - mdc-helpers.typography-config-level-from-mdc(headline1, $overrides)), |
111 |
| - headline-2: $headline-2 or _rem-to-px( |
112 |
| - mdc-helpers.typography-config-level-from-mdc(headline2, $overrides)), |
113 |
| - headline-3: $headline-3 or _rem-to-px( |
114 |
| - mdc-helpers.typography-config-level-from-mdc(headline3, $overrides)), |
115 |
| - headline-4: $headline-4 or _rem-to-px( |
116 |
| - mdc-helpers.typography-config-level-from-mdc(headline4, $overrides)), |
117 |
| - headline-5: $headline-5 or _rem-to-px( |
118 |
| - mdc-helpers.typography-config-level-from-mdc(headline5, $overrides)), |
119 |
| - headline-6: $headline-6 or _rem-to-px( |
120 |
| - mdc-helpers.typography-config-level-from-mdc(headline6, $overrides)), |
121 |
| - subtitle-1: $subtitle-1 or _rem-to-px( |
122 |
| - mdc-helpers.typography-config-level-from-mdc(subtitle1, $overrides)), |
123 |
| - subtitle-2: $subtitle-2 or _rem-to-px( |
124 |
| - mdc-helpers.typography-config-level-from-mdc(subtitle2, $overrides)), |
125 |
| - body-1: $body-1 or _rem-to-px( |
126 |
| - mdc-helpers.typography-config-level-from-mdc(body1, $overrides)), |
127 |
| - body-2: $body-2 or _rem-to-px( |
128 |
| - mdc-helpers.typography-config-level-from-mdc(body2, $overrides)), |
129 |
| - caption: $caption or _rem-to-px( |
130 |
| - mdc-helpers.typography-config-level-from-mdc(caption, $overrides)), |
131 |
| - button: $button or _rem-to-px( |
132 |
| - mdc-helpers.typography-config-level-from-mdc(button, $overrides)), |
133 |
| - overline: $overline or _rem-to-px( |
134 |
| - mdc-helpers.typography-config-level-from-mdc(overline, $overrides)), |
135 |
| - ); |
| 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 | + )); |
136 | 135 | }
|
137 | 136 |
|
138 | 137 | /// Generates an Angular Material typography config based on values from the official Material
|
|
160 | 159 | @function define-rem-typography-config(
|
161 | 160 | // TODO(mmalerba): rename this function to define-typography-config,
|
162 | 161 | // and create a predefined px based config for people that need it.
|
163 |
| - $font-family: null, |
| 162 | + $font-family: mdc-typography.$font-family, |
164 | 163 | $headline-1: null,
|
165 | 164 | $headline-2: null,
|
166 | 165 | $headline-3: null,
|
|
175 | 174 | $button: null,
|
176 | 175 | $overline: null,
|
177 | 176 | ) {
|
178 |
| - // Declare an initial map with all of the levels. |
179 |
| - $overrides: if($font-family, (font-family: $font-family), ()); |
180 |
| - |
181 |
| - @return ( |
182 |
| - headline-1: $headline-1 or mdc-helpers.typography-config-level-from-mdc(headline1, $overrides), |
183 |
| - headline-2: $headline-2 or mdc-helpers.typography-config-level-from-mdc(headline2, $overrides), |
184 |
| - headline-3: $headline-3 or mdc-helpers.typography-config-level-from-mdc(headline3, $overrides), |
185 |
| - headline-4: $headline-4 or mdc-helpers.typography-config-level-from-mdc(headline4, $overrides), |
186 |
| - headline-5: $headline-5 or mdc-helpers.typography-config-level-from-mdc(headline5, $overrides), |
187 |
| - headline-6: $headline-6 or mdc-helpers.typography-config-level-from-mdc(headline6, $overrides), |
188 |
| - subtitle-1: $subtitle-1 or mdc-helpers.typography-config-level-from-mdc(subtitle1, $overrides), |
189 |
| - subtitle-2: $subtitle-2 or mdc-helpers.typography-config-level-from-mdc(subtitle2, $overrides), |
190 |
| - body-1: $body-1 or mdc-helpers.typography-config-level-from-mdc(body1, $overrides), |
191 |
| - body-2: $body-2 or mdc-helpers.typography-config-level-from-mdc(body2, $overrides), |
192 |
| - caption: $caption or mdc-helpers.typography-config-level-from-mdc(caption, $overrides), |
193 |
| - button: $button or mdc-helpers.typography-config-level-from-mdc(button, $overrides), |
194 |
| - overline: $overline or mdc-helpers.typography-config-level-from-mdc(overline, $overrides), |
195 |
| - ); |
| 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 | + )); |
196 | 192 | }
|
197 | 193 |
|
198 | 194 | // Includes all of the typographic styles.
|
|
0 commit comments