(props: CheckboxProps)
| 9 | } |
| 10 | |
| 11 | export function Checkbox(props: CheckboxProps) { |
| 12 | const styles = createStyles() |
| 13 | const [isChecked, setIsChecked] = createSignal(props.checked || false) |
| 14 | const descriptionId = `${createUniqueId()}-description` |
| 15 | |
| 16 | const handleChange = (e: Event) => { |
| 17 | const checked = (e.target as HTMLInputElement).checked |
| 18 | setIsChecked(checked) |
| 19 | props.onChange?.(checked) |
| 20 | } |
| 21 | |
| 22 | return ( |
| 23 | <div class={styles().checkboxContainer}> |
| 24 | <label class={styles().checkboxWrapper}> |
| 25 | <input |
| 26 | data-tsd-control |
| 27 | data-tsd-selected={isChecked() ? 'true' : undefined} |
| 28 | aria-describedby={props.description ? descriptionId : undefined} |
| 29 | type="checkbox" |
| 30 | checked={props.checked ?? isChecked()} |
| 31 | class={styles().checkbox} |
| 32 | onInput={handleChange} |
| 33 | /> |
| 34 | <div class={styles().checkboxLabelContainer}> |
| 35 | {props.label && ( |
| 36 | <span class={styles().checkboxLabel}>{props.label}</span> |
| 37 | )} |
| 38 | {props.description && ( |
| 39 | <span id={descriptionId} class={styles().checkboxDescription}> |
| 40 | {props.description} |
| 41 | </span> |
| 42 | )} |
| 43 | </div> |
| 44 | </label> |
| 45 | </div> |
| 46 | ) |
nothing calls this directly
no test coverage detected