import clsx from 'clsx'; import { forwardRef, useRef, useEffect, MutableRefObject, ChangeEventHandler, HTMLProps, } from 'react'; interface Props extends HTMLProps { checked?: boolean; indeterminate?: boolean; title?: string; label?: string; id: string; className?: string; role?: string; onChange?: ChangeEventHandler; bold?: boolean; } export const Checkbox = forwardRef( ( { indeterminate, title, label, id, checked, onChange, bold = true, ...props }: Props, ref ) => { const defaultRef = useRef(null); let resolvedRef = ref as MutableRefObject; if (!ref) { resolvedRef = defaultRef; } useEffect(() => { if (resolvedRef === null || resolvedRef.current === null) { return; } if (typeof indeterminate !== 'undefined') { resolvedRef.current.indeterminate = indeterminate; } }, [resolvedRef, indeterminate]); return (
); } );