diff options
author | Sebastian <sebasjm@gmail.com> | 2024-05-03 08:43:53 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-05-03 08:44:07 -0300 |
commit | 20353eda268efa962959bead466b59823bfb9b29 (patch) | |
tree | 868d016693f09b40e2c55893d3aed72eca505ecb /packages/aml-backoffice-ui/src/context/ui-forms.ts | |
parent | fa4c7039f4ebeb6ad3cf19237ad7b138519ac142 (diff) | |
download | wallet-core-20353eda268efa962959bead466b59823bfb9b29.tar.xz |
form hook now takes the shape of the form (do not rely on initial value)
Diffstat (limited to 'packages/aml-backoffice-ui/src/context/ui-forms.ts')
-rw-r--r-- | packages/aml-backoffice-ui/src/context/ui-forms.ts | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/packages/aml-backoffice-ui/src/context/ui-forms.ts b/packages/aml-backoffice-ui/src/context/ui-forms.ts index 2e0b8a76d..9cf6125c9 100644 --- a/packages/aml-backoffice-ui/src/context/ui-forms.ts +++ b/packages/aml-backoffice-ui/src/context/ui-forms.ts @@ -39,7 +39,7 @@ import { useContext } from "preact/hooks"; export type Type = UiForms; const defaultForms: UiForms = { - forms: [] + forms: [], }; const Context = createContext<Type>(defaultForms); @@ -142,7 +142,7 @@ type UIFormFieldConfigCaption = { type UIFormFieldConfigGroup = { type: "group"; - properties: UIFormFieldBaseConfig & { + properties: UIFieldBaseDescription & { fields: UIFormFieldConfig[]; }; }; @@ -213,7 +213,7 @@ type UIFormFieldConfigToggle = { properties: UIFormFieldBaseConfig; }; -type UIFieldBaseDescription = { +export type UIFieldBaseDescription = { /* label if the field, visible for the user */ label: string; /* long text to be shown on user demand */ @@ -222,6 +222,9 @@ type UIFieldBaseDescription = { /* short text to be shown close to the field */ help?: string; + /* name of the field, useful for a11y */ + name: string; + /* if the field should be initialy hidden */ hidden?: boolean; /* ui element to show before */ @@ -230,7 +233,7 @@ type UIFieldBaseDescription = { addonAfterId?: string; }; -type UIFormFieldBaseConfig = UIFieldBaseDescription & { +export type UIFormFieldBaseConfig = UIFieldBaseDescription & { /* example to be shown inside the field */ placeholder?: string; @@ -240,9 +243,6 @@ type UIFormFieldBaseConfig = UIFieldBaseDescription & { /* readonly and dim */ disabled?: boolean; - /* name of the field, useful for a11y */ - name: string; - /* conversion id to conver the string into the value type the id should be known to the ui impl */ @@ -258,23 +258,27 @@ export type UIHandlerId = string & { [__handlerId]: true }; // FIXME: validate well formed ui field id const codecForUiFieldId = codecForString as () => Codec<UIHandlerId>; -const codecForUIFormFieldBaseConfigTemplate = < - T extends UIFormFieldBaseConfig, +const codecForUIFormFieldBaseDescriptionTemplate = < + T extends UIFieldBaseDescription, >() => buildCodecForObject<T>() - .property("id", codecForUiFieldId()) .property("addonAfterId", codecOptional(codecForString())) .property("addonBeforeId", codecOptional(codecForString())) - .property("converterId", codecOptional(codecForString())) - .property("disabled", codecOptional(codecForBoolean())) .property("hidden", codecOptional(codecForBoolean())) - .property("required", codecOptional(codecForBoolean())) .property("help", codecOptional(codecForString())) .property("label", codecForString()) .property("name", codecForString()) - .property("placeholder", codecOptional(codecForString())) .property("tooltip", codecOptional(codecForString())); +const codecForUIFormFieldBaseConfigTemplate = < + T extends UIFormFieldBaseConfig, +>() => + codecForUIFormFieldBaseDescriptionTemplate<T>() + .property("id", codecForUiFieldId()) + .property("converterId", codecOptional(codecForString())) + .property("disabled", codecOptional(codecForBoolean())) + .property("required", codecOptional(codecForBoolean())) + .property("placeholder", codecOptional(codecForString())); const codecForUIFormFieldBaseConfig = (): Codec<UIFormFieldBaseConfig> => codecForUIFormFieldBaseConfigTemplate().build("UIFieldToggleProperties"); @@ -370,7 +374,9 @@ const codecForUiFormFieldFile = (): Codec<UIFormFieldConfigFile> => const codecForUIFormFieldWithFieldsConfig = (): Codec< UIFormFieldConfigGroup["properties"] > => - codecForUIFormFieldBaseConfigTemplate<UIFormFieldConfigGroup["properties"]>() + codecForUIFormFieldBaseDescriptionTemplate< + UIFormFieldConfigGroup["properties"] + >() .property("fields", codecForList(codecForUiFormField())) .build("UIFormFieldConfigGroup.properties"); |