From 8cf7bc11283c8adfc6d90270b293dc5acb3858fe Mon Sep 17 00:00:00 2001 From: tegwick Date: Thu, 30 Jul 2026 21:05:43 +0200 Subject: [PATCH] Add attribute value types: time, datetime, amount, one-of, some-of. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement CE-WP-0012 interim catalog (accepted defaults): widgets, options editor, amount JSON encoding, textarea→text-long normalize. --- src/FieldDefinitionForm.tsx | 72 ++++++-- src/FormRenderer.dom.test.tsx | 8 +- src/FormRenderer.tsx | 334 ++++++++++++++++++++++++++++------ src/attribute-types.test.ts | 43 +++++ src/attribute-types.ts | 220 ++++++++++++++++++++++ src/index.ts | 24 ++- 6 files changed, 628 insertions(+), 73 deletions(-) create mode 100644 src/attribute-types.test.ts create mode 100644 src/attribute-types.ts 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 && ( + <> + +