Skip to content

Commit 865863d

Browse files
Refactor typography system to use CSS custom properties (#1107)
Refactor typography system to use CSS custom properties. This is the first PR in a refactor of how we use CSS variables (#982) and renaming title to heading (#668). Some kind of basic fallback support for older browsers will be added back in a latter PR once we can get a clear picture of how broken things are. I know this looks big but for the most part it's just a straight find/replace on variable names or moving @includes to the end of declarations. Modernization: Default to CSS vars for font family, size, and line-height Removed @supports declarations if they only had font declarations @include text-body-* and @include text-heading-* mixins use CSS vars now Edited @mixin font-size() to stop outputting a pixel fallback Reorganization: Renamed -title- to -heading- in mixins and CSS vars and mzp-u-heading-* utility classes component HTML/CSS classes will follow in a separate PR Added font-family declaration to @include text-body-* mixins Added --theme- prefix to variables expected to morph Added --token- prefix to unchanging variables Re-name font-size tokens to use a scale instead of tshirt sizes for names Added --theme-button-line-height var Bug fixes: Moved @include text-* to end of declarations
1 parent a3bbf09 commit 865863d

51 files changed

Lines changed: 788 additions & 956 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
1+
# HEAD
2+
3+
This version introduces some major modernization changes around CSS and drops browser support for XXXX ( to be defined before V23 is published).
4+
5+
The good news is we don't expect any visible changes in modern browsers and you should be able to do some automated visual regression testing to help with the migration.
6+
7+
Introducing theme variables! CSS variables beginning with `--theme-` will adjust based on media queries.
8+
9+
10+
## Typography
11+
12+
* Modernization:
13+
* Default to CSS vars for font family, size, and line-height (#982)
14+
* Removed `@supports` declarations if they only had font declarations
15+
* `@include text-body-*` and `@include text-heading-*` mixins use CSS vars now
16+
* Edited `@mixin font-size()` to stop outputting a pixel fallback
17+
* Reorganization:
18+
* Renamed `-title-` to `-heading-` in mixins and CSS vars
19+
* and `mzp-u-heading-*` utility classes
20+
* component HTML/CSS classes will follow in a separate PR
21+
* Added font-family declaration to `@include text-body-*` mixins
22+
* Added `--theme-` prefix to variables expected to morph
23+
* Added `--token-` prefix to unchanging variables
24+
* Re-name font-size tokens to use a scale instead of tshirt sizes for names
25+
* Added `--theme-button-line-height` var
26+
* Bug fixes:
27+
* Moved `@include text-*` to end of declarations
28+
29+
## Color
30+
31+
* To come in follow up PR.
32+
33+
## Migration Tips
34+
35+
See the [Migration Guide](https://protocol.mozilla.org/docs/usage/migration) for automated scripts (VS Code find/replace and terminal commands) to help with these changes.
36+
37+
* Browser support
38+
* If you require support for older browsers we recommend adding some post-processing to your workflow for CSS variables and font sizes in pixels.
39+
* Rename typography mixins `text-title-(2xs|3xs|xs|sm|md|lg|xl|2xl)``text-heading-$1`
40+
* Rename utility classes `mzp-u-title-(2xs|3xs|xs|sm|md|lg|xl|2xl)``mzp-u-heading-$1`
41+
* Replace any remaining `text-display-*` usage with the equivalent `text-heading-*` mixin:
42+
* `text-display-xx([sl])``text-heading-2x$1`
43+
* `text-display-(xs|sm|md|lg|xl)``text-heading-$1`
44+
* Rename CSS variables to use pattern `--theme-<component>-<property>-<scale>`:
45+
* `--body-font-family``--theme-body-font-family`
46+
* `--title-font-family``--theme-heading-font-family`
47+
* `--body-line-height``--theme-body-line-height`
48+
* `--title-(2xs|3xs|xs|sm|md|lg|xl|2xl)-size``--theme-heading-font-size-$1`
49+
* `--body-(xs|sm|md|lg|xl)-size``--theme-body-font-size-$1`
50+
* `--title-(2xs|3xs|xs|sm|md|lg|xl|2xl)-line-height``--theme-heading-line-height-$1`
51+
* Removed Sass variables (use CSS variables instead):
52+
* `$title-(2xs|3xs|xs|sm|md|lg|xl|2xl)-size``var(--theme-heading-font-size-$1)`
53+
* `$title-(2xs|3xs|xs|sm|md|lg|xl|2xl)-line-height``var(--theme-heading-line-height-$1)`
54+
* `$body-line-height``var(--theme-body-line-height)`
55+
* `$body-(xs|sm|md|lg|xl)-size``var(--theme-body-font-size-$1)`
56+
* `$body-font-family``var(--theme-body-font-family)`
57+
* `$title-font-family``var(--theme-heading-font-family)`
58+
* `$button-font-family``var(--theme-button-font-family)`
59+
* `$text-body-line-height``var(--theme-body-line-height)`
60+
* `$text-title-line-height``var(--theme-heading-line-height)`
61+
* `$text-display-line-height``var(--theme-body-line-height)`
62+
* `text-body-*` mixins now declare `font-family`.
63+
* You can remove any `font-family` declarations from places which use these mixins (unless you don't want the default font).
64+
* Removed mixins and functions:
65+
* `type-scale()` function and associated lookup tables
66+
* `text-body-cta` mixin (use `text-body-md` instead)
67+
* You can remove `@supports (--css: variables)` blocks that only contain font declarations, as CSS custom properties are now required.
68+
169
# 22.0.0
270

371
## Features
@@ -200,7 +268,7 @@ stating variables explicitly, like this:
200268
@supports (--css: variables) {
201269
background-color: var(--background-color-inverse);
202270
color: var(--body-text-color-inverse);
203-
line-height: var(--body-line-height);
271+
line-height: var(--token-body-line-height);
204272
}
205273
}
206274
```

assets/sass/protocol/base/elements/_document.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ html {
1010
}
1111

1212
body {
13-
@include text-body-md;
1413
background: $background-color;
1514
color: $body-text-color;
16-
font-family: $body-font-family;
17-
line-height: $body-line-height;
1815
-moz-osx-font-smoothing: grayscale;
1916
-webkit-font-smoothing: antialiased;
17+
@include text-body-md;
2018

2119
@supports (--css: variable) {
2220
background: var(--background-color);
2321
color: var(--body-text-color);
24-
font-family: var(--body-font-family);
25-
line-height: var(--body-line-height);
2622
}
2723
}
2824

assets/sass/protocol/base/elements/_forms.scss

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ legend {
2828
max-width: 100%; // 1
2929
padding: 0; // 3
3030
white-space: normal; // 1
31-
.mzp-u-inline & {
32-
@include forms.field-label;
33-
}
34-
@include text-body-lg;
35-
font-family: $body-font-family;
36-
font-weight: bold;
3731
margin-bottom: forms.$field-v-spacing;
32+
font-weight: bold;
33+
@include text-body-lg;
3834

39-
@supports (--css: variables) {
40-
font-family: var(--body-font-family);
35+
.mzp-u-inline & {
36+
@include forms.field-label;
4137
}
4238
}
4339

@@ -46,9 +42,14 @@ input,
4642
select,
4743
optgroup,
4844
textarea {
49-
@include font-base;
5045
@include text-body-md;
51-
line-height: 1.25;
46+
@include font-base;
47+
48+
/* stylelint-disable-next-line no-duplicate-selectors */
49+
& {
50+
// needs to come after @includes to over-ride value
51+
line-height: var(--theme-button-line-height);
52+
}
5253
}
5354

5455
button,
@@ -249,7 +250,7 @@ input[type='file'] {
249250
background: $color-white;
250251
border-radius: forms.$field-border-radius;
251252
border: forms.$field-border;
252-
line-height: 1.25;
253+
line-height: var(--theme-button-line-height);
253254
margin: 0 0 forms.$field-v-spacing;
254255

255256
&:hover {

assets/sass/protocol/base/elements/_links.scss

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ a {
4848
}
4949

5050
.mzp-c-cta-link {
51-
font-family: $button-font-family;
51+
font-family: var(--theme-button-font-family);
5252
font-weight: bold;
5353

54-
@supports (--css: variables) {
55-
font-family: var(--button-font-family);
56-
}
57-
5854
&.mzp-t-xs {
5955
@include text-body-sm;
6056
}
@@ -68,30 +64,15 @@ a {
6864
}
6965

7066
&.mzp-t-lg {
71-
@include text-title-xs;
72-
font-family: $title-font-family;
73-
74-
@supports (--css: variables) {
75-
font-family: var(--title-font-family);
76-
}
67+
@include text-heading-xs;
7768
}
7869

7970
&.mzp-t-xl {
80-
@include text-title-sm;
81-
font-family: $title-font-family;
82-
83-
@supports (--css: variables) {
84-
font-family: var(--title-font-family);
85-
}
71+
@include text-heading-sm;
8672
}
8773

8874
&.mzp-t-2xl {
89-
@include text-title-lg;
90-
font-family: $title-font-family;
91-
92-
@supports (--css: variables) {
93-
font-family: var(--title-font-family);
94-
}
75+
@include text-heading-lg;
9576
}
9677

9778
// Icon support

assets/sass/protocol/base/elements/_quotes.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
blockquote {
88
@include bidi(((border-width, 0 0 0 5px, 0 5px 0 0),));
9-
@include text-title-sm;
9+
@include text-heading-sm;
1010
border-color: $color-marketing-gray-20;
1111
border-style: solid;
1212
color: $title-text-color;
13-
font-family: $title-font-family;
1413
font-weight: bold;
1514
margin: $spacing-lg auto;
1615
padding: $spacing-sm $spacing-lg;
1716

1817
cite {
19-
@include text-title-xs;
18+
@include text-heading-xs;
2019
color: $body-text-color-secondary;
2120

2221
&::before {
@@ -29,8 +28,7 @@ blockquote {
2928
}
3029

3130
@supports (--css: variables) {
32-
color: var(--title-text-color);
33-
font-family: var(--title-font-family);
31+
color: var(--heading-text-color);
3432

3533
cite {
3634
color: var(--body-text-color-secondary);

assets/sass/protocol/base/elements/_titles.scss

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ h3,
1212
h4,
1313
h5,
1414
h6 {
15-
$default-font-weight: bold;
16-
font-family: $title-font-family;
1715
color: $title-text-color;
18-
font-weight: $default-font-weight;
16+
font-family: var(--theme-heading-font-family);
17+
font-variant-ligatures: var(--theme-heading-font-ligatures);
18+
letter-spacing: var(--theme-heading-letter-spacing);
1919
text-wrap: balance;
2020
margin: 0 0 0.5em;
2121

@@ -24,40 +24,36 @@ h6 {
2424
}
2525

2626
@supports (--css: variables) {
27-
font-family: var(--title-font-family);
28-
font-variant-ligatures: var(--title-font-ligatures);
29-
font-weight: var(--title-font-weight, #{$default-font-weight});
30-
letter-spacing: var(--title-letter-spacing);
31-
color: var(--title-text-color);
27+
color: var(--heading-text-color);
3228

3329
.mzp-t-dark & {
34-
color: var(--title-text-color-inverse);
30+
color: var(--heading-text-color-inverse);
3531
}
3632
}
3733
}
3834

3935
// Type scale mixins can be found in includes/mixins/_typography.scss
4036
// Sizes are defined in includes/_themes.scss
4137
h1 {
42-
@include text-title-lg;
38+
@include text-heading-lg;
4339
}
4440

4541
h2 {
46-
@include text-title-md;
42+
@include text-heading-md;
4743
}
4844

4945
h3 {
50-
@include text-title-sm;
46+
@include text-heading-sm;
5147
}
5248

5349
h4 {
54-
@include text-title-xs;
50+
@include text-heading-xs;
5551
}
5652

5753
h5 {
58-
@include text-title-2xs;
54+
@include text-heading-2xs;
5955
}
6056

6157
h6 {
62-
@include text-title-3xs;
58+
@include text-heading-3xs;
6359
}

assets/sass/protocol/base/utilities/_rich-text.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
@use '../../includes/lib' as *;
6-
@import '../../base/elements/tables';
6+
@use '../../base/elements/tables' as *;
77

88
.mzp-u-rich-text {
99
h2 {
@@ -17,10 +17,9 @@
1717
}
1818

1919
h4 {
20-
@include text-body-lg;
21-
font-family: var(--body-font-family);
2220
margin-bottom: $layout-xs;
2321
margin-top: $layout-xs;
22+
@include text-body-lg;
2423
}
2524

2625
@media #{$mq-md} {

0 commit comments

Comments
 (0)