-
Notifications
You must be signed in to change notification settings - Fork 0
/
_forms-custom-radioscheckboxes.scss
146 lines (127 loc) · 3.2 KB
/
_forms-custom-radioscheckboxes.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
/**
* Custom Checkboxes and radios
*
* IE9+
*
* --------------------------------
*
* Checkbox button example HTML
*
* <label class="control control--custom" for="checkbox1">
* <input class="control--custom-input" type="checkbox" id="checkbox1" name="myCheckbox" value="A value"/>
* <span class="control-indicator control-indicator--checkbox"></span>
* My Checkbox Label Text
* </label>
*
* -------------------------------
*
* Radio button example HTML
*
* <label class="control control--custom" for="radio1">
* <input class="control--custom-input" type="radio" id="radio1" name="myRadioBtn" value="A value"/>
* <span class="control-indicator control-indicator--radio"></span>
* My Radio Button Label Text
* </label>
*
* ================================= */
// $custom-input-color: $color-primary;
$custom-input-color: $color-primary;
$custom-input-selected-color: $color-bg;
$checkbox-indicator-width: .1em;
.control--custom {
position: relative;
display: block;
cursor: pointer;
user-select: none;
}
// Give inline elements some space to the right
.control--custom--inline {
display: inline-block;
padding-right: 2em;
}
// The hidden input
.control--custom-input {
position: absolute;
opacity: 0;
z-index: -1; // Put the input behind the label so it doesn't overlay text
}
// The new checkbox/radio
.control-indicator {
position: relative;
display: inline-block;
width: 1em;
height: 1em;
transition: $default-transition;
border: $checkbox-indicator-width solid $custom-input-color;
background-color: $custom-input-color;
vertical-align: middle;
margin-top: -.2em;
box-shadow: 0 0 0 2px transparent, 0 0 0 0 transparent; // Used to animate from when element is in :focus
}
// :focus styles
.control--custom-input:focus ~ .control-indicator {
box-shadow: 0 0 0 2px $color-bg, 0 0 0 3px $input-borderColor--focus;
}
// Checkbox modifiers
.control-indicator--checkbox,
.control-indicator--tickbox {
border-radius: .2em;
&:before,
&:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 90%;
display: block;
opacity: 0; // indicator will be faded out when deselected
transition: all 250ms ease-in-out;
}
}
.control-indicator--checkbox {
&:before,
&:after {
top: 50%;
width: 90%;
height: $checkbox-indicator-width;
background-color: $custom-input-selected-color;
}
&:before {
transform: translate(-50%, -50%) rotate(45deg);
}
&:after {
transform: translate(-50%, -50%) rotate(-45deg);
}
}
.control-indicator--tickbox {
&:before {
top: 0;
transform: translateX(-50%) rotate(45deg);
border: $checkbox-indicator-width solid $custom-input-selected-color;
background-color: transparent;
width: 40%;
height: 80%;
border-top: 0;
border-left: 0;
}
&:after {
display: none;
}
}
.control--custom-input:checked ~ .control-indicator--checkbox,
.control--custom-input:checked ~ .control-indicator--tickbox {
// Uncomment to make checkboxes circular when checked
// border-radius: 50%;
&:before,
&:after {
opacity: 1;
}
}
// Radio modifiers
.control-indicator--radio {
border-radius: 50%;
}
.control--custom-input:checked ~ .control-indicator--radio {
background-color: $custom-input-selected-color;
border: .3em solid $custom-input-color;
}