import clsx from "clsx"; import { ReactNode, useEffect, useState } from "react"; import HintTooltip from "../tooltips/HintTooltip"; interface Props { name?: string; title?: string | ReactNode; description: string | ReactNode; value?: boolean; setValue?: React.Dispatch>; className?: string; help?: string; disabled?: boolean; autoFocus?: boolean; } export default function InputCheckboxWithDescription({ name, title, value, setValue, description, className, help, disabled = false, autoFocus }: Props) { const [checked, setChecked] = useState(value ?? false); useEffect(() => { if (value !== checked) { setChecked(value ?? false); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [value]); useEffect(() => { if (setValue && value !== checked) { setValue(checked); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [checked]); return (
{ setChecked(e.target.checked); }} disabled={disabled} autoFocus={autoFocus} className={clsx(disabled && "cursor-not-allowed bg-gray-100", "h-4 w-4 cursor-pointer rounded border-gray-300 text-accent-600 focus:ring-accent-500")} />
); }