From 609ad091e332e4150b4d472284e5a9518cbe7571 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 2 Jan 2024 17:56:42 -0300 Subject: sort for documentation --- packages/web-util/src/forms/DefaultForm.tsx | 47 ++++++++--- packages/web-util/src/forms/FormProvider.tsx | 94 ++++++++++++---------- .../src/forms/InputAbsoluteTime.stories.tsx | 2 +- packages/web-util/src/forms/InputAbsoluteTime.tsx | 10 +-- .../web-util/src/forms/InputAmount.stories.tsx | 2 +- packages/web-util/src/forms/InputAmount.tsx | 2 +- packages/web-util/src/forms/InputArray.stories.tsx | 2 +- packages/web-util/src/forms/InputArray.tsx | 2 +- .../src/forms/InputChoiceHorizontal.stories.tsx | 2 +- .../web-util/src/forms/InputChoiceHorizontal.tsx | 2 +- .../src/forms/InputChoiceStacked.stories.tsx | 2 +- packages/web-util/src/forms/InputChoiceStacked.tsx | 2 +- packages/web-util/src/forms/InputFile.stories.tsx | 2 +- packages/web-util/src/forms/InputFile.tsx | 2 +- .../web-util/src/forms/InputInteger.stories.tsx | 2 +- packages/web-util/src/forms/InputLine.stories.tsx | 2 +- packages/web-util/src/forms/InputLine.tsx | 2 +- .../src/forms/InputSelectMultiple.stories.tsx | 2 +- .../web-util/src/forms/InputSelectMultiple.tsx | 4 +- .../web-util/src/forms/InputSelectOne.stories.tsx | 2 +- packages/web-util/src/forms/InputText.stories.tsx | 2 +- packages/web-util/src/forms/InputText.tsx | 2 +- .../web-util/src/forms/InputTextArea.stories.tsx | 2 +- .../web-util/src/forms/InputToggle.stories.tsx | 2 +- packages/web-util/src/forms/InputToggle.tsx | 2 +- packages/web-util/src/forms/forms.ts | 41 ++++------ packages/web-util/src/forms/useField.ts | 8 +- 27 files changed, 134 insertions(+), 112 deletions(-) (limited to 'packages/web-util/src') diff --git a/packages/web-util/src/forms/DefaultForm.tsx b/packages/web-util/src/forms/DefaultForm.tsx index ffd2812da..1155401f5 100644 --- a/packages/web-util/src/forms/DefaultForm.tsx +++ b/packages/web-util/src/forms/DefaultForm.tsx @@ -1,7 +1,37 @@ -import { ComponentChildren, Fragment, h } from "preact"; -import { FormProvider } from "./FormProvider.js"; -import { FlexibleForm, RenderAllFieldsByUiConfig } from "./forms.js"; +import { Fragment, h } from "preact"; +import { FormProvider, FormProviderProps, FormState } from "./FormProvider.js"; +import { RenderAllFieldsByUiConfig, UIFormField } from "./forms.js"; +import { TranslatedString } from "@gnu-taler/taler-util"; +/** + * Flexible form uses a DoubleColumForm for design + * and may have a dynamic properties defined by + * behavior function. + */ +export interface FlexibleForm { + design: DoubleColumnForm; + behavior?: (form: Partial) => FormState; +} + +/** + * Double column form + * + * Form with sections, every sections have a title and may + * have a description. + * Every sections contain a set of fields. + */ +export type DoubleColumnForm = Array; + +export type DoubleColumnFormSection = { + title: TranslatedString; + description?: TranslatedString; + fields: UIFormField[]; +}; + +/** + * Form Provider implementation that use FlexibleForm + * to defined behavior and fields. + */ export function DefaultForm({ initial, onUpdate, @@ -9,17 +39,10 @@ export function DefaultForm({ onSubmit, children, readOnly, -}: { - children?: ComponentChildren; - initial: Partial; - onSubmit?: (v: Partial) => void; - form: FlexibleForm; - readOnly?: boolean; - onUpdate?: (d: Partial) => void; -}) { +}: Omit, "computeFormState"> & { form: FlexibleForm }) { return ( { value: MutableRef>; - initialValue?: Partial; + initial?: Partial; readOnly?: boolean; - onUpdate?: StateUpdater; - computeFormState?: (v: T) => FormState; + onUpdate?: (v: Partial) => void; + computeFormState?: (v: Partial) => FormState; } //@ts-ignore export const FormContext = createContext>({}); /** - * Map of {[field]:BehaviorResult} + * Map of {[field]:FieldUIOptions} * for every field of type * - any native (string, number, etc...) * - absoluteTime @@ -34,27 +33,53 @@ export const FormContext = createContext>({}); */ export type FormState = { [field in keyof T]?: T[field] extends AbsoluteTime - ? BehaviorResult + ? FieldUIOptions : T[field] extends AmountJson - ? BehaviorResult + ? FieldUIOptions : T[field] extends Array ? InputArrayFieldState

: T[field] extends (object | undefined) ? FormState - : BehaviorResult; + : FieldUIOptions; }; -export type BehaviorResult = Partial & FieldUIOptions - -export interface InputFieldState { - /* should show the error */ +/** + * Properties that can be defined by design or by computing state + */ +export type FieldUIOptions = { + /* text to be shown next to the field */ error?: TranslatedString; - /* should not allow to edit */ - readonly: boolean; - /* should show as disable */ - disabled: boolean; + /* instruction to be shown in the field */ + placeholder?: TranslatedString; + /* long text help to be shown on demand */ + tooltip?: TranslatedString; + /* short text to be shown next to the field*/ + + help?: TranslatedString; + /* should show as disabled and readonly */ + disabled?: boolean; /* should not show */ - hidden: boolean; + hidden?: boolean; + + /* show a mark as required*/ + required?: boolean; +} + +/** + * properties only to be defined on design time + */ +export interface UIFormProps extends FieldUIOptions { + + // property name of the object + name: K; + + // label if the field + label: TranslatedString; + before?: Addon; + after?: Addon; + + // converter to string and back + converter?: StringConverter; } export interface IconAddon { @@ -77,42 +102,25 @@ export interface StringConverter { fromStringUI: (v?: string) => T; } -type FieldUIOptions = { - placeholder?: TranslatedString; - tooltip?: TranslatedString; - help?: TranslatedString; - required?: boolean; -} - -export interface UIFormProps extends FieldUIOptions { - name: K; - label: TranslatedString; - before?: Addon; - after?: Addon; - converter?: StringConverter; +export interface InputArrayFieldState

extends FieldUIOptions { + elements?: FormState

[]; } -export interface InputArrayFieldState

extends BehaviorResult { - elements?: FormState

[]; +export type FormProviderProps = Omit, "value"> & { + onSubmit?: (v: Partial, s: FormState | undefined) => void; + children?: ComponentChildren; } export function FormProvider({ children, - initialValue, + initial, onUpdate: notify, onSubmit, computeFormState, readOnly, -}: { - initialValue?: Partial; - onUpdate?: (v: Partial) => void; - onSubmit?: (v: Partial, s: FormState | undefined) => void; - computeFormState?: (v: Partial) => FormState; - readOnly?: boolean; - children: ComponentChildren; -}): VNode { +}: FormProviderProps): VNode { - const [state, setState] = useState>(initialValue ?? {}); + const [state, setState] = useState>(initial ?? {}); const value = { current: state }; const onUpdate = (v: typeof state) => { setState(v); @@ -120,7 +128,7 @@ export function FormProvider({ }; return (

{ diff --git a/packages/web-util/src/forms/InputAbsoluteTime.stories.tsx b/packages/web-util/src/forms/InputAbsoluteTime.stories.tsx index d146d20bf..6245cf27c 100644 --- a/packages/web-util/src/forms/InputAbsoluteTime.stories.tsx +++ b/packages/web-util/src/forms/InputAbsoluteTime.stories.tsx @@ -22,9 +22,9 @@ import { AbsoluteTime, TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Absolute Time", diff --git a/packages/web-util/src/forms/InputAbsoluteTime.tsx b/packages/web-util/src/forms/InputAbsoluteTime.tsx index 0e03c5595..ee18e5592 100644 --- a/packages/web-util/src/forms/InputAbsoluteTime.tsx +++ b/packages/web-util/src/forms/InputAbsoluteTime.tsx @@ -13,7 +13,7 @@ export function InputAbsoluteTime( props: { pattern?: string } & UIFormProps, ): VNode { const pattern = props.pattern ?? "dd/MM/yyyy"; - const [open, setOpen] = useState(true) + const [open, setOpen] = useState(false) const { value, onChange } = useField(props.name); return ( @@ -53,7 +53,7 @@ export function InputAbsoluteTime( }} {...props} /> - {/* {open && + {open && setOpen(false)}> { @@ -61,8 +61,8 @@ export function InputAbsoluteTime( setOpen(false) }} /> - } */} - {open && + } + {/* {open && setOpen(false)} > { @@ -71,7 +71,7 @@ export function InputAbsoluteTime( onConfirm={() => { setOpen(false) }} /> - } + } */} ); } diff --git a/packages/web-util/src/forms/InputAmount.stories.tsx b/packages/web-util/src/forms/InputAmount.stories.tsx index d6dd9387a..c9f12a437 100644 --- a/packages/web-util/src/forms/InputAmount.stories.tsx +++ b/packages/web-util/src/forms/InputAmount.stories.tsx @@ -22,9 +22,9 @@ import { AmountJson, Amounts, TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Amount", diff --git a/packages/web-util/src/forms/InputAmount.tsx b/packages/web-util/src/forms/InputAmount.tsx index 29ec43525..7a8c08f76 100644 --- a/packages/web-util/src/forms/InputAmount.tsx +++ b/packages/web-util/src/forms/InputAmount.tsx @@ -1,8 +1,8 @@ import { AmountJson, Amounts, TranslatedString } from "@gnu-taler/taler-util"; import { VNode, h } from "preact"; +import { UIFormProps } from "./FormProvider.js"; import { InputLine } from "./InputLine.js"; import { useField } from "./useField.js"; -import { UIFormProps } from "./FormProvider.js"; export function InputAmount( props: { currency?: string } & UIFormProps, diff --git a/packages/web-util/src/forms/InputArray.stories.tsx b/packages/web-util/src/forms/InputArray.stories.tsx index c44789c37..8dbd3ff07 100644 --- a/packages/web-util/src/forms/InputArray.stories.tsx +++ b/packages/web-util/src/forms/InputArray.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Array", diff --git a/packages/web-util/src/forms/InputArray.tsx b/packages/web-util/src/forms/InputArray.tsx index 38c399e66..7d9a1b378 100644 --- a/packages/web-util/src/forms/InputArray.tsx +++ b/packages/web-util/src/forms/InputArray.tsx @@ -132,7 +132,7 @@ export function InputArray( * Consider creating an InnerFormProvider since not every feature is expected */ { // current state is ignored diff --git a/packages/web-util/src/forms/InputChoiceHorizontal.stories.tsx b/packages/web-util/src/forms/InputChoiceHorizontal.stories.tsx index a1c60e44a..2907a4dab 100644 --- a/packages/web-util/src/forms/InputChoiceHorizontal.stories.tsx +++ b/packages/web-util/src/forms/InputChoiceHorizontal.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Choice Horizontal", diff --git a/packages/web-util/src/forms/InputChoiceHorizontal.tsx b/packages/web-util/src/forms/InputChoiceHorizontal.tsx index b490a2c25..778b73c75 100644 --- a/packages/web-util/src/forms/InputChoiceHorizontal.tsx +++ b/packages/web-util/src/forms/InputChoiceHorizontal.tsx @@ -1,8 +1,8 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import { Fragment, VNode, h } from "preact"; +import { UIFormProps } from "./FormProvider.js"; import { LabelWithTooltipMaybeRequired } from "./InputLine.js"; import { useField } from "./useField.js"; -import { UIFormProps } from "./FormProvider.js"; export interface ChoiceH { label: TranslatedString; diff --git a/packages/web-util/src/forms/InputChoiceStacked.stories.tsx b/packages/web-util/src/forms/InputChoiceStacked.stories.tsx index 11816ed98..54228934e 100644 --- a/packages/web-util/src/forms/InputChoiceStacked.stories.tsx +++ b/packages/web-util/src/forms/InputChoiceStacked.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Choice Stacked", diff --git a/packages/web-util/src/forms/InputChoiceStacked.tsx b/packages/web-util/src/forms/InputChoiceStacked.tsx index e49b87800..234bb2255 100644 --- a/packages/web-util/src/forms/InputChoiceStacked.tsx +++ b/packages/web-util/src/forms/InputChoiceStacked.tsx @@ -1,8 +1,8 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import { Fragment, VNode, h } from "preact"; +import { UIFormProps } from "./FormProvider.js"; import { LabelWithTooltipMaybeRequired } from "./InputLine.js"; import { useField } from "./useField.js"; -import { UIFormProps } from "./FormProvider.js"; export interface ChoiceS { label: TranslatedString; diff --git a/packages/web-util/src/forms/InputFile.stories.tsx b/packages/web-util/src/forms/InputFile.stories.tsx index 6779977b6..ba06debf9 100644 --- a/packages/web-util/src/forms/InputFile.stories.tsx +++ b/packages/web-util/src/forms/InputFile.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input File", diff --git a/packages/web-util/src/forms/InputFile.tsx b/packages/web-util/src/forms/InputFile.tsx index bc460f370..6337d0902 100644 --- a/packages/web-util/src/forms/InputFile.tsx +++ b/packages/web-util/src/forms/InputFile.tsx @@ -1,7 +1,7 @@ import { Fragment, VNode, h } from "preact"; +import { UIFormProps } from "./FormProvider.js"; import { LabelWithTooltipMaybeRequired } from "./InputLine.js"; import { useField } from "./useField.js"; -import { UIFormProps, BehaviorResult } from "./FormProvider.js"; export function InputFile( props: { maxBites: number; accept?: string } & UIFormProps, diff --git a/packages/web-util/src/forms/InputInteger.stories.tsx b/packages/web-util/src/forms/InputInteger.stories.tsx index f3bdfc500..bd1a467ab 100644 --- a/packages/web-util/src/forms/InputInteger.stories.tsx +++ b/packages/web-util/src/forms/InputInteger.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Integer", diff --git a/packages/web-util/src/forms/InputLine.stories.tsx b/packages/web-util/src/forms/InputLine.stories.tsx index d048aa05a..da41a221e 100644 --- a/packages/web-util/src/forms/InputLine.stories.tsx +++ b/packages/web-util/src/forms/InputLine.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Line", diff --git a/packages/web-util/src/forms/InputLine.tsx b/packages/web-util/src/forms/InputLine.tsx index 8c44b1ca5..b8879f9ec 100644 --- a/packages/web-util/src/forms/InputLine.tsx +++ b/packages/web-util/src/forms/InputLine.tsx @@ -1,8 +1,8 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import { ComponentChildren, Fragment, VNode, h } from "preact"; -import { useField } from "./useField.js"; import { useEffect, useState } from "preact/hooks"; import { UIFormProps } from "./FormProvider.js"; +import { useField } from "./useField.js"; //@ts-ignore const TooltipIcon = ( diff --git a/packages/web-util/src/forms/InputSelectMultiple.stories.tsx b/packages/web-util/src/forms/InputSelectMultiple.stories.tsx index 7fdc7fca5..6ce5445c0 100644 --- a/packages/web-util/src/forms/InputSelectMultiple.stories.tsx +++ b/packages/web-util/src/forms/InputSelectMultiple.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Select Multiple", diff --git a/packages/web-util/src/forms/InputSelectMultiple.tsx b/packages/web-util/src/forms/InputSelectMultiple.tsx index a721eadce..a67eb23b7 100644 --- a/packages/web-util/src/forms/InputSelectMultiple.tsx +++ b/packages/web-util/src/forms/InputSelectMultiple.tsx @@ -1,9 +1,9 @@ import { Fragment, VNode, h } from "preact"; +import { useState } from "preact/hooks"; +import { UIFormProps } from "./FormProvider.js"; import { ChoiceS } from "./InputChoiceStacked.js"; import { LabelWithTooltipMaybeRequired } from "./InputLine.js"; import { useField } from "./useField.js"; -import { useState } from "preact/hooks"; -import { UIFormProps } from "./FormProvider.js"; export function InputSelectMultiple( props: { diff --git a/packages/web-util/src/forms/InputSelectOne.stories.tsx b/packages/web-util/src/forms/InputSelectOne.stories.tsx index acf2d0c8f..9e9029a77 100644 --- a/packages/web-util/src/forms/InputSelectOne.stories.tsx +++ b/packages/web-util/src/forms/InputSelectOne.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Select One", diff --git a/packages/web-util/src/forms/InputText.stories.tsx b/packages/web-util/src/forms/InputText.stories.tsx index 0137b7488..04ab8a1c6 100644 --- a/packages/web-util/src/forms/InputText.stories.tsx +++ b/packages/web-util/src/forms/InputText.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Text", diff --git a/packages/web-util/src/forms/InputText.tsx b/packages/web-util/src/forms/InputText.tsx index 7ad36b737..1c0c04225 100644 --- a/packages/web-util/src/forms/InputText.tsx +++ b/packages/web-util/src/forms/InputText.tsx @@ -1,6 +1,6 @@ import { VNode, h } from "preact"; -import { InputLine } from "./InputLine.js"; import { UIFormProps } from "./FormProvider.js"; +import { InputLine } from "./InputLine.js"; export function InputText( props: UIFormProps, diff --git a/packages/web-util/src/forms/InputTextArea.stories.tsx b/packages/web-util/src/forms/InputTextArea.stories.tsx index 50d659a74..c8c3eb088 100644 --- a/packages/web-util/src/forms/InputTextArea.stories.tsx +++ b/packages/web-util/src/forms/InputTextArea.stories.tsx @@ -23,8 +23,8 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { DefaultForm as TestedComponent, + FlexibleForm, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Text Area", diff --git a/packages/web-util/src/forms/InputToggle.stories.tsx b/packages/web-util/src/forms/InputToggle.stories.tsx index 005a1d448..ca6857618 100644 --- a/packages/web-util/src/forms/InputToggle.stories.tsx +++ b/packages/web-util/src/forms/InputToggle.stories.tsx @@ -22,9 +22,9 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { + FlexibleForm, DefaultForm as TestedComponent, } from "./DefaultForm.js"; -import { FlexibleForm } from "./forms.js"; export default { title: "Input Toggle", diff --git a/packages/web-util/src/forms/InputToggle.tsx b/packages/web-util/src/forms/InputToggle.tsx index 1ea8699b2..56b29c502 100644 --- a/packages/web-util/src/forms/InputToggle.tsx +++ b/packages/web-util/src/forms/InputToggle.tsx @@ -1,6 +1,6 @@ import { VNode, h } from "preact"; -import { InputLine, LabelWithTooltipMaybeRequired } from "./InputLine.js"; import { UIFormProps } from "./FormProvider.js"; +import { LabelWithTooltipMaybeRequired } from "./InputLine.js"; import { useField } from "./useField.js"; export function InputToggle( diff --git a/packages/web-util/src/forms/forms.ts b/packages/web-util/src/forms/forms.ts index 1c212fafa..3b8620bfb 100644 --- a/packages/web-util/src/forms/forms.ts +++ b/packages/web-util/src/forms/forms.ts @@ -1,34 +1,21 @@ -import { TranslatedString } from "@gnu-taler/taler-util"; -import { InputText } from "./InputText.js"; -import { InputAbsoluteTime } from "./InputAbsoluteTime.js"; -import { InputInteger } from "./InputInteger.js"; import { h as create, Fragment, VNode } from "preact"; -import { InputChoiceStacked } from "./InputChoiceStacked.js"; -import { InputArray } from "./InputArray.js"; -import { InputSelectMultiple } from "./InputSelectMultiple.js"; -import { InputTextArea } from "./InputTextArea.js"; -import { InputFile } from "./InputFile.js"; import { Caption } from "./Caption.js"; +import { FormProvider } from "./FormProvider.js"; import { Group } from "./Group.js"; -import { InputSelectOne } from "./InputSelectOne.js"; -import { FormProvider, FormState } from "./FormProvider.js"; -import { InputLine } from "./InputLine.js"; +import { InputAbsoluteTime } from "./InputAbsoluteTime.js"; import { InputAmount } from "./InputAmount.js"; +import { InputArray } from "./InputArray.js"; import { InputChoiceHorizontal } from "./InputChoiceHorizontal.js"; +import { InputChoiceStacked } from "./InputChoiceStacked.js"; +import { InputFile } from "./InputFile.js"; +import { InputInteger } from "./InputInteger.js"; +import { InputLine } from "./InputLine.js"; +import { InputSelectMultiple } from "./InputSelectMultiple.js"; +import { InputSelectOne } from "./InputSelectOne.js"; +import { InputText } from "./InputText.js"; +import { InputTextArea } from "./InputTextArea.js"; import { InputToggle } from "./InputToggle.js"; -export type DoubleColumnForm = Array; - -export type DoubleColumnFormSection = { - title: TranslatedString; - description?: TranslatedString; - fields: UIFormField[]; -}; -export interface FlexibleForm { - design: DoubleColumnForm; - behavior?: (form: Partial) => FormState; -} - /** * Constrain the type with the ui props */ @@ -127,6 +114,12 @@ type FormSet = { InputLine: () => typeof InputLine; InputChoiceHorizontal: () => typeof InputChoiceHorizontal; }; + +/** + * Helper function that created a typed object. + * + * @returns + */ export function createNewForm() { const res: FormSet = { Provider: FormProvider, diff --git a/packages/web-util/src/forms/useField.ts b/packages/web-util/src/forms/useField.ts index 651778628..eed8cebea 100644 --- a/packages/web-util/src/forms/useField.ts +++ b/packages/web-util/src/forms/useField.ts @@ -1,10 +1,10 @@ import { useContext, useState } from "preact/compat"; -import { BehaviorResult, FormContext, InputFieldState } from "./FormProvider.js"; +import { FieldUIOptions, FormContext } from "./FormProvider.js"; export interface InputFieldHandler { value: Type; onChange: (s: Type) => void; - state: BehaviorResult; + state: FieldUIOptions; isDirty: boolean; } @@ -12,7 +12,6 @@ export function useField( name: K, ): InputFieldHandler { const { - initialValue, value: formValue, computeFormState, onUpdate: notifyUpdate, @@ -27,12 +26,11 @@ export function useField( // console.log("USE FIELD", String(name), formValue.current, fieldValue); const [currentValue, setCurrentValue] = useState(fieldValue); const fieldState = - readField>(formState, String(name)) ?? {}; + readField>(formState, String(name)) ?? {}; //compute default state const state = { disabled: readOnlyForm ? true : (fieldState.disabled ?? false), - readonly: readOnlyForm ? true : (fieldState.readonly ?? false), hidden: fieldState.hidden ?? false, error: fieldState.error, help: fieldState.help, -- cgit v1.2.3