18 lines
497 B
TypeScript
18 lines
497 B
TypeScript
|
|
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} />;
|
||
|
|
};
|