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, form, onSubmit, children, readOnly, }: Omit, "computeFormState"> & { form: FlexibleForm }) { return (
{form.design.map((section, i) => { if (!section) return ; return (

{section.title}

{section.description && (

{section.description}

)}
); })}
{children}
); }