import { CustomCheckboxContainer, CustomCheckboxInput, CustomCheckboxInputProps, } from '@reach/checkbox' import '@reach/checkbox/styles.css' import { ComponentChildren, FunctionalComponent } from 'preact' import { useState } from 'preact/hooks' import { HTMLProps } from 'react' export type SwitchProps = HTMLProps & { checked?: boolean // Optional in case it is wrapped in a button (e.g. a menu item) onChange?: (checked: boolean) => void className?: string children?: ComponentChildren role?: string } export const Switch: FunctionalComponent = (props: SwitchProps) => { const [checkedState, setChecked] = useState(props.checked || false) const checked = props.checked ?? checkedState const className = props.className ?? '' const isDisabled = !!props.disabled const isActive = checked && !isDisabled return ( ) }