-
Notifications
You must be signed in to change notification settings - Fork 0
/
darkswitch.css
107 lines (106 loc) · 2.58 KB
/
darkswitch.css
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
:root {
--hue: 223;
--primary: hsl(var(--hue), 90%, 50%);
--trans-dur: 0.6s;
--trans-timing: cubic-bezier(0.65, 0, 0.35, 1);
}
.switch,
.switch__input {
display: block;
-webkit-tap-highlight-color: transparent;
}
.switch {
margin: auto;
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.switch__icon {
color: hsla(var(--hue), 10%, 80%);
pointer-events: none;
position: absolute;
top: 0.375em;
left: 0.375em;
width: 0.75em;
height: 0.75em;
transition: color var(--trans-dur),
transform var(--trans-dur) var(--trans-timing);
}
.switch__icon:nth-of-type(2) {
right: 0.375em;
left: auto;
}
.switch__inner,
.switch__inner-icons {
border-radius: 0.5em;
display: block;
overflow: hidden;
position: absolute;
top: 0.25em;
left: 0.25em;
width: 2.25em;
height: 1em;
}
.switch__inner:before,
.switch__inner-icons {
transition: transform var(--trans-dur) var(--trans-timing);
transform: translateX(-1.25em);
}
.switch__inner:before {
background-color: var(--primary);
border-radius: inherit;
content: '';
display: block;
width: 100%;
height: 100%;
}
.switch__inner-icons {
pointer-events: none;
}
.switch__inner-icons .switch__icon {
color: hsl(0, 0%, 100%);
top: 0.125em;
left: 0.125em;
transform: translateX(1.25em);
}
.switch__inner-icons .switch__icon:nth-child(2) {
right: 0.125em;
left: auto;
}
.switch__input {
background-color: hsl(0, 0%, 100%);
border-radius: 0.75em;
box-shadow: 0 0 0 0.0625em hsla(var(--hue), 90%, 50%, 0),
0 0.125em 0.5em hsla(var(--hue), 10%, 10%, 0.1);
outline: transparent;
width: 2.75em;
height: 1.5em;
-webkit-appearance: none;
appearance: none;
transition: background-color var(--trans-dur), box-shadow var(--trans-dur);
}
.switch__input:checked {
background-color: hsl(var(--hue), 10%, 10%);
}
.switch__input:checked ~ .switch__icon {
color: hsla(var(--hue), 10%, 40%);
}
.switch__input:checked ~ .switch__inner:before,
.switch__input:checked ~ .switch__inner-icons {
transform: translateX(1.25em);
}
.switch__input:not(:checked) ~ .switch__icon:first-of-type,
.switch__input:checked ~ .switch__icon:nth-of-type(2) {
transform: rotate(360deg);
}
.switch__input:checked ~ .switch__inner-icons .switch__icon:first-of-type {
transform: translateX(-1.25em) rotate(-360deg);
}
.switch__input:checked ~ .switch__inner-icons .switch__icon:nth-of-type(2) {
transform: translateX(-1.25em) rotate(360deg);
}
.switch__input:focus-visible {
box-shadow: 0 0 0 0.0625em hsla(var(--hue), 90%, 50%, 1),
0 0.125em 0.5em hsla(var(--hue), 10%, 10%, 0.1);
}