Skip to content

Commit

Permalink
Move checkbox to new file and restyle from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtitherington committed Nov 5, 2023
1 parent 8b8b2d7 commit 1ce8672
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
55 changes: 55 additions & 0 deletions frontend/src/components/IndeterminateCheckbox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { HTMLProps, useEffect, useRef } from 'react';

const IndeterminateCheckbox = ({
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
ref={ref}
className={`
peer relative appearance-none shrink-0 w-4 h-4 rounded border border-oxford bg-white
checked:bg-crumpet-yellow-500 checked:border-0
indeterminate:text-gray-500
disabled:border-steel-400 disabled:bg-steel-400
${className}
`}
type="checkbox"
{...rest}
/>
{indeterminate ? (
<svg
className="absolute w-4 h-4 px-0.5 pointer-events-none hidden peer-indeterminate:block"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24">
<rect x="4" y="11" width="16" height="2" fill="#51493E" />
</svg>
) : (
<svg
className="absolute w-4 h-4 p-0.5 pointer-events-none hidden peer-checked:block stroke-white outline-none"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="4"
strokeLinecap="round"
strokeLinejoin="round">
<polyline points="20 6 9 17 4 12"></polyline>
</svg>
)}
</>
);
};

export default IndeterminateCheckbox;
4 changes: 3 additions & 1 deletion frontend/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import Example from './example';
export { Example };
export { Example };

export { default as IndeterminateCheckbox } from './IndeterminateCheckbox';

0 comments on commit 1ce8672

Please sign in to comment.