From 1ce867210bcf70f3964faf71e66938d8d8b5843c Mon Sep 17 00:00:00 2001 From: tomtitherington Date: Sun, 5 Nov 2023 15:51:16 +0000 Subject: [PATCH] Move checkbox to new file and restyle from scratch --- .../IndeterminateCheckbox/index.tsx | 55 +++++++++++++++++++ frontend/src/components/index.ts | 4 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/IndeterminateCheckbox/index.tsx 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';