From f9b6d7f48520b80bc3ae4fba796795acb5766139 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 15 Mar 2025 13:24:53 -0500 Subject: [PATCH] Finalize checkbox presentation/behavior --- src/components/Checkbox.tsx | 38 ++++++++++++++++----------- src/components/FieldSetWithStatus.tsx | 14 +++++++--- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx index 8fcd6ce8..9b3e480b 100644 --- a/src/components/Checkbox.tsx +++ b/src/components/Checkbox.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx/lite'; -import { InputHTMLAttributes, ReactNode, Ref } from 'react'; +import { InputHTMLAttributes, ReactNode, RefObject } from 'react'; import { ImCheckmark } from 'react-icons/im'; const boxStyles = clsx( @@ -14,18 +14,21 @@ export default function Checkbox({ accessory, type: _type, ...props -}: InputHTMLAttributes & { - ref?: Ref +}: Omit, 'ref'> & { + ref?: RefObject accessory?: ReactNode }) { return ( - + ref?.current?.click()} + > {accessory ? accessory : props.checked @@ -34,12 +37,15 @@ export default function Checkbox({ 'border-transparent', props.readOnly ? 'bg-gray-300 dark:bg-gray-700' - : 'bg-blue-600', + : 'bg-black', )}> - + : + inputRef?: RefObject accessory?: React.ReactNode hideLabel?: boolean }) { + const inputRefInternal = useRef(null); + + const inputRef = inputRefProp ?? inputRefInternal; + const id = _id || parameterize(label); const { pending } = useFormStatus(); @@ -68,7 +72,9 @@ export default function FieldSetWithStatus({ name: id, type, value, - checked: type === 'checkbox' ? value === 'true' : undefined, + checked: type === 'checkbox' + ? value === 'true' ? true : false + : undefined, placeholder, onChange: e => onChange?.(type === 'checkbox' ? e.target.value === 'true' ? 'false' : 'true'