Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the GridTemplate for all themes #4491

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG_v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ should change the heading of the (upcoming) version to include a major version b

- BREAKING CHANGE: 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
- Implemented the `GridTemplate` component, adding it to the `templates` for the theme

## @rjsf/chakra-ui

- BREAKING CHANGE: 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
- Implemented the `GridTemplate` component, adding it to the `templates` for the theme

## @rjsf/core

- BREAKING CHANGE: 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
- Implemented the `GridTemplate` component, adding it to the `templates` for the theme

## @rjsf/fluent-ui

Expand All @@ -42,16 +45,20 @@ should change the heading of the (upcoming) version to include a major version b

- BREAKING CHANGE: 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
- Implemented the `GridTemplate` component, adding it to the `templates` for the theme

## @rjsf/mui

- BREAKING CHANGE: 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 theme to use `Grid2` instead of the deprecated `Grid`
- Implemented the `GridTemplate` component, adding it to the `templates` for the theme

## @rjsf/semantic-ui

- BREAKING CHANGE: 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
- Implemented the `GridTemplate` component, adding it to the `templates` for the theme

## @rjsf/utils

Expand Down
15 changes: 15 additions & 0 deletions packages/antd/src/templates/GridTemplate/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Col, Row } from 'antd';
import { GridTemplateProps } from '@rjsf/utils';

/** Renders a `GridTemplate` for antd, which is expecting the column sizing information coming in via the
* extra props provided by the caller, which are spread directly on the `Row`/`Col`.
*
* @param props - The GridTemplateProps, including the extra props containing the antd grid positioning details
*/
export default function GridTemplate(props: GridTemplateProps) {
const { children, column, ...rest } = props;
if (column) {
return <Col {...rest}>{children}</Col>;
}
return <Row {...rest}>{children}</Row>;
}
2 changes: 2 additions & 0 deletions packages/antd/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ErrorList from './ErrorList';
import { AddButton, CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from './IconButton';
import FieldErrorTemplate from './FieldErrorTemplate';
import FieldTemplate from './FieldTemplate';
import GridTemplate from './GridTemplate';
import ObjectFieldTemplate from './ObjectFieldTemplate';
import SubmitButton from './SubmitButton';
import TitleField from './TitleField';
Expand All @@ -34,6 +35,7 @@ export function generateTemplates<
ErrorListTemplate: ErrorList,
FieldErrorTemplate,
FieldTemplate,
GridTemplate,
ObjectFieldTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate,
Expand Down
15 changes: 15 additions & 0 deletions packages/chakra-ui/src/GridTemplate/GridTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Grid, GridItem } from '@chakra-ui/react';
import { GridTemplateProps } from '@rjsf/utils';

/** Renders a `GridTemplate` for chakra-ui, which is expecting the column sizing information coming in via the
* extra props provided by the caller, which are spread directly on the `Grid`/`GridItem`.
*
* @param props - The GridTemplateProps, including the extra props containing the chakra-ui grid positioning details
*/
export default function GridTemplate(props: GridTemplateProps) {
const { children, column, ...rest } = props;
if (column) {
return <GridItem {...rest}>{children}</GridItem>;
}
return <Grid {...rest}>{children}</Grid>;
}
2 changes: 2 additions & 0 deletions packages/chakra-ui/src/GridTemplate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './GridTemplate';
export * from './GridTemplate';
2 changes: 2 additions & 0 deletions packages/chakra-ui/src/Templates/Templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconB
import FieldErrorTemplate from '../FieldErrorTemplate';
import FieldHelpTemplate from '../FieldHelpTemplate';
import FieldTemplate from '../FieldTemplate';
import GridTemplate from '../GridTemplate';
import ObjectFieldTemplate from '../ObjectFieldTemplate';
import SubmitButton from '../SubmitButton';
import TitleField from '../TitleField';
Expand Down Expand Up @@ -36,6 +37,7 @@ export function generateTemplates<
FieldErrorTemplate,
FieldHelpTemplate,
FieldTemplate,
GridTemplate,
ObjectFieldTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate,
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/components/templates/GridTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { GridTemplateProps } from '@rjsf/utils';

/** Renders a `GridTemplate` for bootstrap 3, which is expecting the column
* information coming in via the `className` prop.
/** Renders a `GridTemplate` for bootstrap 3, which is expecting the column information coming in via the `className`
* prop. Also spreads all the other props provided by the user directly on the div.
*
* @param props - The GridTemplateProps, including the expected className for
* the bootstrap 3 grid behavior
* @param props - The GridTemplateProps, including the expected className for the bootstrap 3 grid behavior
*/
export default function GridTemplate(props: GridTemplateProps) {
const { children, overrides, column, className, ...rest } = props;
const { children, column, className, ...rest } = props;
const classNames = column ? className : `row ${className}`;
return (
<div className={classNames} {...rest}>
Expand Down
12 changes: 12 additions & 0 deletions packages/fluentui-rc/src/GridTemplate/GridTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Flex } from '@fluentui/react-migration-v0-v9';
import { GridTemplateProps } from '@rjsf/utils';

/** Renders a `GridTemplate` for fluentui-rc, which is expecting the column sizing information coming in via the
* extra props provided by the caller, which are spread directly on the `Flex`.
*
* @param props - The GridTemplateProps, including the extra props containing the fluentui-rc grid positioning details
*/
export default function GridTemplate(props: GridTemplateProps) {
const { children, column, ...rest } = props;
return <Flex {...rest}>{children}</Flex>;
}
2 changes: 2 additions & 0 deletions packages/fluentui-rc/src/GridTemplate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './GridTemplate';
export * from './GridTemplate';
2 changes: 2 additions & 0 deletions packages/fluentui-rc/src/Templates/Templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconB
import FieldErrorTemplate from '../FieldErrorTemplate';
import FieldHelpTemplate from '../FieldHelpTemplate';
import FieldTemplate from '../FieldTemplate';
import GridTemplate from '../GridTemplate';
import ObjectFieldTemplate from '../ObjectFieldTemplate';
import SubmitButton from '../SubmitButton';
import TitleField from '../TitleField';
Expand Down Expand Up @@ -36,6 +37,7 @@ export function generateTemplates<
FieldErrorTemplate,
FieldHelpTemplate,
FieldTemplate,
GridTemplate,
ObjectFieldTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CSSProperties } from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Grid2 from '@mui/material/Grid2';
import Paper from '@mui/material/Paper';
import {
ArrayFieldTemplateItemType,
Expand Down Expand Up @@ -35,19 +35,19 @@ export default function ArrayFieldItemTemplate<
minWidth: 0,
};
return (
<Grid container={true} alignItems='center'>
<Grid item={true} xs style={{ overflow: 'auto' }}>
<Grid2 container={true} alignItems='center'>
<Grid2 size='auto' style={{ overflow: 'auto' }}>
<Box mb={2}>
<Paper elevation={2}>
<Box p={2}>{children}</Box>
</Paper>
</Box>
</Grid>
</Grid2>
{hasToolbar && (
<Grid item={true}>
<Grid2>
<ArrayFieldItemButtonsTemplate {...buttonsProps} style={btnStyle} />
</Grid>
</Grid2>
)}
</Grid>
</Grid2>
);
}
10 changes: 5 additions & 5 deletions packages/mui/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Grid2 from '@mui/material/Grid2';
import Paper from '@mui/material/Paper';
import {
getTemplate,
Expand Down Expand Up @@ -66,8 +66,8 @@ export default function ArrayFieldTemplate<
<ArrayFieldItemTemplate key={key} {...itemProps} />
))}
{canAdd && (
<Grid container justifyContent='flex-end'>
<Grid item={true}>
<Grid2 container justifyContent='flex-end'>
<Grid2>
<Box mt={2}>
<AddButton
id={buttonId<T>(idSchema, 'add')}
Expand All @@ -78,8 +78,8 @@ export default function ArrayFieldTemplate<
registry={registry}
/>
</Box>
</Grid>
</Grid>
</Grid2>
</Grid2>
)}
</Box>
</Paper>
Expand Down
16 changes: 16 additions & 0 deletions packages/mui/src/GridTemplate/GridTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Grid2 from '@mui/material/Grid2';
import { GridTemplateProps } from '@rjsf/utils';

/** Renders a `GridTemplate` for mui, which is expecting the column sizing information coming in via the
* extra props provided by the caller, which are spread directly on the `Grid2`.
*
* @param props - The GridTemplateProps, including the extra props containing the mui grid positioning details
*/
export default function GridTemplate(props: GridTemplateProps) {
const { children, column, ...rest } = props;
return (
<Grid2 container={!column} {...rest}>
{children}
</Grid2>
);
}
2 changes: 2 additions & 0 deletions packages/mui/src/GridTemplate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './GridTemplate';
export * from './GridTemplate';
20 changes: 10 additions & 10 deletions packages/mui/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Grid from '@mui/material/Grid';
import Grid2 from '@mui/material/Grid2';
import {
FormContextType,
ObjectFieldTemplateProps,
Expand Down Expand Up @@ -69,21 +69,21 @@ export default function ObjectFieldTemplate<
registry={registry}
/>
)}
<Grid container={true} spacing={2} style={{ marginTop: '10px' }}>
<Grid2 container={true} spacing={2} style={{ marginTop: '10px' }}>
{properties.map((element, index) =>
// Remove the <Grid> if the inner element is hidden as the <Grid>
// Remove the <Grid2> if the inner element is hidden as the <Grid2>
// itself would otherwise still take up space.
element.hidden ? (
element.content
) : (
<Grid item={true} xs={12} key={index} style={{ marginBottom: '10px' }}>
<Grid2 size={{ xs: 12 }} key={index} style={{ marginBottom: '10px' }}>
{element.content}
</Grid>
</Grid2>
)
)}
{canExpand<T, S, F>(schema, uiSchema, formData) && (
<Grid container justifyContent='flex-end'>
<Grid item={true}>
<Grid2 container justifyContent='flex-end'>
<Grid2>
<AddButton
id={buttonId<T>(idSchema, 'add')}
className='object-property-expand'
Expand All @@ -92,10 +92,10 @@ export default function ObjectFieldTemplate<
uiSchema={uiSchema}
registry={registry}
/>
</Grid>
</Grid>
</Grid2>
</Grid2>
)}
</Grid>
</Grid2>
</>
);
}
2 changes: 2 additions & 0 deletions packages/mui/src/Templates/Templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconB
import FieldErrorTemplate from '../FieldErrorTemplate';
import FieldHelpTemplate from '../FieldHelpTemplate';
import FieldTemplate from '../FieldTemplate';
import GridTemplate from '../GridTemplate';
import ObjectFieldTemplate from '../ObjectFieldTemplate';
import SubmitButton from '../SubmitButton';
import TitleField from '../TitleField';
Expand Down Expand Up @@ -37,6 +38,7 @@ export function generateTemplates<
FieldErrorTemplate,
FieldHelpTemplate,
FieldTemplate,
GridTemplate,
ObjectFieldTemplate,
TitleFieldTemplate: TitleField,
WrapIfAdditionalTemplate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CSSProperties, FocusEvent } from 'react';
import Grid from '@mui/material/Grid';
import Grid2 from '@mui/material/Grid2';
import TextField from '@mui/material/TextField';
import {
ADDITIONAL_PROPERTY_FLAG,
Expand Down Expand Up @@ -59,8 +59,8 @@ export default function WrapIfAdditionalTemplate<
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) => onKeyChange(target && target.value);

return (
<Grid container key={`${id}-key`} alignItems='center' spacing={2} className={classNames} style={style}>
<Grid item xs>
<Grid2 container key={`${id}-key`} alignItems='center' spacing={2} className={classNames} style={style}>
<Grid2 size='auto'>
<TextField
fullWidth={true}
required={required}
Expand All @@ -72,11 +72,9 @@ export default function WrapIfAdditionalTemplate<
onBlur={!readonly ? handleBlur : undefined}
type='text'
/>
</Grid>
<Grid item={true} xs>
{children}
</Grid>
<Grid item={true}>
</Grid2>
<Grid2 size='auto'>{children}</Grid2>
<Grid2>
<RemoveButton
id={buttonId<T>(id, 'remove')}
className='array-item-remove'
Expand All @@ -87,7 +85,7 @@ export default function WrapIfAdditionalTemplate<
uiSchema={uiSchema}
registry={registry}
/>
</Grid>
</Grid>
</Grid2>
</Grid2>
);
}
Loading