summaryrefslogtreecommitdiffstats
path: root/browser/components/storybook/docs/README.typography.stories.md
blob: 4b85d59ef8c3b334849aa505ea23188c76460d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# Typography
## Scale
[In-content pages and the browser chrome](https://acorn.firefox.com/latest/resources/browser-anatomy/desktop-ZaxCgqkt) follow different type scales due to the chrome relying on operating systems' font sizing, while in-content pages follow the type scale set by the design system.

We set `font: message-box` at the root of `common-shared.css` and `global.css` stylesheets so that both in-content and the chrome can have access to operating system font families.

We also don't specify line height units and rely on the default.

### In-content
<table class="sb-preview-design-tokens">
  <thead>
    <tr>
      <th>Name</th>
      <th>HTML class/tag or CSS token</th>
      <th>Preview</th>
      <th>Font size</th>
      <th>Font weight</th>
    </tr>
  </thead>
  <tbody>
    <tr>
    <th>Heading XLarge</th>
      <td><code>h1,<br/>.heading-xlarge</code></td>
      <td>
        ```html story
          <h1 class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</h1>
        ```
      </td>
      <td>
        <code>1.6rem</code> (<code>24px</code>)
      </td>
      <td>
        <code>600</code>
      </td>
    </tr>
    <tr>
      <th>Heading Large</th>
      <td><code>h2,<br/>.heading-large</code></td>
      <td>
        ```html story
          <h2 class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</h2>
        ```
      </td>
      <td>
        <code>1.467rem</code> (<code>22px</code>)
      </td>
      <td>
        <code>600</code>
      </td>
    </tr>
    <tr>
      <th>Heading Medium</th>
      <td><code>h3,<br/>.heading-medium</code></td>
      <td >
        ```html story
          <h3 class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</h3>
        ```
      </td>
      <td>
        <code>1.133rem</code> (<code>17px</code>)
      </td>
      <td>
        <code>600</code>
      </td>
    </tr>
    <tr>
      <th>Root (body)</th>
      <td><code>--font-size-root</code> set at the <code>:root</code> of <code>common-shared.css</code></td>
      <td>
        ```html story
          <p class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</p>
        ```
      </td>
      <td>
        <code>15px</code> (<code>1rem</code>)
      </td>
      <td>
        <code>normal</code>
      </td>
    </tr>
    <tr>
      <th>Body Small</th>
      <td><code>--font-size-small</code></td>
      <td>
        ```html story
          <p class="text-truncated-ellipsis sb-preview-font-size-small">The quick brown fox jumps over the lazy dog</p>
        ```
      </td>
      <td>
        <code>0.867rem</code> (<code>13px</code>)
      </td>
      <td>
        <code>normal</code>
      </td>
    </tr>
  </tbody>
</table>

### Chrome

The chrome solely relies on `font` declarations (it also relies on `font: menu` for panels) so that it can inherit the operating system font family **and** sizing in order for it to feel like it is part of the user's operating system. Keep in mind that font sizes and families vary between macOS, Windows, and Linux. Moreover, you will only see a difference between `font: message-box` and `font: menu` font sizes on macOS.

Note that there currently isn't a hierarchy of multiple headings on the chrome since every panel and modal that opens from it relies only on an `h1` for its title; so today, we just bold the existing fonts in order to create headings.

<table class="sb-preview-design-tokens">
  <thead>
    <tr>
      <th>Name</th>
      <th>Class</th>
      <th>Preview</th>
      <th>Font keyword</th>
      <th>Font weight</th>
    </tr>
  </thead>
  <tbody>
     <tr>
      <th>Menu Heading</th>
      <td><code>h1</code></td>
      <td class="sb-preview-chrome-typescale sb-preview-chrome-menu">
        ```html story
          <h1 class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</h1>
        ```
      </td>
      <td>
        <code>menu</code>
      </td>
      <td>
        <code>600</code>
      </td>
    </tr>
    <tr>
      <th>Menu</th>
      <td>Applied directly to panel classes in <code>panel.css</code> and <code>panelUI-shared.css</code></td>
      <td class="sb-preview-chrome-typescale sb-preview-chrome-menu">
         ```html story
          <p class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</p>
        ```
      </td>
      <td>
        <code>menu</code>
      </td>
      <td>
        <code>normal</code>
      </td>
    </tr>
    <tr>
      <th>Heading</th>
      <td><code>h1</code></td>
      <td class="sb-preview-chrome-typescale">
        ```html story
          <h1 class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</h1>
        ```
      </td>
      <td>
        <code>message-box</code>
      </td>
      <td>
        <code>600</code>
      </td>
    </tr>
    <tr>
      <th>Root (body)</th>
      <td><code>message-box</code> set at the <code>:root</code> of <code>global.css</code></td>
      <td class="sb-preview-chrome-typescale">
         ```html story
          <p class="text-truncated-ellipsis">The quick brown fox jumps over the lazy dog</p>
        ```
      </td>
      <td>
        <code>message-box</code>
      </td>
      <td>
        <code>normal</code>
      </td>
    </tr>
  </tbody>
</table>

## Design tokens
Type setting relies on design tokens for font size and font weight.

#### Font size
<table class="sb-preview-design-tokens">
  <thead>
    <tr>
      <th>Base token</th>
      <th>In-content value</th>
      <th>Chrome value</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>
        <code>--font-size-xxlarge</code>
      </th>
      <td>
        <code>1.6rem</code>
      </td>
      <td>
        <code>unset</code>
      </td>
    </tr>
    <tr>
      <th>
        <code>--font-size-xlarge</code>
      </th>
      <td>
        <code>1.467rem</code>
      </td>
      <td>
        <code>unset</code>
      </td>
    </tr>
    <tr>
      <th>
        <code>--font-size-large</code>
      </th>
      <td>
        <code>1.133rem</code>
      </td>
      <td>
        <code>unset</code>
      </td>
    </tr>
    <tr>
      <th>
        <code>--font-size-root</code>
      </th>
      <td>
        <code>15px</code>
      </td>
      <td>
        <code>unset</code>
      </td>
    </tr>
    <tr>
      <th>
        <code>--font-size-small</code>
      </th>
      <td>
        <code>0.867rem</code>
      </td>
      <td>
        <code>unset</code>
      </td>
    </tr>
  </tbody>
</table>


#### Font weight
<table class="sb-preview-design-tokens">
  <thead>
    <tr>
      <th>Base token</th>
      <th>In-content value</th>
      <th>Chrome value</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>
        <code>--font-weight-default</code>
      </th>
      <td>
        <code>normal</code>
      </td>
      <td>
        <code>normal</code>
      </td>
    </tr>
    <tr>
      <th>
        <code>--font-weight-bold</code>
      </th>
      <td>
        <code>600</code>
      </td>
      <td>
        <code>600</code>
      </td>
    </tr>
  </tbody>
</table>

## Helpers
### text-and-typography.css

The text and typography stylesheet found in `toolkit/themes/shared/design-system/text-and-typography.css` contains type setting declarations, and text and typography helper classes:

-  It applies the design system's type scale by default, therefore it styles the `root` and headings automatically.
-  It comes with helper classes for contexts where designers may visually prefer an `h1` to start at the "medium" heading size instead of "large" (e.g. Shopping sidebar). It also contains text related helpers for truncating and deemphasizing text.

You should rely on typography helper classes and the defaults set by the design system.

This file is imported into `common-shared.css` and `global-shared.css` so that both in-content pages and the chrome receive their respective typography scale treatments, and have access to helper classes.

#### Heading
##### XLarge (h1)
###### In-content
```html story
  <h1>Firefox View</h1>
```

###### Chrome
```html story
  <h1 class="sb-preview-chrome-typescale">Close window and quit Firefox?</h1>
```

###### Chrome menus
```html story
  <h1 class="sb-preview-chrome-typescale sb-preview-chrome-menu">Edit bookmark</h1>
```

```css story
h1,
.heading-xlarge {
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xxlarge);
}
```

*Reminder: There's no hierarchy of headings on the chrome. So here's just in-content's preview:*

##### Large (h2)
```html story
  <h2>Recent browsing</h2>
```

```css story
h2,
.heading-large {
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xlarge);
}
```

##### Medium (h3)
```html story
  <h3>Tabs from other devices</h3>
```

```css story
h3,
.heading-medium {
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-large);
}
```

#### Text
##### De-emphasized

```html story
  <span class="text-deemphasized">Get your passwords on your other devices.</span>
```

```css story
.text-deemphasized {
  font-size: var(--font-size-small);
  color: var(--text-color-deemphasized);
}
```

##### Truncated ellipsis

```html story
  <div class="text-truncated-ellipsis">A really long piece of text a really long piece of text a really long piece of text a really long piece of text a really long piece of text a really long piece of text.</div>
```

```css story
.text-truncated-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
```

`.text-truncated-ellipsis` can be applied to `display: block` or `display: inline-block` elements.

For `display: flex` or `display: grid` elements, you'll need to wrap its contents with an element with the `.text-truncated-ellipsis` class instead.

Example:

```html
<div class="my-flex-element">
  <span class="text-truncated-ellipsis">A really long string of text that needs truncation.</span>
</div>
```