-
Notifications
You must be signed in to change notification settings - Fork 1
/
_uiswitch.scss
170 lines (142 loc) · 3.79 KB
/
_uiswitch.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
// UISwitch2
// A customizable UISwitch in pure CSS3.
//
// @author Christian Petersen <[email protected]>
// Bourbon Mixins
@import 'mixins';
$uiswitch-thumb-off-tint: #ABB2BF !default;
$uiswitch-thumb-on-tint: #ffffff !default;
$uiswitch-on-tint: #4A90E2 !default;
$uiswitch-off-tint: #EDF1F5 !default;
$uiswitch-size: 50px !default;
$uiswitch-thumb-size: $uiswitch-size / 3 !default;
$uiswitch-active-thumb-size: $uiswitch-size / 2.25 !default;
$uiswitch-thumb-offset: ($uiswitch-thumb-size / 4) !default;
$uiswitch-on-thumb-offset: $uiswitch-thumb-offset + $uiswitch-thumb-size !default;
%uiswitch {
@include box-sizing(border-box);
@include appearance(none);
@include user-select(none);
@include size($uiswitch-size $uiswitch-size / 2);
position: relative;
border-radius: $uiswitch-size / 2;
cursor: pointer;
outline: 0;
z-index: 0;
margin: 0;
padding: 0;
border: none;
background-color: $uiswitch-off-tint;
@include transition-duration(250ms);
@include transition-timing-function(ease-in-out);
-webkit-touch-callout: none;
-webkit-text-size-adjust: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
// Thumb
&::after {
@include box-sizing(border-box);
@include size($uiswitch-thumb-size);
content: ' ';
position: absolute;
border-radius: $uiswitch-active-thumb-size / 2;
background: $uiswitch-thumb-off-tint;
z-index: 2;
top: $uiswitch-thumb-offset;
left: $uiswitch-thumb-offset;
@include transition(transform 300ms, width 280ms, background-color 600ms);
@include transform(translate3d(0, 0, 0));
@include transition-timing-function(cubic-bezier(0.42, 0.800, 0.58, 1.2));
}
&:active {
background-color: $uiswitch-off-tint;
}
// Background tint for ON state
&:checked {
background-color: $uiswitch-on-tint;
}
// Thumb for ON state
&:checked::after {
@include transform(translate3d($uiswitch-on-thumb-offset, 0, 0));
right: $uiswitch-size / 2;
left: inherit;
}
&:focus {
box-shadow: 0 0 4px 2px transparentize($uiswitch-on-tint, 0.4);
}
// Thumb for active state
&:active::after {
width: $uiswitch-active-thumb-size;
}
&:checked::before,
&:active::before {
@include transform(scale(0));
}
// Disabled
&:disabled {
opacity: 0.5;
cursor: default;
@include transition(none);
&:active::before,
&:active::after,
&:checked:active::before,
&:checked::before {
width: $uiswitch-thumb-size;
@include transition(none);
}
}
}
@mixin uiswitch(
$size: $uiswitch-size,
$thumb-size: $size / 3,
$active-thumb-size: $size / 2.25,
$thumb-offset: ($thumb-size / 4),
$on-thumb-offset: $thumb-offset + $thumb-size,
$on-tint: $uiswitch-on-tint,
$off-tint: $uiswitch-off-tint,
$thumb-off-tint: $uiswitch-thumb-off-tint,
$thumb-on-tint: $uiswitch-thumb-on-tint) {
@extend %uiswitch;
@include size($size $size / 2);
border-radius: $size / 2;
@deprecated $size;
background-color: $off-tint;
$on-tint-start: $on-tint;
$on-tint-end: desaturate($on-tint-start, 1);
&::before {
background-color: $off-tint;
}
&::after {
@include size($thumb-size);
border-radius: $active-thumb-size / 2;
top: $thumb-offset;
left: $thumb-offset;
background: $thumb-off-tint;
}
&:active {
background-color: $off-tint;
}
&:active::after {
width: $active-thumb-size;
}
&:checked {
background-color: $on-tint;
}
&:checked::after {
@include transform(translate3d($on-thumb-offset, 0, 0));
right: $size / 2;
background: $thumb-on-tint;
}
// Disabled
&:disabled {
&:active::before,
&:active::after,
&:checked:active::before,
&:checked::before {
width: $thumb-size;
}
}
}
// Make .uiswitch class available out of the box
.uiswitch {
@include uiswitch();
}