blob: bd242731f17f51841fd66d8bbe0363893b76687a (
plain) (
blame)
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
|
<script>
export let checked = false;
export let id;
</script>
<style>
.toggle {
--width: 40px;
--height: calc(var(--width) / 2);
--border-radius: calc(var(--height) / 2);
display: inline-block;
cursor: pointer;
}
.toggle__input {
display: none;
}
.toggle__fill {
position: relative;
width: var(--width);
height: var(--height);
border-radius: var(--border-radius);
background: #dddddd;
transition: background 0.2s;
}
.toggle__fill::after {
content: "";
position: absolute;
top: 0;
left: 0;
height: var(--height);
width: var(--height);
background: #ffffff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
border-radius: var(--border-radius);
transition: transform 0.2s;
}
.toggle__input:checked ~ .toggle__fill {
background: #009578;
}
.toggle__input:checked ~ .toggle__fill::after {
transform: translateX(var(--height));
}
</style>
<label class="toggle" for="{id}">
<input class="toggle__input" id="{id}" name="{id}" type="checkbox" bind:checked={checked} on:change>
<div class="toggle__fill"></div>
</label>
|