-
Notifications
You must be signed in to change notification settings - Fork 11
/
_switch.scss
232 lines (190 loc) · 5.37 KB
/
_switch.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
// Foundation for Sites by ZURB
// foundation.zurb.com
// Licensed under MIT Open Source
////
/// @group switch
////
/// Background color of a switch.
/// @type Color
$switch-background: $medium-gray !default;
/// Background active color of a switch.
/// @type Color
$switch-background-active: $primary-color !default;
/// Height of a switch, with no class applied.
/// @type Number
$switch-height: 2rem !default;
/// Height of a switch with .tiny class.
/// @type Number
$switch-height-tiny: 1.5rem !default;
/// Height of a switch with .small class.
/// @type Number
$switch-height-small: 1.75rem !default;
/// Height of a switch with .large class.
/// @type Number
$switch-height-large: 2.5rem !default;
/// Border radius of the switch
/// @type Number
$switch-radius: $global-radius !default;
/// border around a modal.
/// @type Number
$switch-margin: $global-margin !default;
/// Background color for the switch container and paddle.
/// @type Color
$switch-paddle-background: $white !default;
/// Spacing between a switch paddle and the edge of the body.
/// @type Number
$switch-paddle-offset: 0.25rem !default;
/// border radius of the switch paddle
/// @type Number
$switch-paddle-radius: $global-radius !default;
/// switch transition.
/// @type Number
$switch-paddle-transition: all 0.25s ease-out !default;
// make them variables
// ask about accessibility on label
// change class name for text
/// Adds styles for a switch container. Apply this to a container class.
@mixin switch-container {
margin-bottom: $switch-margin;
outline: 0;
position: relative;
user-select: none;
// These properties cascade down to the switch text
color: $white;
font-weight: bold;
font-size: rem-calc(14);
}
/// Adds styles for a switch input. Apply this to an `<input>` within a switch.
@mixin switch-input {
opacity: 0;
position: absolute;
}
/// Adds styles for the background and paddle of a switch. Apply this to a `<label>` within a switch.
@mixin switch-paddle {
background: $switch-background;
cursor: pointer;
display: block;
position: relative;
width: 4rem;
height: $switch-height;
transition: $switch-paddle-transition;
border-radius: $switch-radius;
// Resetting these <label> presets so type styles cascade down
color: inherit;
font-weight: inherit;
// Needed to override specificity
input + & {
margin: 0;
}
// The paddle itself
&::after {
background: $switch-paddle-background;
content: '';
display: block;
position: absolute;
height: 1.5rem;
#{$global-left}: 0.25rem;
top: 0.25rem;
width: 1.5rem;
transition: $switch-paddle-transition;
transform: translate3d(0, 0, 0);
border-radius: $switch-paddle-radius;
}
// Change the visual style when the switch is active
input:checked ~ & {
background: $switch-background-active;
&::after {
#{$global-left}: 2.25rem;
}
}
input:focus ~ & {
@include disable-mouse-outline;
}
}
/// Adds base styles for active/inactive text inside a switch. Apply this to text elements inside the switch `<label>`.
@mixin switch-text {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
/// Adds styles for the active state text within a switch.
@mixin switch-text-active {
#{$global-left}: 8%;
display: none;
input:checked + label > & {
display: block;
}
}
/// Adds styles for the inactive state text within a switch.
@mixin switch-text-inactive {
#{$global-right}: 15%;
input:checked + label > & {
display: none;
}
}
/// Changes the size of a switch by modifying the size of the body and paddle. Apply this to a switch container.
/// @param {Number} $font-size [1rem] - Font size of label text within the switch.
/// @param {Number} $width [4rem] - Width of the switch body.
/// @param {Number} $height [2rem] - Height of the switch body.
/// @param {Number} $paddle-width [1.5rem] - Width of the switch paddle.
/// @param {Number} $paddle-offset [0.25rem] - Spacing between the switch paddle and the edge of the switch body.
@mixin switch-size(
$font-size: 1rem,
$width: 4rem,
$height: 2rem,
$paddle-width: 1.5rem,
$paddle-offset: 0.25rem
) {
$paddle-height: $height - ($paddle-offset * 2);
$paddle-left-active: $width - $paddle-width - $paddle-offset;
.switch-paddle {
width: $width;
height: $height;
font-size: $font-size;
}
.switch-paddle::after {
width: $paddle-width;
height: $paddle-height;
}
input:checked ~ .switch-paddle:after {
#{$global-left}: $paddle-left-active;
}
}
@mixin foundation-switch {
// Container class
.switch {
@include switch-container;
}
// <input> element
.switch-input {
@include switch-input;
}
// <label> element
.switch-paddle {
@include switch-paddle;
}
// Base label text styles
%switch-text {
@include switch-text;
}
// Active label text styles
.switch-active {
@extend %switch-text;
@include switch-text-active;
}
// Inactive label text styles
.switch-inactive {
@extend %switch-text;
@include switch-text-inactive;
}
// Switch sizes
.switch.tiny {
@include switch-size(rem-calc(10), 3rem, $switch-height-tiny, 1rem, $switch-paddle-offset);
}
.switch.small {
@include switch-size(rem-calc(12), 3.5rem, $switch-height-small, 1.25rem, $switch-paddle-offset);
}
.switch.large {
@include switch-size(rem-calc(16), 5rem, $switch-height-large, 2rem, $switch-paddle-offset);
}
}