-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustom-checkbox-radio.scss
92 lines (92 loc) · 2.63 KB
/
custom-checkbox-radio.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
// Overrideable variables
$ccr-size: 1em !default;
$ccr-color-outer: black !default;
$ccr-color-outer-checked: $ccr-color-outer !default;
$ccr-color-inner: black !default;
$ccr-background: #fff !default;
$ccr-background-checked: $ccr-background !default;
$ccr-border-width: 1px !default;
$ccr-border-width-focus: $ccr-border-width + 1px !default;
$ccr-border-radius-checkbox: 2px !default;
$ccr-icon-scale-checkbox: 70% !default;
$ccr-icon-scale-radio: 45% !default;
@import "./lib";
.checkbox,
.radio {
*,
::before,
::after {
box-sizing: border-box;
}
input {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
~ label {
display: flex;
line-height: 1.1;
cursor: pointer;
user-select: none;
&::before {
content: "";
width: $ccr-size;
height: $ccr-size;
// outline: 1px solid; // **** Debugging ****
background-color: $ccr-background;
// box-shadow doesn't mess with the position of the background-image, unlike border
box-shadow: 0 0 0 $ccr-border-width $ccr-color-outer;
background-position: center;
background-repeat: no-repeat;
flex-shrink: 0;
margin-right: 0.5em;
transform: translateY(-15%);
}
// Nested inline elements won't render their whitespace,
// what with it being flexed as a henchman so work around it:
a {
margin-right: 0.3em;
margin-left: 0.3em;
}
}
&:focus ~ label::before {
box-shadow: 0 0 0 $ccr-border-width-focus $ccr-color-outer;
}
&:checked ~ label::before {
background-color: $ccr-background-checked;
box-shadow: 0 0 0 $ccr-border-width $ccr-color-outer-checked;
}
}
}
// Checkbox-specific
.checkbox input {
~ label {
&::before {
border-radius: $ccr-border-radius-checkbox;
}
}
&:checked ~ label::before {
background-image: svg(
"<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><path d='M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z' fill='#{$ccr-color-inner}' /></svg>"
);
background-size: $ccr-icon-scale-checkbox $ccr-icon-scale-checkbox;
}
}
// Radio-specific
.radio input {
~ label {
&::before {
border-radius: 50%;
}
}
&:checked ~ label::before {
background-image: svg(
"<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='12' fill='#{$ccr-color-inner}' /></svg>"
);
background-size: $ccr-icon-scale-radio $ccr-icon-scale-radio;
}
}