Skip to content

Commit ffe154b

Browse files
Added new templates, utility function and refactored ArrayFieldItemTemplate (#4489)
* Added new templates, utility function and refactored ArrayFieldItemTemplate - In `@rjsf/utils`: - Refactored the `ArrayFieldItemTemplateType` to extract out all the button related props to `ArrayFieldItemButtonsTemplateType`, adding `buttonsProps: ArrayFieldItemButtonsTemplateType` as a new prop - Also created a deprecated alias type `ArrayFieldTemplateItemType` that points to `ArrayFieldItemTemplateType` for backwards compatibility - Added new `GridTemplateProps` type - Added two the following new, required props to `TemplatesType`: - `ArrayFieldItemButtonsTemplate: ComponentType<ArrayFieldItemButtonsTemplateType<T, S, F>>;` - `GridTemplate: ComponentType<GridTemplateProps>` - Added a new `buttonId<T>(id: IdSchema<T> | string, btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove')` used to generate consistent ids for RJSF buttons - In `@rjsf/core`: - Updated `ArrayField` to provide the `buttonsProps` to the `ArrayFieldItemTemplateType` - Added `ArrayFieldItemButtonsTemplate` component as a refactor of all the common buttons code from all the `ArrayFieldItemTemplate` implementations, adding a unique id using the `buttonId()` function - Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate` - Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes - All other themes: - Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate` - Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes - Updated the playground to remove `fluent-ui` theme - Updated the `custom-templates.md` documentation for the changes to the `ArrayFieldTemplateItem` and add the two new templates - Updated the `utility-functions.md` documentation to add the `buttonId()` function - Added the `v6.x upgrade guide.md` documentation - Updated `CHANGELOG_V6.md` accordingly * - Updated changelog * Apply suggestions from code review - Self feedback * Update packages/docs/docs/advanced-customization/custom-templates.md - Self review
1 parent c6eb0a8 commit ffe154b

File tree

57 files changed

+2297
-3001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2297
-3001
lines changed

CHANGELOG_v6.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,68 @@ should change the heading of the (upcoming) version to include a major version b
1717
-->
1818
# 6.0.0-beta.1
1919

20+
## @rjsf/antd
21+
22+
- BREAKING CHANGE: Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate`
23+
- Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes
24+
25+
## @rjsf/chakra-ui
26+
27+
- BREAKING CHANGE: Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate`
28+
- Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes
29+
30+
## @rjsf/core
31+
32+
- BREAKING CHANGE: Updated `ArrayField` to provide the `buttonsProps` to the `ArrayFieldItemTemplateType`
33+
- Added `ArrayFieldItemButtonsTemplate` component as a refactor of all the common buttons code from all the `ArrayFieldItemTemplate` implementations, adding a unique id using the `buttonId()` function
34+
- Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate`
35+
- Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes
36+
37+
## @rjsf/fluent-ui
38+
39+
- BREAKING CHANGE: Deleted this theme in favor of `fluentui-rc`
40+
41+
## @rjsf/fluentui-rc
42+
43+
- BREAKING CHANGE: Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate`
44+
- Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes
45+
46+
## @rjsf/mui
47+
48+
- BREAKING CHANGE: Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate`
49+
- Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes
50+
51+
## @rjsf/semantic-ui
52+
53+
- BREAKING CHANGE: Refactored `ArrayFieldItemTemplate` to use the new `ArrayFieldItemButtonsTemplate`
54+
- Updated the `ArrayFieldTemplate`, `ObjectFieldTemplate`, and `WrapIfAdditionalTemplate` to a unique id using the `buttonId()` function and adding consistent marker classes
55+
56+
## @rjsf/utils
57+
58+
- BREAKING CHANGE: Refactored the `ArrayFieldItemTemplateType` to extract out all the button related props to `ArrayFieldItemButtonsTemplateType`, adding `buttonsProps: ArrayFieldItemButtonsTemplateType` as a new prop
59+
- Also created a deprecated alias type `ArrayFieldTemplateItemType` that points to `ArrayFieldItemTemplateType` for backwards compatibility
60+
- Added new `GridTemplateProps` type
61+
- BREAKING CHANGE: Added two the following new, required props to `TemplatesType`:
62+
- `ArrayFieldItemButtonsTemplate: ComponentType<ArrayFieldItemButtonsTemplateType<T, S, F>>;`
63+
- `GridTemplate: ComponentType<GridTemplateProps>`
64+
- Added a new `buttonId<T>(id: IdSchema<T> | string, btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove')` used to generate consistent ids for RJSF buttons
65+
66+
## Dev / docs / playground
67+
68+
- Updated the playground to remove `fluent-ui` theme
69+
- Updated the `custom-templates.md` documentation for the changes to the `ArrayFieldTemplateItem` and add the two new templates
70+
- Updated the `utility-functions.md` documentation to add the `buttonId()` function
71+
- Added the `v6.x upgrade guide.md` documentation
72+
73+
# 6.0.0-alpha.0
74+
2075
## @rjsf/bootstrap-4
2176

22-
- Package has been replaced with `@rjsf/react-bootstrap`. `react-boostrap` v1 / Bootstrap 4 are no longer supported in RJSF v6.
77+
- BREAKING CHANGE: Package has been replaced with `@rjsf/react-bootstrap`. `react-boostrap` v1 / Bootstrap 4 are no longer supported in RJSF v6.
2378

2479
## @rjsf/material-ui
2580

26-
- Removed `@rjsf/material-ui` package. Material UI v4 (`@material-ui/core`) has been deprecated since September 2021. To use Material UI v5 (`@mui/core`) with RJSF, please use the `@rjsf/mui` theme instead.
81+
- BREAKING CHANGE: Removed `@rjsf/material-ui` package. Material UI v4 (`@material-ui/core`) has been deprecated since September 2021. To use Material UI v5 (`@mui/core`) with RJSF, please use the `@rjsf/mui` theme instead.
2782

2883
## @rjsf/react-bootstrap
2984

@@ -33,3 +88,7 @@ should change the heading of the (upcoming) version to include a major version b
3388
- IconButton: Remove deprecated `block` prop
3489
- RangeWidget: Use `FormRange` component
3590
- SelectWidget: Use new FormSelect component, remove `bsPrefix` prop to achieve correct styling
91+
92+
## Dev / docs / playground
93+
94+
- Updated the playground to remove `material-ui-4` theme and replace the `bootstrap-4` theme with `react-bootstrap`

packages/antd/src/templates/ArrayFieldItemTemplate/index.tsx

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Button, Col, Row } from 'antd';
2-
import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2+
import {
3+
ArrayFieldTemplateItemType,
4+
FormContextType,
5+
getUiOptions,
6+
getTemplate,
7+
RJSFSchema,
8+
StrictRJSFSchema,
9+
} from '@rjsf/utils';
310

411
const BTN_GRP_STYLE = {
512
width: '100%',
@@ -11,30 +18,20 @@ const BTN_STYLE = {
1118

1219
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
1320
*
14-
* @param props - The `ArrayFieldTemplateItemType` props for the component
21+
* @param props - The `ArrayFieldItemTemplateType` props for the component
1522
*/
1623
export default function ArrayFieldItemTemplate<
1724
T = any,
1825
S extends StrictRJSFSchema = RJSFSchema,
1926
F extends FormContextType = any
2027
>(props: ArrayFieldTemplateItemType<T, S, F>) {
21-
const {
22-
children,
23-
disabled,
24-
hasCopy,
25-
hasMoveDown,
26-
hasMoveUp,
27-
hasRemove,
28-
hasToolbar,
29-
index,
30-
onCopyIndexClick,
31-
onDropIndexClick,
32-
onReorderClick,
33-
readonly,
28+
const { children, buttonsProps, hasToolbar, index, registry, uiSchema } = props;
29+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
30+
const ArrayFieldItemButtonsTemplate = getTemplate<'ArrayFieldItemButtonsTemplate', T, S, F>(
31+
'ArrayFieldItemButtonsTemplate',
3432
registry,
35-
uiSchema,
36-
} = props;
37-
const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates;
33+
uiOptions
34+
);
3835
const { rowGutter = 24, toolbarAlign = 'top' } = registry.formContext;
3936

4037
return (
@@ -44,42 +41,7 @@ export default function ArrayFieldItemTemplate<
4441
{hasToolbar && (
4542
<Col flex='192px'>
4643
<Button.Group style={BTN_GRP_STYLE}>
47-
{(hasMoveUp || hasMoveDown) && (
48-
<MoveUpButton
49-
disabled={disabled || readonly || !hasMoveUp}
50-
onClick={onReorderClick(index, index - 1)}
51-
style={BTN_STYLE}
52-
uiSchema={uiSchema}
53-
registry={registry}
54-
/>
55-
)}
56-
{(hasMoveUp || hasMoveDown) && (
57-
<MoveDownButton
58-
disabled={disabled || readonly || !hasMoveDown}
59-
onClick={onReorderClick(index, index + 1)}
60-
style={BTN_STYLE}
61-
uiSchema={uiSchema}
62-
registry={registry}
63-
/>
64-
)}
65-
{hasCopy && (
66-
<CopyButton
67-
disabled={disabled || readonly}
68-
onClick={onCopyIndexClick(index)}
69-
style={BTN_STYLE}
70-
uiSchema={uiSchema}
71-
registry={registry}
72-
/>
73-
)}
74-
{hasRemove && (
75-
<RemoveButton
76-
disabled={disabled || readonly}
77-
onClick={onDropIndexClick(index)}
78-
style={BTN_STYLE}
79-
uiSchema={uiSchema}
80-
registry={registry}
81-
/>
82-
)}
44+
<ArrayFieldItemButtonsTemplate {...buttonsProps} style={BTN_STYLE} />
8345
</Button.Group>
8446
</Col>
8547
)}

packages/antd/src/templates/ArrayFieldTemplate/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
GenericObjectType,
88
RJSFSchema,
99
StrictRJSFSchema,
10+
buttonId,
1011
} from '@rjsf/utils';
1112
import classNames from 'classnames';
1213
import { Col, Row, ConfigProvider } from 'antd';
@@ -18,7 +19,7 @@ const DESCRIPTION_COL_STYLE = {
1819

1920
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
2021
*
21-
* @param props - The `ArrayFieldTemplateItemType` props for the component
22+
* @param props - The `ArrayFieldItemTemplateType` props for the component
2223
*/
2324
export default function ArrayFieldTemplate<
2425
T = any,
@@ -109,6 +110,7 @@ export default function ArrayFieldTemplate<
109110
<Row gutter={rowGutter} justify='end'>
110111
<Col flex='192px'>
111112
<AddButton
113+
id={buttonId<T>(idSchema, 'add')}
112114
className='array-item-add'
113115
disabled={disabled || readonly}
114116
onClick={onAddClick}

packages/antd/src/templates/ObjectFieldTemplate/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getTemplate,
1616
getUiOptions,
1717
titleId,
18+
buttonId,
1819
} from '@rjsf/utils';
1920
import { Col, Row, ConfigProvider } from 'antd';
2021
import { useContext } from 'react';
@@ -153,6 +154,7 @@ export default function ObjectFieldTemplate<
153154
<Row gutter={rowGutter} justify='end'>
154155
<Col flex='192px'>
155156
<AddButton
157+
id={buttonId<T>(idSchema, 'add')}
156158
className='object-property-expand'
157159
disabled={disabled || readonly}
158160
onClick={onAddClick(schema)}

packages/antd/src/templates/WrapIfAdditionalTemplate/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
StrictRJSFSchema,
99
TranslatableString,
1010
WrapIfAdditionalTemplateProps,
11+
buttonId,
1112
} from '@rjsf/utils';
1213

1314
const VERTICAL_LABEL_COL = { span: 24 };
@@ -108,6 +109,7 @@ export default function WrapIfAdditionalTemplate<
108109
</Col>
109110
<Col flex='192px'>
110111
<RemoveButton
112+
id={buttonId<T>(id, 'remove')}
111113
className='array-item-remove'
112114
disabled={disabled || readonly}
113115
onClick={onDropPropertyClick(label)}

0 commit comments

Comments
 (0)