From 00bffcf4fcf055dbb3c2dc146daa4b704bc482d7 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Fri, 27 Oct 2023 20:48:02 -0700 Subject: [PATCH] Introduce fujifilm simulations dropdown --- src/components/FieldSetWithStatus.tsx | 56 ++++++-- src/photo/PhotoForm.tsx | 4 + src/photo/form.ts | 18 ++- src/site/globals.css | 18 ++- src/vendors/fujifilm/index.ts | 199 +++++++++++++------------- 5 files changed, 176 insertions(+), 119 deletions(-) diff --git a/src/components/FieldSetWithStatus.tsx b/src/components/FieldSetWithStatus.tsx index affe5150..c518e37d 100644 --- a/src/components/FieldSetWithStatus.tsx +++ b/src/components/FieldSetWithStatus.tsx @@ -11,6 +11,8 @@ export default function FieldSetWithStatus({ note, value, onChange, + selectOptions, + selectOptionsDefaultLabel, placeholder, loading, required, @@ -23,6 +25,8 @@ export default function FieldSetWithStatus({ note?: string value: string onChange?: (value: string) => void + selectOptions?: { value: string, label: string }[] + selectOptionsDefaultLabel?: string placeholder?: string loading?: boolean required?: boolean @@ -52,21 +56,43 @@ export default function FieldSetWithStatus({ } - onChange?.(type === 'checkbox' - ? e.target.value === 'true' ? 'false' : 'true' - : e.target.value)} - type={type} - autoComplete="off" - readOnly={readOnly || pending} - className={cc(type === 'text' && 'w-full')} - /> + {selectOptions + ? + : onChange?.(type === 'checkbox' + ? e.target.value === 'true' ? 'false' : 'true' + : e.target.value)} + type={type} + autoComplete="off" + readOnly={readOnly || pending} + className={cc(type === 'text' && 'w-full')} + />} ); }; diff --git a/src/photo/PhotoForm.tsx b/src/photo/PhotoForm.tsx index 6f07a4ae..9f680de0 100644 --- a/src/photo/PhotoForm.tsx +++ b/src/photo/PhotoForm.tsx @@ -96,6 +96,8 @@ export default function PhotoForm({ label, note, required, + options, + optionsDefaultLabel, readOnly, hideIfEmpty, hideBasedOnCamera, @@ -113,6 +115,8 @@ export default function PhotoForm({ note={note} value={formData[key] ?? ''} onChange={value => setFormData({ ...formData, [key]: value })} + selectOptions={options} + selectOptionsDefaultLabel={optionsDefaultLabel} required={required} readOnly={readOnly} placeholder={loadingMessage && !formData[key] diff --git a/src/photo/form.ts b/src/photo/form.ts index 0e055799..a8c8b140 100644 --- a/src/photo/form.ts +++ b/src/photo/form.ts @@ -8,7 +8,10 @@ import { getOffsetFromExif } from '@/utility/exif'; import { toFixedNumber } from '@/utility/number'; import { convertStringToArray } from '@/utility/string'; import { generateNanoid } from '@/utility/nanoid'; -import { FujifilmSimulation } from '@/vendors/fujifilm'; +import { + FILM_SIMULATION_FORM_INPUT_OPTIONS, + FujifilmSimulation, +} from '@/vendors/fujifilm'; export type PhotoFormData = Record; @@ -22,14 +25,20 @@ type FormMeta = { hideBasedOnCamera?: (make?: string, mode?: string) => boolean loadingMessage?: string checkbox?: boolean + options?: { value: string, label: string }[] + optionsDefaultLabel?: string }; const FORM_METADATA: Record = { title: { label: 'title' }, tags: { label: 'tags', note: 'comma-separated values' }, id: { label: 'id', readOnly: true, hideIfEmpty: true }, - // eslint-disable-next-line max-len - blurData: { label: 'blur data', readOnly: true, required: true, loadingMessage: 'Generating blur data ...' }, + blurData: { + label: 'blur data', + readOnly: true, + required: true, + loadingMessage: 'Generating blur data ...', + }, url: { label: 'url', readOnly: true }, extension: { label: 'extension', readOnly: true }, aspectRatio: { label: 'aspect ratio', readOnly: true }, @@ -37,7 +46,8 @@ const FORM_METADATA: Record = { model: { label: 'camera model' }, filmSimulation: { label: 'fujifilm simulation', - readOnly: true, + options: FILM_SIMULATION_FORM_INPUT_OPTIONS, + optionsDefaultLabel: 'Unknown', hideBasedOnCamera: make => make !== 'FUJIFILM', }, focalLength: { label: 'focal length' }, diff --git a/src/site/globals.css b/src/site/globals.css index 5cfbf843..5118a39d 100644 --- a/src/site/globals.css +++ b/src/site/globals.css @@ -18,22 +18,32 @@ tracking-wider } button, .button, - input[type=text], input[type=email], input[type=password] { + input[type=text], input[type=email], input[type=password], select { @apply - px-2 py-1.5 + px-2.5 py-2 border rounded-md bg-white dark:bg-black border-gray-200 dark:border-gray-700 - font-mono text-base leading-none + font-mono text-base leading-tight min-h-[2.25rem] } - input[type=text], input[type=email], input[type=password] { + input[type=text], input[type=email], input[type=password], select { @apply text-[1rem] /* Prevent iOS auto-zoom behavior */ min-w-[20rem] read-only:cursor-default + } + input[type=text], input[type=email], input[type=password] { + @apply read-only:bg-gray-100 dark:read-only:bg-gray-900 dark:read-only:text-gray-400 } + /* Required for readonly behavior on