import clsx from "clsx" import React, { useImperativeHandle } from "react" import CheckIcon from "../../fundamentals/icons/check-icon" type IndeterminateCheckboxProps = { type?: "checkbox" | "radio" onChange?: (e: React.ChangeEvent) => void checked?: boolean title?: string indeterminate?: boolean className?: React.HTMLAttributes["className"] name?: string disabled?: boolean // NOTE: only visual, still have to filter disabled ids out } const IndeterminateCheckbox = React.forwardRef< HTMLInputElement, IndeterminateCheckboxProps >(({ indeterminate = false, className, checked, ...rest }, ref) => { const type = rest.type || "checkbox" const innerRef = React.useRef(null) useImperativeHandle( ref, () => innerRef.current ) React.useEffect(() => { if (innerRef.current) { innerRef.current.indeterminate = indeterminate } }, [innerRef, indeterminate]) const handleClick = () => { if (!rest.disabled && innerRef.current) { innerRef.current.click() } } if (type === "radio") { return (
) } return (
{checked && }
) }) export default IndeterminateCheckbox