diff --git a/src/FieldDefinitionForm.tsx b/src/FieldDefinitionForm.tsx index e8aeb42..3fdb1c3 100644 --- a/src/FieldDefinitionForm.tsx +++ b/src/FieldDefinitionForm.tsx @@ -1,26 +1,33 @@ /** * Shared key + type editor for add/edit attribute flows - * (CE-WP-0007-T10/T11; CE-WP-0010 attributes vocabulary). - * Styled to match EvidenceFormBody / InlineCaptureForm. + * (CE-WP-0007-T10/T11; CE-WP-0010 vocabulary; CE-WP-0012 types). */ import type { CSSProperties, ReactNode } from "react"; -import type { FormFieldSchema } from "./FormRenderer"; +import { + DEFAULT_CURRENCY, + formatOptionsText, + IMPLEMENTED_FIELD_TYPES, + typeNeedsOptions, + type AttributeOption, + type AttributeValueType, +} from "./attribute-types"; -export type FieldType = FormFieldSchema["type"]; - -const FIELD_TYPES: readonly { value: FieldType; label: string }[] = [ - { value: "text", label: "Text" }, - { value: "textarea", label: "Text area" }, - { value: "date", label: "Date" }, -]; +export type FieldType = AttributeValueType; export interface FieldDefinitionFormProps { readonly label: string; readonly type: FieldType; + readonly options?: readonly AttributeOption[]; + readonly defaultCurrency?: string; onChangeLabel(next: string): void; onChangeType(next: FieldType): void; + onChangeOptions?(next: readonly AttributeOption[]): void; + onChangeDefaultCurrency?(next: string): void; + /** Raw options text (controlled by parent when provided). */ + readonly optionsText?: string; + onChangeOptionsText?(next: string): void; onSave(): void; onCancel(): void; readonly saveLabel?: string; @@ -32,6 +39,9 @@ export interface FieldDefinitionFormProps { export function FieldDefinitionForm(p: FieldDefinitionFormProps) { const saveLabel = p.saveLabel ?? "Save"; const cancelLabel = p.cancelLabel ?? "Cancel"; + const needsOptions = typeNeedsOptions(p.type); + const optionsText = + p.optionsText ?? formatOptionsText(p.options); return (
+ + {p.type === "amount" && ( + <> + + p.onChangeDefaultCurrency?.(e.target.value.toUpperCase())} + data-testid={`${p.testidPrefix}-currency-input`} + placeholder="EUR" + maxLength={3} + style={inputStyle} + /> + + )} + + {needsOptions && ( + <> + +