forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggle.svelte
More file actions
80 lines (68 loc) · 1.7 KB
/
Copy pathToggle.svelte
File metadata and controls
80 lines (68 loc) · 1.7 KB
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
<script>
import iconLoader from "../../img/icon-loader.svg";
export let checked = false;
</script>
<style>
label {
--switch-timing: 150ms 75ms;
cursor: pointer;
display: block;
font-size: 1rem;
height: 1em;
min-width: 1.75em;
position: relative;
user-select: none;
width: 1.75em;
}
input[type=checkbox] {
display: block;
position: absolute;
visibility: hidden;
}
span {
background-color: var(--color-black);
border-radius: 0.625em;
display: block;
height: 100%;
pointer-events: none;
transition: background-color 100ms 75ms;
width: 100%;
}
span::before {
background-color: white;
border-radius: 50%;
content: "";
height: 0.75em;
left: 0.125em;
position: absolute;
top: 0.125em;
transition: left 175ms ease-in;
width: 0.75em;
}
input:checked + span {
background-color: var(--color-blue);
}
input:checked + span::before {
left: calc(100% - (0.75em + 0.125em)); /* minus el width + left */
}
:global(label svg) {
display: none;
height: 1em;
position: absolute;
right: 0;
top: 0;
width: 1em;
}
input:disabled + span {
opacity: 0;
}
:global(input:disabled + span + svg) {
display: block;
}
</style>
<!-- prevent toggle label clicks from triggering parent element on:click -->
<label on:click|stopPropagation={() => {}}>
<input type="checkbox" on:click|stopPropagation bind:checked={checked}>
<span></span>
{@html iconLoader}
</label>