diff --git a/src/components/input/CheckboxInput.tsx b/src/components/input/CheckboxInput.tsx new file mode 100644 index 00000000..fb0c95c7 --- /dev/null +++ b/src/components/input/CheckboxInput.tsx @@ -0,0 +1,89 @@ +'use client'; + +import { HTMLProps, useEffect, useRef } from 'react'; +import { cn } from '@/lib/helper'; + +interface CheckboxInputProps extends HTMLProps { + name: string; + label?: string; + indeterminate?: boolean; + classNames?: { + wrapper?: string; + inputWrapper?: string; + checkbox?: string; + label?: string; + }; + isError?: boolean; + isValid?: boolean; + errorMessage?: string; +} + +const CheckboxInput = ({ + indeterminate, + name, + label, + className, + classNames, + isValid, + isError, + errorMessage, + ...rest +}: CheckboxInputProps) => { + const ref = useRef(null!); + + useEffect(() => { + if (typeof indeterminate === 'boolean') { + ref.current.indeterminate = !rest.checked && indeterminate; + } + }, [ref, indeterminate]); + + return ( +
+
+ + + {label && ( + + )} +
+ + {errorMessage && {errorMessage}} +
+ ); +}; + +export default CheckboxInput;