@carbon/type 10.1.1 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,673 @@
1
+ //
2
+ // Copyright IBM Corp. 2018, 2018
3
+ //
4
+ // This source code is licensed under the Apache-2.0 license found in the
5
+ // LICENSE file in the root directory of this source tree.
6
+ //
7
+
8
+ @import '../vendor/@carbon/layout/breakpoint';
9
+ @import 'scale';
10
+
11
+ /// @type Map
12
+ /// @access public
13
+ /// @group @carbon/type
14
+ $caption-01: (
15
+ font-size: carbon--type-scale(1),
16
+ font-weight: carbon--font-weight('regular'),
17
+ line-height: carbon--rem(16px),
18
+ letter-spacing: 0.32px,
19
+ ) !default;
20
+
21
+ /// @type Map
22
+ /// @access public
23
+ /// @group @carbon/type
24
+ $label-01: (
25
+ font-size: carbon--type-scale(1),
26
+ font-weight: carbon--font-weight('regular'),
27
+ line-height: carbon--rem(16px),
28
+ letter-spacing: 0.32px,
29
+ ) !default;
30
+
31
+ /// @type Map
32
+ /// @access public
33
+ /// @group @carbon/type
34
+ $helper-text-01: (
35
+ font-size: carbon--type-scale(1),
36
+ font-style: italic,
37
+ line-height: carbon--rem(16px),
38
+ letter-spacing: 0.32px,
39
+ ) !default;
40
+
41
+ /// @type Map
42
+ /// @access public
43
+ /// @group @carbon/type
44
+ $body-short-01: (
45
+ font-size: carbon--type-scale(2),
46
+ font-weight: carbon--font-weight('regular'),
47
+ line-height: carbon--rem(18px),
48
+ letter-spacing: 0.16px,
49
+ ) !default;
50
+
51
+ /// @type Map
52
+ /// @access public
53
+ /// @group @carbon/type
54
+ $body-long-01: (
55
+ font-size: carbon--type-scale(2),
56
+ font-weight: carbon--font-weight('regular'),
57
+ line-height: carbon--rem(20px),
58
+ letter-spacing: 0.16px,
59
+ ) !default;
60
+
61
+ /// @type Map
62
+ /// @access public
63
+ /// @group @carbon/type
64
+ $body-short-02: (
65
+ font-size: carbon--type-scale(3),
66
+ font-weight: carbon--font-weight('regular'),
67
+ line-height: carbon--rem(22px),
68
+ letter-spacing: 0,
69
+ ) !default;
70
+
71
+ /// @type Map
72
+ /// @access public
73
+ /// @group @carbon/type
74
+ $body-long-02: (
75
+ font-size: carbon--type-scale(3),
76
+ font-weight: carbon--font-weight('regular'),
77
+ line-height: carbon--rem(24px),
78
+ letter-spacing: 0,
79
+ ) !default;
80
+
81
+ /// @type Map
82
+ /// @access public
83
+ /// @group @carbon/type
84
+ $code-01: (
85
+ font-size: carbon--type-scale(1),
86
+ font-weight: carbon--font-weight('regular'),
87
+ line-height: carbon--rem(16px),
88
+ letter-spacing: 0.32px,
89
+ ) !default;
90
+
91
+ /// @type Map
92
+ /// @access public
93
+ /// @group @carbon/type
94
+ $code-02: (
95
+ font-size: carbon--type-scale(2),
96
+ font-weight: carbon--font-weight('regular'),
97
+ line-height: carbon--rem(20px),
98
+ letter-spacing: 0.32px,
99
+ ) !default;
100
+
101
+ /// @type Map
102
+ /// @access public
103
+ /// @group @carbon/type
104
+ $heading-01: (
105
+ font-size: carbon--type-scale(2),
106
+ font-weight: carbon--font-weight('semibold'),
107
+ line-height: carbon--rem(18px),
108
+ letter-spacing: 0.16px,
109
+ ) !default;
110
+
111
+ /// @type Map
112
+ /// @access public
113
+ /// @group @carbon/type
114
+ $productive-heading-01: $heading-01 !default;
115
+
116
+ /// @type Map
117
+ /// @access public
118
+ /// @group @carbon/type
119
+ $heading-02: (
120
+ font-size: carbon--type-scale(3),
121
+ font-weight: carbon--font-weight('semibold'),
122
+ line-height: carbon--rem(22px),
123
+ letter-spacing: 0,
124
+ ) !default;
125
+
126
+ /// @type Map
127
+ /// @access public
128
+ /// @group @carbon/type
129
+ $productive-heading-02: $heading-02 !default;
130
+
131
+ /// @type Map
132
+ /// @access public
133
+ /// @group @carbon/type
134
+ $productive-heading-03: (
135
+ font-size: carbon--type-scale(5),
136
+ font-weight: carbon--font-weight('regular'),
137
+ line-height: carbon--rem(26px),
138
+ letter-spacing: 0,
139
+ ) !default;
140
+
141
+ /// @type Map
142
+ /// @access public
143
+ /// @group @carbon/type
144
+ $productive-heading-04: (
145
+ font-size: carbon--type-scale(7),
146
+ font-weight: carbon--font-weight('regular'),
147
+ line-height: carbon--rem(36px),
148
+ letter-spacing: 0,
149
+ ) !default;
150
+
151
+ /// @type Map
152
+ /// @access public
153
+ /// @group @carbon/type
154
+ $productive-heading-05: (
155
+ font-size: carbon--type-scale(8),
156
+ font-weight: carbon--font-weight('regular'),
157
+ line-height: carbon--rem(40px),
158
+ letter-spacing: 0,
159
+ ) !default;
160
+
161
+ /// @type Map
162
+ /// @access public
163
+ /// @group @carbon/type
164
+ $productive-heading-06: (
165
+ font-size: carbon--type-scale(8),
166
+ font-weight: carbon--font-weight('light'),
167
+ line-height: carbon--rem(50px),
168
+ letter-spacing: 0,
169
+ ) !default;
170
+
171
+ /// @type Map
172
+ /// @access public
173
+ /// @group @carbon/type
174
+ $productive-heading-07: (
175
+ font-size: carbon--type-scale(10),
176
+ font-weight: carbon--font-weight('light'),
177
+ line-height: carbon--rem(64px),
178
+ letter-spacing: 0,
179
+ ) !default;
180
+
181
+ /// @type Map
182
+ /// @access public
183
+ /// @group @carbon/type
184
+ $expressive-heading-01: $heading-01 !default;
185
+
186
+ /// @type Map
187
+ /// @access public
188
+ /// @group @carbon/type
189
+ $expressive-heading-02: $heading-02 !default;
190
+
191
+ /// @type Map
192
+ /// @access public
193
+ /// @group @carbon/type
194
+ $expressive-heading-03: (
195
+ font-size: carbon--type-scale(5),
196
+ font-weight: carbon--font-weight('regular'),
197
+ line-height: 130%,
198
+ letter-spacing: 0,
199
+ breakpoints: (
200
+ xlg: (
201
+ font-size: carbon--type-scale(5),
202
+ line-height: 125%,
203
+ ),
204
+ max: (
205
+ font-size: carbon--type-scale(6),
206
+ ),
207
+ ),
208
+ ) !default;
209
+
210
+ /// @type Map
211
+ /// @access public
212
+ /// @group @carbon/type
213
+ $expressive-heading-04: (
214
+ font-size: carbon--type-scale(7),
215
+ font-weight: carbon--font-weight('regular'),
216
+ line-height: 129%,
217
+ letter-spacing: 0,
218
+ breakpoints: (
219
+ xlg: (
220
+ font-size: carbon--type-scale(7),
221
+ line-height: 125%,
222
+ ),
223
+ max: (
224
+ font-size: carbon--type-scale(8),
225
+ ),
226
+ ),
227
+ ) !default;
228
+
229
+ /// @type Map
230
+ /// @access public
231
+ /// @group @carbon/type
232
+ $expressive-heading-05: (
233
+ font-size: carbon--type-scale(8),
234
+ font-weight: carbon--font-weight('regular'),
235
+ line-height: 125%,
236
+ letter-spacing: 0,
237
+ breakpoints: (
238
+ md: (
239
+ font-size: carbon--type-scale(9),
240
+ line-height: 122%,
241
+ ),
242
+ lg: (
243
+ font-size: carbon--type-scale(10),
244
+ line-height: 119%,
245
+ ),
246
+ xlg: (
247
+ font-size: carbon--type-scale(11),
248
+ line-height: 117%,
249
+ ),
250
+ max: (
251
+ font-size: carbon--type-scale(13),
252
+ ),
253
+ ),
254
+ ) !default;
255
+
256
+ /// @type Map
257
+ /// @access public
258
+ /// @group @carbon/type
259
+ $expressive-heading-06: (
260
+ font-size: carbon--type-scale(8),
261
+ font-weight: carbon--font-weight('semibold'),
262
+ line-height: 125%,
263
+ letter-spacing: 0,
264
+ breakpoints: (
265
+ md: (
266
+ font-size: carbon--type-scale(9),
267
+ line-height: 122%,
268
+ ),
269
+ lg: (
270
+ font-size: carbon--type-scale(10),
271
+ line-height: 119%,
272
+ ),
273
+ xlg: (
274
+ font-size: carbon--type-scale(11),
275
+ line-height: 117%,
276
+ ),
277
+ max: (
278
+ font-size: carbon--type-scale(13),
279
+ ),
280
+ ),
281
+ ) !default;
282
+
283
+ /// @type Map
284
+ /// @access public
285
+ /// @group @carbon/type
286
+ $expressive-paragraph-01: (
287
+ font-size: carbon--type-scale(6),
288
+ font-weight: carbon--font-weight('light'),
289
+ line-height: 125%,
290
+ letter-spacing: 0,
291
+ breakpoints: (
292
+ lg: (
293
+ font-size: carbon--type-scale(7),
294
+ line-height: 129%,
295
+ ),
296
+ max: (
297
+ font-size: carbon--type-scale(8),
298
+ line-height: 125%,
299
+ ),
300
+ ),
301
+ );
302
+
303
+ /// @type Map
304
+ /// @access public
305
+ /// @group @carbon/type
306
+ $quotation-01: (
307
+ font-size: carbon--type-scale(5),
308
+ font-weight: carbon--font-weight('regular'),
309
+ line-height: 130%,
310
+ letter-spacing: 0,
311
+ breakpoints: (
312
+ md: (
313
+ font-size: carbon--type-scale(5),
314
+ ),
315
+ lg: (
316
+ font-size: carbon--type-scale(6),
317
+ line-height: 125%,
318
+ ),
319
+ xlg: (
320
+ font-size: carbon--type-scale(7),
321
+ line-height: 129%,
322
+ ),
323
+ max: (
324
+ font-size: carbon--type-scale(8),
325
+ line-height: 125%,
326
+ ),
327
+ ),
328
+ ) !default;
329
+
330
+ /// @type Map
331
+ /// @access public
332
+ /// @group @carbon/type
333
+ $quotation-02: (
334
+ font-size: carbon--type-scale(8),
335
+ font-weight: carbon--font-weight('light'),
336
+ line-height: 125%,
337
+ letter-spacing: 0,
338
+ breakpoints: (
339
+ md: (
340
+ font-size: carbon--type-scale(9),
341
+ line-height: 122%,
342
+ ),
343
+ lg: (
344
+ font-size: carbon--type-scale(10),
345
+ line-height: 119%,
346
+ ),
347
+ xlg: (
348
+ font-size: carbon--type-scale(11),
349
+ line-height: 117%,
350
+ ),
351
+ max: (
352
+ font-size: carbon--type-scale(13),
353
+ ),
354
+ ),
355
+ ) !default;
356
+
357
+ /// @type Map
358
+ /// @access public
359
+ /// @group @carbon/type
360
+ $display-01: (
361
+ font-size: carbon--type-scale(10),
362
+ font-weight: carbon--font-weight('light'),
363
+ line-height: 119%,
364
+ letter-spacing: 0,
365
+ breakpoints: (
366
+ md: (
367
+ font-size: carbon--type-scale(10),
368
+ ),
369
+ lg: (
370
+ font-size: carbon--type-scale(12),
371
+ ),
372
+ xlg: (
373
+ font-size: carbon--type-scale(13),
374
+ line-height: 117%,
375
+ ),
376
+ max: (
377
+ font-size: carbon--type-scale(15),
378
+ line-height: 113%,
379
+ ),
380
+ ),
381
+ ) !default;
382
+
383
+ /// @type Map
384
+ /// @access public
385
+ /// @group @carbon/type
386
+ $display-02: (
387
+ font-size: carbon--type-scale(10),
388
+ font-weight: carbon--font-weight('semibold'),
389
+ line-height: 119%,
390
+ letter-spacing: 0,
391
+ breakpoints: (
392
+ md: (
393
+ font-size: carbon--type-scale(10),
394
+ ),
395
+ lg: (
396
+ font-size: carbon--type-scale(12),
397
+ ),
398
+ xlg: (
399
+ font-size: carbon--type-scale(13),
400
+ line-height: 116%,
401
+ ),
402
+ max: (
403
+ font-size: carbon--type-scale(15),
404
+ line-height: 113%,
405
+ ),
406
+ ),
407
+ ) !default;
408
+
409
+ /// @type Map
410
+ /// @access public
411
+ /// @group @carbon/type
412
+ $display-03: (
413
+ font-size: carbon--type-scale(10),
414
+ font-weight: carbon--font-weight('light'),
415
+ line-height: 119%,
416
+ letter-spacing: 0,
417
+ breakpoints: (
418
+ md: (
419
+ font-size: carbon--type-scale(14),
420
+ line-height: 115%,
421
+ ),
422
+ lg: (
423
+ font-size: carbon--type-scale(17),
424
+ line-height: 111%,
425
+ letter-spacing: -0.64px,
426
+ ),
427
+ xlg: (
428
+ font-size: carbon--type-scale(20),
429
+ line-height: 107%,
430
+ letter-spacing: -0.64px,
431
+ ),
432
+ max: (
433
+ font-size: carbon--type-scale(23),
434
+ line-height: 105%,
435
+ letter-spacing: -0.96px,
436
+ ),
437
+ ),
438
+ ) !default;
439
+
440
+ /// @type Map
441
+ /// @access public
442
+ /// @group @carbon/type
443
+ $display-04: (
444
+ font-size: carbon--type-scale(10),
445
+ font-weight: carbon--font-weight('semibold'),
446
+ line-height: 119%,
447
+ letter-spacing: 0,
448
+ breakpoints: (
449
+ md: (
450
+ font-size: carbon--type-scale(14),
451
+ line-height: 115%,
452
+ ),
453
+ lg: (
454
+ font-size: carbon--type-scale(17),
455
+ line-height: 111%,
456
+ letter-spacing: -0.64px,
457
+ ),
458
+ xlg: (
459
+ font-size: carbon--type-scale(20),
460
+ line-height: 107%,
461
+ letter-spacing: -0.64px,
462
+ ),
463
+ max: (
464
+ font-size: carbon--type-scale(23),
465
+ line-height: 105%,
466
+ letter-spacing: -0.96px,
467
+ ),
468
+ ),
469
+ ) !default;
470
+
471
+ /// @type Map
472
+ /// @access public
473
+ /// @group @carbon/type
474
+ $tokens: (
475
+ caption-01: $caption-01,
476
+ label-01: $label-01,
477
+ helper-text-01: $helper-text-01,
478
+ body-short-01: $body-short-01,
479
+ body-short-02: $body-short-02,
480
+ body-long-01: $body-long-01,
481
+ body-long-02: $body-long-02,
482
+ code-01: $code-01,
483
+ code-02: $code-02,
484
+ heading-01: $heading-01,
485
+ heading-02: $heading-02,
486
+ productive-heading-01: $productive-heading-01,
487
+ productive-heading-02: $productive-heading-02,
488
+ productive-heading-03: $productive-heading-03,
489
+ productive-heading-04: $productive-heading-04,
490
+ productive-heading-05: $productive-heading-05,
491
+ productive-heading-06: $productive-heading-06,
492
+ productive-heading-07: $productive-heading-07,
493
+ expressive-paragraph-01: $expressive-paragraph-01,
494
+ expressive-heading-01: $expressive-heading-01,
495
+ expressive-heading-02: $expressive-heading-02,
496
+ expressive-heading-03: $expressive-heading-03,
497
+ expressive-heading-04: $expressive-heading-04,
498
+ expressive-heading-05: $expressive-heading-05,
499
+ expressive-heading-06: $expressive-heading-06,
500
+ quotation-01: $quotation-01,
501
+ quotation-02: $quotation-02,
502
+ display-01: $display-01,
503
+ display-02: $display-02,
504
+ display-03: $display-03,
505
+ display-04: $display-04,
506
+ );
507
+
508
+ /// @param {Map} $map
509
+ /// @access public
510
+ /// @group @carbon/type
511
+ @mixin properties($map) {
512
+ @each $name, $value in $map {
513
+ #{$name}: $value;
514
+ }
515
+ }
516
+
517
+ /// @param {Number} $value - Number with units
518
+ /// @return {Number} Without units
519
+ /// @access public
520
+ /// @group @carbon/type
521
+ @function strip-unit($value) {
522
+ @return $value / ($value * 0 + 1);
523
+ }
524
+
525
+ /// This helper includes fluid type styles for the given token value. Fluid type
526
+ /// means that the `font-size` is computed using `calc()` in order to be
527
+ /// determined by the screen size instead of a breakpoint. As a result, fluid
528
+ /// styles should be used with caution in fixed width contexts.
529
+ ///
530
+ /// In addition, we make use of %-based line-heights so that the line-height of
531
+ /// each type style is computed correctly due to the dynamic nature of the
532
+ /// `font-size`.
533
+ ///
534
+ /// Most of the logic for this work comes from CSS Tricks:
535
+ /// https://css-tricks.com/snippets/css/fluid-typography/
536
+ ///
537
+ /// @param {Map} $type-styles - The value of a given type token
538
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - Custom breakpoints to use
539
+ /// @access public
540
+ /// @group @carbon/type
541
+ @mixin fluid-type($type-styles, $breakpoints: $carbon--grid-breakpoints) {
542
+ // Include the initial styles for the given token by default without any
543
+ // media query guard. This includes `font-size` as a fallback in the case
544
+ // that a browser does not support `calc()`
545
+ @include properties(map-remove($type-styles, breakpoints));
546
+ // We also need to include the `sm` styles by default since they don't
547
+ // appear in the fluid styles for tokens
548
+ @include fluid-type-size($type-styles, sm, $breakpoints);
549
+
550
+ // Finally, we need to go through all the breakpoints defined in the type
551
+ // token and apply the properties and fluid type size for that given
552
+ // breakpoint
553
+ @each $name, $values in map-get($type-styles, breakpoints) {
554
+ @include carbon--breakpoint($name) {
555
+ @include properties($values);
556
+ @include fluid-type-size($type-styles, $name, $breakpoints);
557
+ }
558
+ }
559
+ }
560
+
561
+ /// Computes the fluid `font-size` for a given type style and breakpoint
562
+ /// @param {Map} $type-styles - The styles for a given token
563
+ /// @param {String} $name - The name of the breakpoint to which we apply the fluid
564
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - The breakpoints for the grid system
565
+ /// @access public
566
+ /// @group @carbon/type
567
+ @mixin fluid-type-size(
568
+ $type-styles,
569
+ $name,
570
+ $breakpoints: $carbon--grid-breakpoints
571
+ ) {
572
+ // Get the information about the breakpoint we're currently working in. Useful
573
+ // for getting initial width information
574
+ $breakpoint: map-get($breakpoints, $name);
575
+
576
+ // Our fluid styles are captured under the 'breakpoints' property in our type
577
+ // styles map. These define what values to treat as `max-` variables below
578
+ $fluid-sizes: map-get($type-styles, breakpoints);
579
+ $fluid-breakpoint: ();
580
+ // Special case for `sm` because the styles for small are on the type style
581
+ // directly
582
+ @if $name == sm {
583
+ $fluid-breakpoint: map-remove($type-styles, breakpoints);
584
+ } @else {
585
+ $fluid-breakpoint: map-get($fluid-sizes, $name);
586
+ }
587
+
588
+ // Initialize our font-sizes to the default size for the type style
589
+ $max-font-size: map-get($type-styles, font-size);
590
+ $min-font-size: map-get($type-styles, font-size);
591
+ @if map-has-key($fluid-breakpoint, font-size) {
592
+ $min-font-size: map-get($fluid-breakpoint, font-size);
593
+ }
594
+
595
+ // Initialize our min and max width to the width of the current breakpoint
596
+ $max-vw: map-get($breakpoint, width);
597
+ $min-vw: map-get($breakpoint, width);
598
+
599
+ // We can use `breakpoint-next` to see if there is another breakpoint we can
600
+ // use to update `max-font-size` and `max-vw` with larger values
601
+ $next-breakpoint-available: carbon--breakpoint-next($name, $breakpoints);
602
+ $next-fluid-breakpoint-name: null;
603
+
604
+ // We need to figure out what the next available fluid breakpoint is for our
605
+ // given $type-styles. In this loop we try and iterate through breakpoints
606
+ // until we either manually set $next-breakpoint-available to null or
607
+ // `breakpoint-next` returns null.
608
+ @while $next-breakpoint-available {
609
+ @if map-has-key($fluid-sizes, $next-breakpoint-available) {
610
+ $next-fluid-breakpoint-name: $next-breakpoint-available;
611
+ $next-breakpoint-available: null;
612
+ } @else {
613
+ $next-breakpoint-available: carbon--breakpoint-next(
614
+ $next-breakpoint-available,
615
+ $breakpoints
616
+ );
617
+ }
618
+ }
619
+
620
+ // If we have found the next available fluid breakpoint name, then we know
621
+ // that we have values that we can use to set max-font-size and max-vw as both
622
+ // values derive from the next breakpoint
623
+ @if $next-fluid-breakpoint-name {
624
+ $next-fluid-breakpoint: map-get($breakpoints, $next-fluid-breakpoint-name);
625
+ $max-font-size: map-get(
626
+ map-get($fluid-sizes, $next-fluid-breakpoint-name),
627
+ font-size
628
+ );
629
+ $max-vw: map-get($next-fluid-breakpoint, width);
630
+
631
+ // prettier-ignore
632
+ font-size: calc(#{$min-font-size} +
633
+ #{strip-unit($max-font-size - $min-font-size)} *
634
+ ((100vw - #{$min-vw}) / #{strip-unit($max-vw - $min-vw)})
635
+ );
636
+ } @else {
637
+ // Otherwise, just default to setting the font size found from the type
638
+ // style or the given fluid breakpoint in the type style
639
+ font-size: $min-font-size;
640
+ }
641
+ }
642
+
643
+ /// Helper mixin to include the styles for a given token in any selector in your
644
+ /// project. Also includes an optional fluid option that will enable fluid
645
+ /// styles for the token if they are defined. Fluid styles will cause the
646
+ /// token's font-size to be computed based on the viewport size. As a result, use
647
+ /// with caution in fixed contexts.
648
+ /// @param {String} $name - The name of the token to get the styles for
649
+ /// @param {Boolean} $fluid [false] - Specify whether to include fluid styles for the
650
+ /// @param {Map} $breakpoints [$carbon--grid-breakpoints] - Provide a custom breakpoint map to use
651
+ /// @access public
652
+ /// @group @carbon/type
653
+ @mixin carbon--type-style(
654
+ $name,
655
+ $fluid: false,
656
+ $breakpoints: $carbon--grid-breakpoints
657
+ ) {
658
+ @if not map-has-key($tokens, $name) {
659
+ @error 'Unable to find a token with the name: `#{$name}`';
660
+ }
661
+
662
+ $token: map-get($tokens, $name);
663
+
664
+ // If $fluid is set to true and the token has breakpoints defined for fluid
665
+ // styles, delegate to the fluid-type helper for the given token
666
+ @if $fluid == true and map-has-key($token, 'breakpoints') {
667
+ @include fluid-type($token, $breakpoints);
668
+ } @else {
669
+ // Otherwise, we just include all the property declarations directly on the
670
+ // selector
671
+ @include properties(map-remove($token, 'breakpoints'));
672
+ }
673
+ }