-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom-inputs.scss
182 lines (180 loc) · 5.9 KB
/
custom-inputs.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
$color-default: #849FBB; // default color
$color-default-light: #DDDDDD; // default color light
$color-active: #57CB85; // color when active or checked
$color-active-light: #9EFFC4; // active color light
$color-focus: #6FB5FB; // color when focused
$margin-el: 7px; // default margin for our custom inputs
/**
* Checkboxes & radios
*/
.fh-checkbox > [type="checkbox"],
.fh-radio > [type="radio"] {
&:checked,
&:not(:checked) {
width: 0;
height: 0;
display: none;
opacity: 0;
& + label {
display: inline-block;
margin-right: $margin-el;
margin-top: $margin-el;
margin-bottom: $margin-el;
padding-left: 22px;
padding-top: 2px;
position: relative;
cursor: pointer;
&:before {
// position elements absolute to parent container
position: absolute;
display: inline-block;
bottom: 1px;
left: 0;
width: 13px;
height: 13px;
border: 2px solid $color-default;
color: $color-default;
}
&:hover:before {
// add some hover styling
background-color: $color-default;
}
}
&:focus + label:before {
border-color: $color-focus;
box-shadow: 0 0 6px 0 $color-focus;
}
&[disabled] + label {
cursor: not-allowed;
opacity: .4;
&:before {
opacity: .7;
}
}
}
}
// styling for checkbox for both states
.fh-checkbox > [type="checkbox"]:checked + label:before,
.fh-checkbox > [type="checkbox"]:not(:checked) + label:before {
// set icon font
font-family: "FontAwesome";
font-size: 13px;
text-align: center;
// add some CSS3-animations
-webkit-transition: border-color .2s ease-in, background-color .2s ease-in;
-moz-transition: border-color .2s ease-in, background-color .2s ease-in;
-o-transition: border-color .2s ease-in, background-color .2s ease-in;
-ms-transition: border-color .2s ease-in, background-color .2s ease-in;
transition: border-color .2s ease-in, background-color .2s ease-in;
}
// styling for checkbox when selected
.fh-checkbox > [type="checkbox"]:checked + label:before {
// set checkmark icon
content: "\f00c";
color: #FFF;
background-color: $color-active;
border-color: $color-active;
}
// styling for checkbox when not selected
.fh-checkbox > [type="checkbox"]:not(:checked) + label:before {
// remove checkmark icon
content: "";
}
// styling for radio for both states
.fh-radio > [type="radio"]:checked + label:before,
.fh-radio > [type="radio"]:not(:checked) + label:before, {
content: "";
border-radius: 15px;
// add some CSS3-animations
-webkit-transition: border-color .2s ease-in, box-shadow .1s ease-in, background-color .2s ease-in, box-shadow .2s ease-in;
-moz-transition: border-color .2s ease-in, box-shadow .1s ease-in, background-color .2s ease-in;
-o-transition: border-color .2s ease-in, box-shadow .1s ease-in, background-color .2s ease-in;
-ms-transition: border-color .2s ease-in, box-shadow .1s ease-in, background-color .2s ease-in;
transition: border-color .2s ease-in, box-shadow .1s ease-in, background-color .2s ease-in;
}
// styling for radio when selected
.fh-radio > [type="radio"]:checked + label:before {
color: $color-active;
border-color: $color-active;
background-color: $color-active;
// use box-shadow to render circle
box-shadow: inset 0 0 0 1px #fff;
}
// styling for radio when not selected
.fh-radio > [type="radio"]:not(:checked) + label:before {
box-shadow: inset 0 0 0 3px #fff;
}
/**
* On/off switch
*/
.fh-switch {
position: relative;
}
.fh-switch > [type="checkbox"]:checked,
.fh-switch > [type="checkbox"]:not(:checked) {
width: 0;
height: 0;
display: none;
opacity: 0;
& + label {
cursor: pointer;
display: inline-block;
margin-right: $margin-el;
margin-top: $margin-el;
margin-bottom: $margin-el;
// apply padding so the switch fits inside the label
padding-right: 60px;
&:after {
content: "";
top: 4px;
right: 10px;
width: 30px;
height: 12px;
// use absolute for better positioning
position: absolute;
border-radius: 30px;
}
& + .fh-switch-knob {
top: 0;
width: 20px;
height: 20px;
border-radius: 30px;
display: inline-block;
position: absolute;
cursor: pointer;
pointer-events: none;
box-shadow: 1px 1px 1px $color-default-light;
// add some CSS3-animations
-webkit-transition: right .1s ease-in, background-color .1s ease-in;
-moz-transition: right .1s ease-in, background-color .1s ease-in;
-o-transition: right .1s ease-in, background-color .1s ease-in;
-ms-transition: right .1s ease-in, background-color .1s ease-in;
}
}
&:focus + label:after,
&:focus + label + .fh-switch-knob {
box-shadow: 0 0 6px 0 $color-focus;
}
&[disabled] {
& + label,
& + label:after,
& + label + .fh-switch-knob {
cursor: not-allowed;
opacity: 0.4;
}
}
}
.fh-switch > [type="checkbox"]:checked + label:after {
background-color: $color-active-light;
}
.fh-switch > [type="checkbox"]:not(:checked) + label:after {
background-color: $color-default-light;
}
.fh-switch > [type="checkbox"]:checked + label + .fh-switch-knob {
right:5px;
background-color: $color-active;
}
.fh-switch > [type="checkbox"]:not(:checked) + label + .fh-switch-knob {
right: 25px;
background-color: $color-default;
}