From 8224223918a19ccc57fb4a640c04c0f1a760c520 Mon Sep 17 00:00:00 2001 From: Mario Subotic Date: Tue, 27 Apr 2021 14:10:48 +0800 Subject: [PATCH 1/3] feat(dynamic-form): adds an optional wrapping element for the form item you can now wrap an element with the its label and decsription in a containing element to help with the structure and styling of the form BREAKING CHANGE: additonalProps which used to me mapped to the form element are now mapped to the wrapping element to keep the same API as the sections. To map additional props to the form element use the formElementAdditionalProps attribute instead. --- lib/src/hooks/useDynamicForm.tsx | 40 +++++++++++++++++++++++--------- lib/src/index.json | 16 ++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/src/hooks/useDynamicForm.tsx b/lib/src/hooks/useDynamicForm.tsx index acbf0e677..fa28c7818 100644 --- a/lib/src/hooks/useDynamicForm.tsx +++ b/lib/src/hooks/useDynamicForm.tsx @@ -27,6 +27,10 @@ export interface DynamicFormItem { valueType?: "string" | "number"; rulerKey?: string; condition?: DynamicFormInternalStateValue; + formElementAdditionalProps?: { + [k: string]: any; + }; + wrappingElement?: "div" | "section" | "none"; additionalProps?: { [k: string]: any; }; @@ -343,7 +347,7 @@ const DynamicFormItemComponent: React.FC<{ onChange: props.onChange, }; - const { additionalProps = {} }: DynamicFormItem = props.item; + const { formElementAdditionalProps = {} }: DynamicFormItem = props.item; let formItem: ReactNode; @@ -355,18 +359,22 @@ const DynamicFormItemComponent: React.FC<{ switch (controlType) { case "Textarea": { + const { value = "", ...rest } = commonProps; + formItem = ( <> -