-
Notifications
You must be signed in to change notification settings - Fork 414
/
_mixins.scss
328 lines (257 loc) · 6.89 KB
/
_mixins.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
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
/*------------------------------------*\
$MIXINS
\*------------------------------------*/
/**
* Create a fully formed type style (sizing and vertical rhythm) by passing in a
* single value, e.g.:
*
`@include font-size(10px);`
*
* Thanks to @redclov3r for the `line-height` Sass:
* twitter.com/redclov3r/status/250301539321798657
*/
@mixin font-size($font-size, $line-height:true){
font-size:$font-size;
font-size:($font-size / $base-font-size)*1rem;
@if $line-height == true{
line-height:ceil($font-size / $base-line-height) * ($base-line-height / $font-size);
}
}
/**
* Style any number of headings in one fell swoop, e.g.:
*
.foo{
@include headings(1, 3){
color:#BADA55;
}
}
*
* With thanks to @lar_zzz, @paranoida, @rowanmanning and ultimately
* @thierrylemoulec for refining and improving my initial mixin.
*/
@mixin headings($from: 1, $to: 6){
%base-heading {
@content
}
@if $from >= 1 and $to <= 6{
@for $i from $from through $to{
h#{$i}{
@extend %base-heading;
}
}
}
}
/**
* Create vendor-prefixed CSS in one go, e.g.
*
`@include vendor(border-radius, 4px);`
*
*/
@mixin vendor($property, $value...){
-webkit-#{$property}:$value;
-moz-#{$property}:$value;
-ms-#{$property}:$value;
-o-#{$property}:$value;
#{$property}:$value;
}
/**
* Create CSS keyframe animations for all vendors in one go, e.g.:
*
.foo{
@include vendor(animation, shrink 3s);
}
@include keyframe(shrink){
from{
font-size:5em;
}
}
*
* Courtesy of @integralist: twitter.com/integralist/status/260484115315437569
*/
@mixin keyframe ($animation-name){
@-webkit-keyframes $animation-name{
@content;
}
@-moz-keyframes $animation-name{
@content;
}
@-ms-keyframes $animation-name{
@content;
}
@-o-keyframes $animation-name{
@content;
}
@keyframes $animation-name{
@content;
}
}
/**
* Force overly long spans of text to truncate, e.g.:
*
`@include truncate(100%);`
*
* Where `$truncation-boundary` is a united measurement.
*/
@mixin truncate($truncation-boundary){
max-width:$truncation-boundary;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
}
/**
* CSS arrows!!! But... before you read on, you might want to grab a coffee...
*
* This mixin creates a CSS arrow on a given element. We can have the arrow
* appear in one of 12 locations, thus:
*
* 01 02 03
* +------------------+
* 12 | | 04
* | |
* 11 | | 05
* | |
* 10 | | 06
* +------------------+
* 09 08 07
*
* You pass this position in along with a desired arrow color and optional
* border color, for example:
*
* `@include arrow(top, left, red)`
*
* for just a single, red arrow, or:
*
* `@include arrow(bottom, center, red, black)`
*
* which will create a red triangle with a black border which sits at the bottom
* center of the element. Call the mixin thus:
*
.foo{
background-color:#BADA55;
border:1px solid #ACE;
@include arrow(top, left, #BADA55, #ACE);
}
*
*/
@mixin arrow($arrow-edge, $arrow-location, $arrow-color, $border-color: $arrow-color){
@if $arrow-edge == top{
@extend %arrow--top;
&:before{
border-bottom-color:$border-color!important;
}
&:after{
border-bottom-color:$arrow-color!important;
}
@if $arrow-location == left{
@extend %arrow--left;
}
@if $arrow-location == center{
@extend %arrow--center;
}
@if $arrow-location == right{
@extend %arrow--right;
}
}
@if $arrow-edge == right{
@extend %arrow--far;
&:before{
border-left-color:$border-color!important;
}
&:after{
border-left-color:$arrow-color!important;
}
@if $arrow-location == top{
@extend %arrow--upper;
}
@if $arrow-location == center{
@extend %arrow--middle;
}
@if $arrow-location == bottom{
@extend %arrow--lower;
}
}
@if $arrow-edge == bottom{
@extend %arrow--bottom;
&:before{
border-top-color:$border-color!important;
}
&:after{
border-top-color:$arrow-color!important;
}
@if $arrow-location == left{
@extend %arrow--left;
}
@if $arrow-location == center{
@extend %arrow--center;
}
@if $arrow-location == right{
@extend %arrow--right;
}
}
@if $arrow-edge == left{
@extend %arrow--near;
&:before{
border-right-color:$border-color!important;
}
&:after{
border-right-color:$arrow-color!important;
}
@if $arrow-location == top{
@extend %arrow--upper;
}
@if $arrow-location == center{
@extend %arrow--middle;
}
@if $arrow-location == bottom{
@extend %arrow--lower;
}
}
}
/**
* Media query mixin.
*
* It’s not great practice to define solid breakpoints up-front, preferring to
* modify your design when it needs it, rather than assuming you’ll want a
* change at ‘mobile’. However, as inuit.css is required to take a hands off
* approach to design decisions, this is the closest we can get to baked-in
* responsiveness. It’s flexible enough to allow you to set your own breakpoints
* but solid enough to be frameworkified.
*
* We define some broad breakpoints in our vars file that are picked up here
* for use in a simple media query mixin. Our options are:
*
* palm
* lap
* lap-and-up
* portable
* desk
* desk-wide
*
* Not using a media query will, naturally, serve styles to all devices.
*
* `@include media-query(palm){ [styles here] }`
*
* We work out your end points for you:
*/
$palm-end: $lap-start - 1px;
$lap-end: $desk-start - 1px;
@mixin media-query($media-query){
@if $media-query == palm{
@media only screen and (max-width:$palm-end) { @content; }
}
@if $media-query == lap{
@media only screen and (min-width:$lap-start) and (max-width:$lap-end) { @content; }
}
@if $media-query == lap-and-up{
@media only screen and (min-width:$lap-start) { @content; }
}
@if $media-query == portable{
@media only screen and (max-width:$lap-end) { @content; }
}
@if $media-query == desk{
@media only screen and (min-width:$desk-start) { @content; }
}
@if $media-query == desk-wide{
@media only screen and (min-width: $desk-wide-start) { @content; }
}
}