-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_Checkbox.scss
112 lines (99 loc) · 3.17 KB
/
_Checkbox.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
@import 'Normalize';
// Default variables
$default-checkbox-size: 18px;
$default-checkbox-thickness: 1px;
$default-checkbox-color: #666;
$default-checkbox-border-thickness: 1px;
$default-checkbox-border-radius: 15%;
$default-checkbox-desaturate-percentage: 50%;
$default-checkbox-type: 'outline';
$checkbox-lighten-percentage: 5%;
$checkbox-on-hover-opacity: 0.2;
$checkbox-transition-duration: 0.2s;
@mixin CheckboxHover(
$size: $default-checkbox-size,
$thickness: $default-checkbox-thickness,
$color: $default-checkbox-color,
$border-thickness: $default-checkbox-border-thickness,
$border-radius: $default-checkbox-border-radius,
$desaturate-percentage: $default-checkbox-desaturate-percentage,
$type: $default-checkbox-type) {
cursor: pointer;
border: $border-thickness solid lighten($color, $checkbox-lighten-percentage);
@if $type == 'outline' {
&:after {
opacity: $checkbox-on-hover-opacity;
}
}
@if $type == 'fill' {
background-color: transparentize($color, (1-$checkbox-on-hover-opacity));
}
}
@mixin Checkbox(
$size: $default-checkbox-size,
$thickness: $default-checkbox-thickness,
$color: $default-checkbox-color,
$border-thickness: $default-checkbox-border-thickness,
$border-radius: $default-checkbox-border-radius,
$desaturate-percentage: $default-checkbox-desaturate-percentage,
$type: $default-checkbox-type) {
// Hide the actual checkbox
display: none;
& + * {
// Styling adjacent container as checkbox
position: relative;
display: inline-block;
vertical-align: middle;
width: $size;
height: $size;
border: $border-thickness solid desaturate(lighten($color, $checkbox-lighten-percentage), $desaturate-percentage);
box-sizing: border-box;
@include border-radius($border-radius);
@include transition(all $checkbox-transition-duration);
&:hover {
// Hover styles
@include CheckboxHover(
$size: $size, $thickness: $thickness, $color: $color,
$border-thickness: $border-thickness, $border-radius: $border-radius,
$desaturate-percentage: $desaturate-percentage, $type: $type);
}
&:after {
// This contains the tick mark. Its a rotated rectangle with border
// on two adjacent sides
position: absolute;
box-sizing: border-box;
width: $size / 1.5;
height: $size / 3;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
content: '';
opacity: 0;
border-left: $thickness solid $color;
border-bottom: $thickness solid $color;
@include transform(translateY(-20%) rotate(-45deg));
@include transition(all $checkbox-transition-duration);
}
}
&:checked + * {
// Styling adjacent container when it is checked
@if $type == 'outline' {
// Checkbox of type outline
border: $border-thickness solid lighten($color, $checkbox-lighten-percentage);
}
@if $type == 'fill' {
// Checkbox of type filled
border: $border-thickness solid $color;
background-color: $color;
&:after {
border-color: #FFF;
}
}
&:after {
// Displaying the checkmark
opacity: 1;
}
}
}