import { h } from 'preact'; import { useCallback, useState } from 'preact/hooks'; export default function Switch({ checked, id, onChange, label, labelPosition = 'before' }) { const [isFocused, setFocused] = useState(false); const handleChange = useCallback(() => { if (onChange) { onChange(id, !checked); } }, [id, onChange, checked]); const handleFocus = useCallback(() => { onChange && setFocused(true); }, [onChange, setFocused]); const handleBlur = useCallback(() => { onChange && setFocused(false); }, [onChange, setFocused]); return (