-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path_mixins.scss
179 lines (155 loc) · 4.31 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
// @param {string} bp Breakpoint value. One of `xs, sm, md, lg`.
// @param {boolean} isMaxWidth By default, the media queries are mobile first,
// so they use `min-width: __px`. By passing `true`, the mixin will subtract
// one pixel from the breakpoint value and make it `max-width: __px`.
// @param {boolean} isScreenOnly Whether to hide this media query from print styles.
//
// Note: For print media, we want the default styles and the xs breakpoint to take effect.
@mixin breakpoint($bp, $isMaxWidth: false, $isScreenOnly: true) {
// Avoid media queries like (min-width: 0px) and (max-width: -1px).
@if $bp == xs {
@content;
} @else {
$query: get-breakpoint-query($bp, $isMaxWidth);
@media #{get-media-query($query, $isScreenOnly)} {
@content;
}
}
}
@mixin breakpoints($min, $max) {
$start: map-get($breakpoints, $min);
$end: map-get($breakpoints, $max);
@if map-has-key($breakpoints, $min) and map-has-key($breakpoints, $max) {
$end: $end - 1px;
@if $start > $end {
@warn "Unreachable media query: #{$start} <--> #{$end}";
@content;
} @else {
$media-query-min: "(min-width: #{$start})";
$media-query-max: "(max-width: #{$end})";
// There should be no lower bound when the extra small breakpoint is used.
// e.g. `@include breakpoints(xs, sm)` should be from 0 <--> 768.
@if $min == xs {
@media screen and #{$media-query-max} {
@content;
}
} @else {
@media screen and #{$media-query-min} and #{$media-query-max} {
@content;
}
}
}
} @else {
@warn "#{$min} or #{$max} breakpoint not recognized. Valid breakpoints: #{map-keys($breakpoints)}";
@content;
}
}
@mixin augment-hit-area($byPercent: 100%, $pseudo: 'after') {
$isPercent: str-slice(inspect($byPercent), -1) == "%";
$size: if($isPercent, 100% + $byPercent, $byPercent);
$offset: if($isPercent, $byPercent / -2, $byPercent / -4);
// Increase the hit area by 100% by placing a pseudo element behind the handle
&::#{$pseudo} {
content: '';
position: absolute;
// Having the hit area on top of the handle seemed to help Android a little. Was below it (-1)
z-index: 1;
top: $offset;
left: $offset;
display: block;
width: $size;
height: $size;
// Uncomment to see the hit area
// background-color: rgba(255, 255, 0, 0.3);
}
}
@mixin keep-aspect() {
position: relative;
width: 100%;
height: 0;
overflow: hidden;
padding-bottom: 100%;
}
@mixin aspect($width, $height) {
padding-bottom: percentage($height / $width);
}
@mixin no-aspect() {
height: auto;
padding-bottom: 0;
overflow: visible;
}
// Fill the parent using absolute positioning
@mixin fill-parent() {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
// For when you need fill-parent on one breakpoint, but not a bigger one.
@mixin reset-fill-parent() {
position: static;
top: auto;
right: auto;
bottom: auto;
left: auto;
}
// Clearfix
// --------
// For clearing floats like a boss h5bp.com/q
@mixin clearfix() {
&::after {
content: "";
display: table;
clear: both;
}
}
// Text overflow
// -------------------------
// Requires inline-block or block for proper styling
@mixin text-overflow($nowrap: true) {
overflow: hidden;
text-overflow: ellipsis;
@if ($nowrap) {
white-space: nowrap;
}
}
@mixin font-smooth($smooth: true) {
@if $smooth {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
@else {
-webkit-font-smoothing: subpixel-antialiased;
-moz-osx-font-smoothing: auto;
}
}
// Promoting layers can alleviate many animation issues, but also be
// aware that having too many layers will cause performance issues.
// http://jankfree.org/
//
// Prefer `will-change`
// https://developer.mozilla.org/en-US/docs/Web/CSS/will-change
// http://aerotwist.com/blog/bye-bye-layer-hacks/
@mixin layer-promote() {
transform: translateZ(0);
}
@mixin background-cover() {
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
@mixin size($width, $height: $width) {
width: $width;
height: $height;
}
@mixin table-center-wrap() {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
@mixin table-center() {
display: table-cell;
vertical-align: middle;
}