Skip to content

Commit 29e3e98

Browse files
authored
[Dynamic Form] Fix for 1788/1794 and add styles property for support customizing styling (#1913)
* fixed #1788 and add styles/className property to support styling customization, should somehow fix #1794 * Update DynamicForm.md as michaelmaillot suggested * fixed typo name problem on dynamicForm/DynamicForm.styles.ts * fixed the typo on dynamicField/DynamicField.styles.ts fixed the subcomponent styles doesn't work in dynamic field issue * Update DynamicForm.md to add more description on styles property * remove the indent in sample code on DynamicForm.md, correct the styling class name * remove all indent on sample code in DynamicForm.md * Update DynamicForm.md to add line break before the sample code
1 parent cc2ef4f commit 29e3e98

File tree

8 files changed

+507
-221
lines changed

8 files changed

+507
-221
lines changed

docs/documentation/docs/controls/DynamicForm.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ The `DynamicForm` can be configured with the following properties:
6969
| customIcons | { [ columnInternalName: string ]: string } | no | Specifies custom icons for the form. The key of this dictionary is the column internal name, the value is the Fluent UI icon name. |
7070
| storeLastActiveTab | boolean | no | When uploading files: Specifies if last active tab will be stored after the Upload panel has been closed. Note: the value of selected tab is stored in the queryString hash. Default - `true` |
7171
| folderPath | string | no | Server relative or library relative folder to create the item in. This option is only available for document libraries and works only when the contentTypeId is specified and has a base type of type Document or Folder. Defaults to the root folder of the library. |
72+
| className | string | no | Set CSS Class. |
73+
| styles | IStyleFunctionOrObject<IDynamicFormStyleProps, [IDynamicFormStyles](#idynamicformstyles-interface)> | no | Styles to apply on control. See the example [here](#how-to-use-styles-property) |
7274

7375
## Validation Error Dialog Properties `IValidationErrorDialogProps`
7476

@@ -77,3 +79,77 @@ The `DynamicForm` can be configured with the following properties:
7779
| showDialogOnValidationError | boolean | no | Specifies if the dialog should be shown on validation error. Default - `false` |
7880
| customTitle | string | no | Specifies a custom title to be shown in the validation dialog. Default - empty |
7981
| customMessage | string | no | Specifies a custom message to be shown in the validation dialog. Default - empty |
82+
83+
## IDynamicFormStyles interface
84+
85+
| Property | Type | Description |
86+
| ---- | ---- | ---- |
87+
| root | IStyle | styles for the root element |
88+
| sectionTitle | IStyle | styles for the **section title** when your list has enabled [list formatting on form layout](https://learn.microsoft.com/sharepoint/dev/declarative-customization/list-form-configuration#configure-custom-body-with-one-or-more-sections) |
89+
| sectionFormFields | IStyle | styles for the **section container** when your list has enabled list formatting on form layout |
90+
| sectionFormField | IStyle | styles for the **section field** when your list has enabled list formatting on form layout |
91+
| sectionLine | IStyle | styles for the **section line break** when your list has enabled list formatting on form layout |
92+
| header | IStyle | styles for the **header** when your list has enabled list formatting on [custom header](https://learn.microsoft.com/sharepoint/dev/declarative-customization/list-form-configuration#configure-custom-header) |
93+
| footer | IStyle | styles for the **footer** when your list has enabled list formatting on [custom footer](https://learn.microsoft.com/sharepoint/dev/declarative-customization/list-form-configuration#configure-custom-footer) |
94+
| validationErrorDialog | IStyle | styles for the **content** element in Validation Error Dialog |
95+
| actions | IStyle | styles for the **actions** element in Validation Error Dialog |
96+
| actionsRight | IStyle | styles for the **button container** of Validation Error Dialog |
97+
| action | IStyle | styles for the **close button** in Validation Error Dialog |
98+
| buttons | IStyle | styles for the buttons (save button/cancel button) |
99+
| subComponentStyles | {fieldStyles: [IDynamicFieldStyles](#idynamicfieldstyles-interface)} | styles of dynamic field control|
100+
101+
## IDynamicFieldStyles interface
102+
103+
| Property | Type | Description |
104+
| ---- | ---- | ---- |
105+
| fieldEditor | IStyle | styles for root element |
106+
| fieldContainer | IStyle | styles for container element under root |
107+
| titleContainer | IStyle | styles for the title container element of the field |
108+
| fieldIcon | IStyle | styles for the icon element of the field |
109+
| fieldDisplay | IStyle | styles for sub field control.e.g. TextField,ListItemPicker |
110+
| fieldDisplayNoPadding | IStyle | styles for "Url" field control |
111+
| fieldDescription | IStyle | styles for field description element |
112+
| fieldRequired | IStyle | styles for required element |
113+
| fieldLabel | IStyle | styles for field label element , it will append fieldRequired style if the field is required |
114+
| labelContainer | IStyle | styles for field label container element |
115+
| pickersContainer | IStyle | styles for those picker sub control,e.g. DatePicker,TaxonomyPicker |
116+
| errormessage | IStyle | styles for errormessage element |
117+
| richText | IStyle | styles for richText sub control |
118+
| thumbnailFieldButtons | IStyle | styles for button when field type is 'Thumbnail' |
119+
| selectedFileContainer | IStyle | styles for File Selection Control |
120+
121+
## How to use styles property
122+
123+
Property styles of Dynamic Form gives you a set of properties which you can use to modify styles.
124+
In this example it shows 4 columns (by default it shows 3 columns per row) in one row if screen size is bigger than 1280px (it requires enable list formatting first)
125+
and make the error message font size a bit large.
126+
127+
```TypeScript
128+
styles={{
129+
sectionFormField: {
130+
selectors: {
131+
':has(div)': {
132+
[`@media (min-width: 1280px)`]: {
133+
"min-width": '21%',
134+
"max-width": '21%' //force show 4 columns per row in big screen size when enabled list custom formatting
135+
}
136+
},
137+
},
138+
},
139+
140+
subComponentStyles: {
141+
fieldStyles: {
142+
errormessage: {
143+
"font-size": "18px" //overwrite the error message font size in Dynamic Field for Lookup/Note/Date fields (The error message element is generated directly in Dynamic Field control)
144+
},
145+
fieldDisplay: {
146+
selectors: {
147+
'.ms-TextField-errorMessage': {
148+
"font-size": "18px !important" //overwrite the error message font size in Dynamic Field for TextField (error message element is wrapped in Fluent UI TextField control, we cannot modify it directly,we have to use 'selectors' to change it)
149+
}
150+
}
151+
}
152+
}
153+
}
154+
}}
155+
```

src/controls/dynamicForm/DynamicForm.module.scss

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)