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
68 lines (60 loc) · 1.29 KB
/
Copy pathToggle.svelte
File metadata and controls
68 lines (60 loc) · 1.29 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
<script>
export let checked = false;
export let disabled = false;
export let title = undefined;
export let ariaAttributes = {};
</script>
<!-- prevent toggle button clicks from triggering parent element on:click -->
<button
on:click|stopPropagation
{...ariaAttributes}
aria-pressed={checked}
{disabled}
{title}
aria-label="toggle"
>
<span aria-hidden="true"></span>
</button>
<style>
button {
--switch-timing: 150ms 75ms;
background-color: transparent;
font-size: var(--toggle-font-size, 1rem);
height: 1em;
min-width: 1.75em;
position: relative;
width: 1.75em;
}
/* ios */
@supports (-webkit-touch-callout: none) {
button {
font-size: var(--toggle-font-size, 2rem);
}
}
span {
background-color: var(--color-grey);
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;
}
button[aria-pressed="true"] > span {
background-color: var(--color-blue);
}
button[aria-pressed="true"] > span::before {
left: calc(100% - (0.75em + 0.125em)); /* minus el width + left */
}
</style>