Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/chakra-ui

- Added `MultiSchemaFieldTemplate`
- Improve visual styling of error validation boxes
- Update `chakra-ui/react` package to `^3.19.1`

## @rjsf/core

Expand Down
1,196 changes: 560 additions & 636 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/chakra-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@
],
"license": "Apache-2.0",
"devDependencies": {
"@chakra-ui/cli": "^3.16.1",
"@chakra-ui/react": "^3.16.1",
"@chakra-ui/cli": "^3.19.1",
"@chakra-ui/react": "^3.19.1",
"@emotion/eslint-plugin": "^11.12.0",
"@emotion/jest": "^11.13.0",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@rjsf/core": "^6.0.0-beta.10",
"@rjsf/snapshot-tests": "^6.0.0-beta.10",
"@rjsf/utils": "^6.0.0-beta.10",
Expand Down
20 changes: 4 additions & 16 deletions packages/chakra-ui/src/ErrorList/ErrorList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
import { ListIndicator, ListItem, ListRoot } from '@chakra-ui/react';
import { TriangleAlert } from 'lucide-react';
import { ListItem, ListRoot } from '@chakra-ui/react';

import { Alert } from '../components/ui/alert';

Expand All @@ -10,21 +9,10 @@ export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSche
}: ErrorListProps<T, S, F>) {
const { translateString } = registry;
return (
<Alert
flexDirection='column'
alignItems='flex-start'
gap={3}
status='error'
title={translateString(TranslatableString.ErrorsLabel)}
>
<ListRoot>
<Alert status='error' title={translateString(TranslatableString.ErrorsLabel)} mb={3}>
<ListRoot listStylePosition='inside'>
{errors.map((error, i) => (
<ListItem key={i}>
<ListIndicator asChild color='red.500'>
<TriangleAlert />
</ListIndicator>
{error.stack}
</ListItem>
<ListItem key={i}>{error.stack}</ListItem>
))}
</ListRoot>
</Alert>
Expand Down
20 changes: 8 additions & 12 deletions packages/chakra-ui/src/FieldErrorTemplate/FieldErrorTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
import { ListItem, ListRoot, Text } from '@chakra-ui/react';
import { Fieldset } from '@chakra-ui/react';

/** The `FieldErrorTemplate` component renders the errors local to the particular field
*
Expand All @@ -16,15 +16,11 @@ export default function FieldErrorTemplate<
}
const id = errorId<T>(idSchema);

return (
<ListRoot>
{errors.map((error, i: number) => {
return (
<ListItem key={i}>
<Text id={id}>{error}</Text>
</ListItem>
);
})}
</ListRoot>
);
return errors.map((error, i: number) => {
return (
<Fieldset.ErrorText mt={0} key={i} id={id}>
{error}
</Fieldset.ErrorText>
);
});
}
2 changes: 1 addition & 1 deletion packages/chakra-ui/src/FieldTemplate/FieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function FieldTemplate<
{displayLabel && rawDescription ? <Fieldset.Legend mt={2}>{description}</Fieldset.Legend> : null}
{help}
<Fieldset.Content>{children}</Fieldset.Content>
{errors && <Fieldset.ErrorText>{errors}</Fieldset.ErrorText>}
{errors}
</Fieldset.Root>
</WrapIfAdditionalTemplate>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Box, Card } from '@chakra-ui/react';
import { FormContextType, MultiSchemaFieldTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';

export default function MultiSchemaFieldTemplate<
Expand All @@ -8,9 +9,11 @@ export default function MultiSchemaFieldTemplate<
const { optionSchemaField, selector } = props;

return (
<div>
<div>{selector}</div>
{optionSchemaField}
</div>
<Card.Root mb={2}>
<Card.Body pb={2}>
<Box mb={4}>{selector}</Box>
{optionSchemaField}
</Card.Body>
</Card.Root>
);
}
44 changes: 23 additions & 21 deletions packages/chakra-ui/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,29 @@ export default function ObjectFieldTemplate<
registry={registry}
/>
)}
<Grid gap={description ? 2 : 6} mb={4}>
{properties.map((element, index) =>
element.hidden ? (
element.content
) : (
<GridItem key={`${idSchema.$id}-${element.name}-${index}`}>{element.content}</GridItem>
),
)}
{canExpand<T, S, F>(schema, uiSchema, formData) && (
<GridItem justifySelf='flex-end'>
<AddButton
id={buttonId<T>(idSchema, 'add')}
className='rjsf-object-property-expand'
onClick={onAddClick(schema)}
disabled={disabled || readonly}
uiSchema={uiSchema}
registry={registry}
/>
</GridItem>
)}
</Grid>
{properties.length > 0 && (
<Grid gap={description ? 2 : 6} mb={4}>
{properties.map((element, index) =>
element.hidden ? (
element.content
) : (
<GridItem key={`${idSchema.$id}-${element.name}-${index}`}>{element.content}</GridItem>
),
)}
{canExpand<T, S, F>(schema, uiSchema, formData) && (
<GridItem justifySelf='flex-end'>
<AddButton
id={buttonId<T>(idSchema, 'add')}
className='rjsf-object-property-expand'
onClick={onAddClick(schema)}
disabled={disabled || readonly}
uiSchema={uiSchema}
registry={registry}
/>
</GridItem>
)}
</Grid>
)}
</>
);
}
8 changes: 3 additions & 5 deletions packages/chakra-ui/src/components/ui/alert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, ReactElement, ReactNode } from 'react';
import { forwardRef, ReactNode } from 'react';
import { Alert as ChakraAlert } from '@chakra-ui/react';

import { CloseButton } from './close-button';
Expand All @@ -10,7 +10,6 @@ import { CloseButton } from './close-button';
* @param {ReactNode} [props.startElement] - The element to display at the start of the alert.
* @param {ReactNode} [props.endElement] - The element to display at the end of the alert.
* @param {ReactNode} [props.title] - The title of the alert.
* @param {ReactElement} [props.icon] - The icon to display in the alert.
* @param {boolean} [props.closable] - Whether to show the close button.
* @param {function} [props.onClose] - The function to call when the close button is clicked.
*
Expand All @@ -20,16 +19,15 @@ export interface AlertProps extends Omit<ChakraAlert.RootProps, 'title'> {
startElement?: ReactNode;
endElement?: ReactNode;
title?: ReactNode;
icon?: ReactElement;
closable?: boolean;
onClose?: () => void;
}

export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(props, ref) {
const { title, children, icon, closable, onClose, startElement, endElement, ...rest } = props;
const { title, children, closable, onClose, startElement, endElement, ...rest } = props;
return (
<ChakraAlert.Root ref={ref} {...rest}>
{startElement || <ChakraAlert.Indicator>{icon}</ChakraAlert.Indicator>}
{startElement || <ChakraAlert.Indicator />}
{children ? (
<ChakraAlert.Content>
<ChakraAlert.Title>{title}</ChakraAlert.Title>
Expand Down
Loading