-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathcheckbox.tsx
More file actions
43 lines (39 loc) · 1.13 KB
/
checkbox.tsx
File metadata and controls
43 lines (39 loc) · 1.13 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
import { createSignal } from 'solid-js'
import { useStyles } from '../styles/use-styles'
interface CheckboxProps {
label?: string
checked?: boolean
onChange?: (checked: boolean) => void
description?: string
}
export function Checkbox(props: CheckboxProps) {
const styles = useStyles()
const [isChecked, setIsChecked] = createSignal(props.checked || false)
const handleChange = (e: Event) => {
const checked = (e.target as HTMLInputElement).checked
setIsChecked(checked)
props.onChange?.(checked)
}
return (
<div class={styles().checkboxContainer}>
<label class={styles().checkboxWrapper}>
<input
type="checkbox"
checked={isChecked()}
class={styles().checkbox}
onInput={handleChange}
/>
<div class={styles().checkboxLabelContainer}>
{props.label && (
<span class={styles().checkboxLabel}>{props.label}</span>
)}
{props.description && (
<span class={styles().checkboxDescription}>
{props.description}
</span>
)}
</div>
</label>
</div>
)
}