Files
cunningham/packages/react/src/components/Forms/Checkbox/index.tsx

18 lines
497 B
TypeScript
Raw Normal View History

import React, { HTMLProps, useEffect, useRef } from "react";
export const Checkbox = ({
indeterminate,
className = "",
...rest
}: { indeterminate?: boolean } & HTMLProps<HTMLInputElement>) => {
const ref = useRef<HTMLInputElement>(null!);
useEffect(() => {
if (typeof indeterminate === "boolean") {
ref.current.indeterminate = !rest.checked && indeterminate;
}
}, [ref, indeterminate]);
return <input type="checkbox" ref={ref} className={className} {...rest} />;
};