This repository has been archived by the owner on Oct 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path_font-size.scss
147 lines (131 loc) · 3.07 KB
/
_font-size.scss
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
/* ============================================================================
@CORE -> MIXINS -> FONT SIZE
========================================================================= */
/**
* Create a fully formed type style (sizing and vertical rhythm) by passing in
* a single value, e.g.
*
.foo {
@include font-size(12);
}
*
* This will generate a `rem`-based font-size, as well as a unitless
* line-height which will place the element on your baseline, e.g.
*
.foo {
font-size: 0.75rem;
line-height: 2;
}
*
* If you do not want Scally to generate a line-height for you then simply pass
* in your own as a second parameter e.g.
*
.foo {
@include font-size(12, 1.5);
}
*
* This will yield:
*
.foo {
font-size: 0.75rem;
line-height: 1.5;
}
*
* This parameter can be any integer including an integer with `px` appended,
* `inherit`, or `normal` e.g.
*
.foo {
@include font-size(12, 18px);
}
.foo {
@include font-size(12, inherit);
}
.foo {
@include font-size(12, normal);
}
*
* Any line-heights with `px` appended will still output as a unitless
* line-height e.g.
*
.foo {
@include font-size(12, 18px);
}
*
* This will yield:
*
.foo {
font-size: 0.75rem;
line-height: 1.5;
}
*
* If you don't want a line-height at all, pass in a second parameter of
* `none` or `false`:
*
.foo {
@include font-size(12, none);
}
*
* This will yield:
*
.foo {
font-size: 0.75rem;
}
*
* @example
.foo {
@include font-size(18);
}
.foo {
@include font-size(12, 1.5);
}
.foo {
@include font-size(12, 18px);
}
.foo {
@include font-size(12, none);
}
.foo {
@include font-size(24, inherit);
}
.foo {
@include font-size(24, normal);
}
.foo {
@include font-size(24, false, true);
}
or
.foo {
@include font-size(24, 1.2, !important);
}
.foo {
@include font-size(24, auto, !important);
}
*
* @credit
* https://github.com/inuitcss/tools.mixins/blob/master/_tools.mixins.scss
*/
@mixin font-size($font-size-value, $line-height-value: auto, $sledgehammer: false) {
$important: if($sledgehammer, " !important", "");
$font-size-value: strip-unit($font-size-value);
font-size: (($font-size-value / strip-unit($font-size)) * 1rem)#{$important};
@if $line-height-value == auto {
line-height: ceil($font-size-value / $line-height) * ($line-height /
$font-size-value)#{$important};
}
@else {
@if (type-of($line-height-value) == number) {
@if unitless($line-height-value) {
line-height: $line-height-value#{$important};
}
@else {
line-height: strip-unit($line-height-value) / $font-size-value#{$important};
}
}
@elseif $line-height-value == inherit or $line-height-value == normal {
line-height: $line-height-value#{$important};
}
@elseif ($line-height-value != none and $line-height-value != false) {
@warn "D'oh! `#{$line-height-value}` is not a valid value for `line-height`."
}
}
}