-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathCheckbox.svelte
More file actions
78 lines (66 loc) · 1.64 KB
/
Checkbox.svelte
File metadata and controls
78 lines (66 loc) · 1.64 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
<script>
import { onMount } from 'svelte';
import { page } from '$app/stores';
import IconEnabled from './icon-enabled.svg';
let {
checked = $bindable(),
onclick,
onchange,
oninput,
} = $props();
const onClick = (event) => {
if (onclick) onclick(event);
// oninput comes first before checked change
if (oninput) oninput(checked);
// change the checked
checked = !checked;
// onchange goes after
if (onchange) onchange(checked);
};
</script>
<!-- TODO: Add this to svelteui -->
<button
class="checkbox"
data-checked={checked}
data-penguinmodsvelteui-checkbox="true"
onclick={onClick}
>
{#if checked}
<img src={IconEnabled} alt="√" />
{/if}
</button>
<style>
.checkbox {
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 2px 0;
flex-shrink: 0;
background: transparent;
border: 1px solid rgba(0, 0, 0, 0.5);
border-radius: 3px;
cursor: pointer;
}
.checkbox img {
position: absolute;
width: calc(20px - 4px);
height: calc(20px - 4px);
left: 1px;
top: 1px;
filter: brightness(0.25);
pointer-events: none;
}
:global(body.dark-mode) .checkbox {
border-color: rgba(255, 255, 255, 0.5);
}
:global(body.dark-mode) .checkbox img {
filter: brightness(1);
}
.checkbox[data-checked="true"] {
background: dodgerblue;
}
.checkbox[data-checked="true"] img {
filter: brightness(1);
}
</style>