import { ChangeEvent, FC, PropsWithChildren } from 'react'; import classNames from 'classnames'; import { identity } from 'ramda'; import { useDomId } from './helpers/hooks'; export type BooleanControlProps = PropsWithChildren<{ checked?: boolean; onChange?: (checked: boolean, e: ChangeEvent) => void; className?: string; inline?: boolean; }>; interface BooleanControlWithTypeProps extends BooleanControlProps { type: 'switch' | 'checkbox'; } export const BooleanControl: FC = ( { checked = false, onChange = identity, className, children, type, inline = false }, ) => { const id = useDomId(); const onChecked = (e: ChangeEvent) => onChange(e.target.checked, e); const typeClasses = { 'form-switch': type === 'switch', 'form-checkbox': type === 'checkbox', }; const style = inline ? { display: 'inline-block' } : {}; return ( ); };