From f76a2e88dfc3f80dea552314d6b37a067e5c0836 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 15 Mar 2025 10:46:15 -0500 Subject: [PATCH] Create custom checkbox --- src/admin/AdminBatchUploadActions.tsx | 43 ++++---- src/admin/SignInOrUploadClient.tsx | 2 +- src/components/Checkbox.tsx | 53 ++++++++++ src/components/FieldSetWithStatus.tsx | 100 ++++++++++-------- .../form/ApplyRecipesGloballyCheckbox.tsx | 14 +-- 5 files changed, 131 insertions(+), 81 deletions(-) create mode 100644 src/components/Checkbox.tsx diff --git a/src/admin/AdminBatchUploadActions.tsx b/src/admin/AdminBatchUploadActions.tsx index 68d63b51..a081e068 100644 --- a/src/admin/AdminBatchUploadActions.tsx +++ b/src/admin/AdminBatchUploadActions.tsx @@ -12,7 +12,6 @@ import { } from '@/utility/date'; import sleep from '@/utility/sleep'; import { readStreamableValue } from 'ai/rsc'; -import { clsx } from 'clsx/lite'; import { useRouter } from 'next/navigation'; import { Dispatch, SetStateAction, useRef, useState } from 'react'; import { BiCheckCircle, BiImageAdd } from 'react-icons/bi'; @@ -120,15 +119,9 @@ export default function AdminBatchUploadActions({
-
+
{showBulkSettings - ? ( - tagErrorMessage || - `Apply to ${pluralize(storageUrls.length, 'upload')}` - ) + ? `Apply to ${pluralize(storageUrls.length, 'upload')}` : `Found ${pluralize(storageUrls.length, 'upload')}`}
{showBulkSettings && !actionErrorMessage && -
+
- - +
+ + +
}
& { + ref?: Ref + accessory?: ReactNode +}) { + return ( + + {accessory + ? accessory + : props.checked + ? + + + : } + + + ); +} diff --git a/src/components/FieldSetWithStatus.tsx b/src/components/FieldSetWithStatus.tsx index 25b146a7..629a47e2 100644 --- a/src/components/FieldSetWithStatus.tsx +++ b/src/components/FieldSetWithStatus.tsx @@ -1,6 +1,6 @@ 'use client'; -import { Ref } from 'react'; +import { Ref, InputHTMLAttributes } from 'react'; import { useFormStatus } from 'react-dom'; import Spinner from './Spinner'; import { clsx } from 'clsx/lite'; @@ -8,6 +8,7 @@ import { FieldSetType, AnnotatedTag } from '@/photo/form'; import TagInput from './TagInput'; import { FiChevronDown } from 'react-icons/fi'; import { parameterize } from '@/utility/string'; +import Checkbox from './Checkbox'; export default function FieldSetWithStatus({ id: _id, @@ -33,7 +34,6 @@ export default function FieldSetWithStatus({ inputRef, accessory, hideLabel, - checkboxAccessory, }: { id?: string label: string @@ -58,59 +58,58 @@ export default function FieldSetWithStatus({ inputRef?: Ref accessory?: React.ReactNode hideLabel?: boolean - checkboxAccessory?: React.ReactNode }) { const id = _id || parameterize(label); const { pending } = useFormStatus(); - const renderInput = - onChange?.(type === 'checkbox' - ? e.target.value === 'true' ? 'false' : 'true' - : e.target.value)} - spellCheck={spellCheck} - autoComplete="off" - autoCapitalize={!capitalize ? 'off' : undefined} - readOnly={readOnly || pending || loading} - disabled={type === 'checkbox' && ( + const inputProps: InputHTMLAttributes = { + id, + name: id, + type, + value, + checked: type === 'checkbox' ? value === 'true' : undefined, + placeholder, + onChange: e => onChange?.(type === 'checkbox' + ? e.target.value === 'true' ? 'false' : 'true' + : e.target.value), + spellCheck, + autoComplete: 'off', + autoCapitalize: !capitalize ? 'off' : undefined, + readOnly: readOnly || pending || loading, + disabled: type === 'checkbox' && ( + readOnly || pending || loading + ), + className: clsx( + ( + type === 'text' || + type === 'email' || + type === 'password' + ) && 'w-full', + type === 'checkbox' && ( readOnly || pending || loading - )} - className={clsx( - ( - type === 'text' || - type === 'email' || - type === 'password' - ) && 'w-full', - type === 'checkbox' && ( - readOnly || pending || loading - ) && 'opacity-50 cursor-not-allowed', - Boolean(error) && 'error', - )} - />; + ) && 'opacity-50 cursor-not-allowed', + Boolean(error) && 'error', + ), + }; return ( - type === 'hidden' - ? renderInput + type === 'hidden' + ? :
- {!hideLabel && label && + {!hideLabel &&