diff --git a/frontend/src/components/IndeterminateCheckbox/index.tsx b/frontend/src/components/IndeterminateCheckbox/index.tsx new file mode 100644 index 0000000..bdb40b6 --- /dev/null +++ b/frontend/src/components/IndeterminateCheckbox/index.tsx @@ -0,0 +1,55 @@ +import { HTMLProps, useEffect, useRef } from 'react'; + +const IndeterminateCheckbox = ({ + indeterminate, + className = '', + ...rest +}: { indeterminate?: boolean } & HTMLProps) => { + const ref = useRef(null!); + + useEffect(() => { + if (typeof indeterminate === 'boolean') { + ref.current.indeterminate = !rest.checked && indeterminate; + } + }, [ref, indeterminate]); + + return ( + <> + + {indeterminate ? ( + + + + ) : ( + + + + )} + + ); +}; + +export default IndeterminateCheckbox; diff --git a/frontend/src/components/index.ts b/frontend/src/components/index.ts index fe08074..810e815 100644 --- a/frontend/src/components/index.ts +++ b/frontend/src/components/index.ts @@ -1,2 +1,4 @@ import Example from './example'; -export { Example }; \ No newline at end of file +export { Example }; + +export { default as IndeterminateCheckbox } from './IndeterminateCheckbox';