flotilla/src/lib/components/ToggleInput.svelte

16 lines
514 B
Svelte
Raw Normal View History

2026-07-15 16:30:17 +00:00
<script lang="ts">
import type {HTMLInputAttributes} from "svelte/elements"
2026-07-15 16:30:17 +00:00
type Props = Omit<HTMLInputAttributes, "checked" | "onchange" | "type"> & {
2026-07-15 16:30:17 +00:00
checked?: boolean
onchange?: (checked: boolean) => void
}
let {checked = $bindable(), onchange, ...restProps}: Props = $props()
2026-07-15 16:30:17 +00:00
const onInput = (event: Event & {currentTarget: HTMLInputElement}) =>
onchange?.(event.currentTarget.checked)
</script>
<input {...restProps} type="checkbox" class="toggle" bind:checked onchange={onInput} />