Skip to content

Commit 412d782

Browse files
Convert typography to use rem units with px fallbacks (#2302)
* add temp vars * base styles * lint * cleanup * lint * Create nervous-experts-camp.md * lint * Stylelint auto-fixes * Update nervous-experts-camp.md Co-authored-by: Actions Auto Build <[email protected]>
1 parent 3b397d9 commit 412d782

File tree

7 files changed

+204
-88
lines changed

7 files changed

+204
-88
lines changed

.changeset/nervous-experts-camp.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": minor
3+
---
4+
5+
Convert typography to use `rem` units with `px` fallbacks

src/base/base.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// stylelint-disable selector-max-type, selector-no-qualifying-type
1+
// stylelint-disable selector-max-type, selector-no-qualifying-type, primer/typography
22
* {
33
box-sizing: border-box;
44
}
@@ -14,7 +14,7 @@ button {
1414

1515
body {
1616
font-family: $body-font;
17-
font-size: $body-font-size;
17+
font-size: var(--body-font-size, $body-font-size);
1818
line-height: $body-line-height;
1919
color: var(--color-fg-default);
2020
background-color: var(--color-canvas-default);

src/primitives/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
@import '@primer/primitives/tokens-v2-private/css/tokens/functional/size/size.css';
88
@import '@primer/primitives/tokens-v2-private/css/tokens/functional/size/viewport.css';
99
@import '@primer/primitives/tokens-v2-private/css/tokens/functional/typography/typography.css';
10+
@import './temp-typography-tokens.scss';
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Temporary typography vars in rem units variables
2+
:root {
3+
// Heading sizes - mobile
4+
// h4-h6 remain the same size on both mobile & desktop
5+
--h00-size-mobile: 2.5rem;
6+
--h0-size-mobile: 2rem;
7+
--h1-size-mobile: 1.625rem;
8+
--h2-size-mobile: 1.375rem;
9+
--h3-size-mobile: 1.125rem;
10+
11+
// Heading sizes - desktop
12+
--h00-size: 3rem;
13+
--h0-size: 2.5rem;
14+
--h1-size: 2rem;
15+
--h2-size: 1.5rem;
16+
--h3-size: 1.25rem;
17+
--h4-size: 1rem;
18+
--h5-size: 0.875rem;
19+
--h6-size: 0.75rem;
20+
--body-font-size: 0.875rem;
21+
--font-size-small: 0.75rem;
22+
}

src/support/mixins/typography.scss

+18-12
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,63 @@
1010
// Heading mixins for use within components
1111
// These match heading utilities in utilities/typography
1212
@mixin h1 {
13-
font-size: $h1-size;
13+
font-size: var(--h1-size, $h1-size);
1414
font-weight: $font-weight-bold;
1515
}
1616

1717
@mixin h2 {
18-
font-size: $h2-size;
18+
font-size: var(--h2-size, $h2-size);
1919
font-weight: $font-weight-bold;
2020
}
2121

2222
@mixin h3 {
23-
font-size: $h3-size;
23+
font-size: var(--h3-size, $h3-size);
2424
font-weight: $font-weight-bold;
2525
}
2626

2727
@mixin h4 {
28-
font-size: $h4-size;
28+
font-size: var(--h4-size, $h4-size);
2929
font-weight: $font-weight-bold;
3030
}
3131

3232
@mixin h5 {
33-
font-size: $h5-size;
33+
font-size: var(--h5-size, $h5-size);
3434
font-weight: $font-weight-bold;
3535
}
3636

3737
@mixin h6 {
38-
font-size: $h6-size;
38+
font-size: var(--h6-size, $h6-size);
3939
font-weight: $font-weight-bold;
4040
}
4141

4242
// Responsive heading mixins
4343
// There are no responsive mixins for h4-h6 because they are small
4444
// and don't need to be smaller on mobile.
4545
@mixin f1-responsive {
46-
font-size: $h1-size-mobile;
46+
font-size: var(--h1-size-mobile, $h1-size-mobile);
4747

4848
// 32px on desktop
49-
@include breakpoint(md) { font-size: $h1-size; }
49+
@include breakpoint(md) {
50+
font-size: var(--h1-size, $h1-size);
51+
}
5052
}
5153

5254
@mixin f2-responsive {
53-
font-size: $h2-size-mobile;
55+
font-size: var(--h2-size-mobile, $h2-size-mobile);
5456

5557
// 24px on desktop
56-
@include breakpoint(md) { font-size: $h2-size; }
58+
@include breakpoint(md) {
59+
font-size: var(--h2-size, $h2-size);
60+
}
5761
}
5862

5963
@mixin f3-responsive {
60-
font-size: $h3-size-mobile;
64+
font-size: var(--h3-size-mobile, $h3-size-mobile);
6165

6266
// 20px on desktop
63-
@include breakpoint(md) { font-size: $h3-size; }
67+
@include breakpoint(md) {
68+
font-size: var(--h3-size, $h3-size);
69+
}
6470
}
6571

6672
// These use the mixins from above for responsive heading sizes.

src/support/variables/typography.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ $h6-size: 12px !default;
2121
$font-size-small: 12px !default;
2222

2323
// Font weights
24-
$font-weight-bold: 600 !default;
25-
$font-weight-semibold: 500 !default;
26-
$font-weight-normal: 400 !default;
27-
$font-weight-light: 300 !default;
24+
$font-weight-bold: var(--base-text-weight-medium, 600) !default;
25+
$font-weight-semibold: var(--base-text-weight-semibold, 500) !default;
26+
$font-weight-normal: var(--base-text-weight-normal, 400) !default;
27+
$font-weight-light: var(--base-text-weight-light, 300) !default;
2828

2929
// Line heights
3030
$lh-condensed-ultra: 1 !default;

0 commit comments

Comments
 (0)