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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ should change the heading of the (upcoming) version to include a major version b

- Fixed form data propagation with `patternProperties` [#4617](https://github.com/rjsf-team/react-jsonschema-form/pull/4617)

## @rjsf/chakra-ui

- Added `getChakra` to package exports
- Restored the `ui:options` customization

# 6.0.0-beta.7

## @rjsf/core
Expand Down
1 change: 0 additions & 1 deletion packages/chakra-ui/src/AddButton/AddButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Button } from '@chakra-ui/react';
import { PlusIcon } from 'lucide-react';

export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
uiSchema,
registry,
...props
}: IconButtonProps<T, S, F>) {
Expand Down
13 changes: 8 additions & 5 deletions packages/chakra-ui/src/AltDateWidget/AltDateWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MouseEvent, useEffect, useState } from 'react';
import { Box, Button, FieldsetRoot } from '@chakra-ui/react';
import {
ariaDescribedByIds,
dateRangeOptions,
DateElementFormat,
DateObject,
dateRangeOptions,
FormContextType,
getDateElementProps,
parseDateString,
Expand All @@ -13,7 +13,8 @@ import {
TranslatableString,
WidgetProps,
} from '@rjsf/utils';
import { Box, Button } from '@chakra-ui/react';
import { MouseEvent, useEffect, useState } from 'react';
import { getChakra } from '../utils';

function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
props: WidgetProps<T, S, F>,
Expand Down Expand Up @@ -85,8 +86,10 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
onChange(undefined);
};

const chakraProps = getChakra({ uiSchema: props.uiSchema });

return (
<Box>
<FieldsetRoot {...(chakraProps as any)}>
<Box display='flex' flexWrap='wrap' alignItems='center'>
{getDateElementProps(
state,
Expand Down Expand Up @@ -127,7 +130,7 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
</Button>
)}
</Box>
</Box>
</FieldsetRoot>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@rjsf/utils';

import { Field } from '../components/ui/field';
import { getChakra } from '../utils';

export default function BaseInputTemplate<
T = any,
Expand All @@ -36,6 +37,7 @@ export default function BaseInputTemplate<
autofocus,
placeholder,
disabled,
uiSchema,
} = props;
const inputProps = getInputProps<T, S, F>(schema, type, options);

Expand All @@ -44,6 +46,8 @@ export default function BaseInputTemplate<
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);

const chakraProps = getChakra({ uiSchema });

return (
<Field
mb={1}
Expand All @@ -52,6 +56,7 @@ export default function BaseInputTemplate<
readOnly={readonly}
invalid={rawErrors && rawErrors.length > 0}
label={labelValue(label, hideLabel || !label)}
{...chakraProps}
>
<Input
id={id}
Expand Down
5 changes: 4 additions & 1 deletion packages/chakra-ui/src/CheckboxWidget/CheckboxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

import { Field } from '../components/ui/field';
import { Checkbox } from '../components/ui/checkbox';
import { getChakra } from '../utils';

export default function CheckboxWidget<
T = any,
Expand Down Expand Up @@ -50,8 +51,10 @@ export default function CheckboxWidget<
const _onBlur = ({ target }: FocusEvent<HTMLInputElement | any>) => onBlur(id, target && target.value);
const _onFocus = ({ target }: FocusEvent<HTMLInputElement | any>) => onFocus(id, target && target.value);

const chakraProps = getChakra({ uiSchema });

return (
<Field mb={1} required={required}>
<Field mb={1} required={required} {...chakraProps}>
{!hideLabel && description && (
<DescriptionFieldTemplate
id={descriptionId<T>(id)}
Expand Down
11 changes: 10 additions & 1 deletion packages/chakra-ui/src/CheckboxesWidget/CheckboxesWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { FocusEvent } from 'react';

import { Checkbox } from '../components/ui/checkbox';
import { getChakra } from '../utils';

export default function CheckboxesWidget<
T = any,
Expand All @@ -32,6 +33,7 @@ export default function CheckboxesWidget<
label,
hideLabel,
rawErrors = [],
uiSchema,
} = props;
const { enumOptions, enumDisabled, emptyValue } = options;

Expand All @@ -43,8 +45,15 @@ export default function CheckboxesWidget<
const row = options ? options.inline : false;
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, true) as string[];

const chakraProps = getChakra({ uiSchema });

return (
<FieldsetRoot mb={1} disabled={disabled || readonly} invalid={rawErrors && rawErrors.length > 0}>
<FieldsetRoot
mb={1}
disabled={disabled || readonly}
invalid={rawErrors && rawErrors.length > 0}
{...(chakraProps as any)}
>
<CheckboxGroup
onValueChange={(option) => onChange(enumOptionsValueForIndex<S>(option, enumOptions, emptyValue))}
value={selectedIndexes}
Expand Down
5 changes: 5 additions & 0 deletions packages/chakra-ui/src/RadioWidget/RadioWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

import { Field } from '../components/ui/field';
import { Radio, RadioGroup } from '../components/ui/radio';
import { getChakra } from '../utils';

export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
id,
Expand All @@ -27,6 +28,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
onChange,
onBlur,
onFocus,
uiSchema,
}: WidgetProps<T, S, F>) {
const { enumOptions, enumDisabled, emptyValue } = options;

Expand All @@ -40,13 +42,16 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
const row = options ? options.inline : false;
const selectedIndex = (enumOptionsIndexForValue<S>(value, enumOptions) as string) ?? null;

const chakraProps = getChakra({ uiSchema });

return (
<Field
mb={1}
disabled={disabled || readonly}
required={required}
readOnly={readonly}
label={labelValue(label, hideLabel || !label)}
{...chakraProps}
>
<RadioGroup
onChange={_onChange}
Expand Down
6 changes: 5 additions & 1 deletion packages/chakra-ui/src/RangeWidget/RangeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {

import { Field } from '../components/ui/field';
import { Slider } from '../components/ui/slider';
import { getChakra } from '../utils';

export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
value,
Expand All @@ -25,14 +26,17 @@ export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSc
label,
hideLabel,
id,
uiSchema,
}: WidgetProps<T, S, F>) {
const _onChange = ({ value }: SliderValueChangeDetails) =>
onChange(value === undefined ? options.emptyValue : value[0]);
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);

const chakraProps = getChakra({ uiSchema });

return (
<Field mb={1} label={labelValue(label, hideLabel || !label)}>
<Field mb={1} label={labelValue(label, hideLabel || !label)} {...chakraProps}>
<Slider
{...rangeSpec<S>(schema)}
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { OptionsOrGroups } from 'chakra-react-select';
import { createListCollection, NativeSelect as ChakraSelect } from '@chakra-ui/react';

import { Field } from '../components/ui/field';
import { getChakra } from '../utils';

/**
* NativeSelectWidget is a React component that renders a native select input.
Expand Down Expand Up @@ -47,6 +48,7 @@ export default function NativeSelectWidget<
onFocus,
rawErrors = [],
schema,
uiSchema,
} = props;
const { enumOptions, enumDisabled, emptyValue } = options;

Expand Down Expand Up @@ -102,6 +104,8 @@ export default function NativeSelectWidget<
items: displayEnumOptions.filter((item) => item.value),
});

const chakraProps = getChakra({ uiSchema });

return (
<Field
mb={1}
Expand All @@ -110,6 +114,7 @@ export default function NativeSelectWidget<
readOnly={readonly}
invalid={rawErrors && rawErrors.length > 0}
label={labelValue(label, hideLabel || !label)}
{...chakraProps}
>
<ChakraSelect.Root>
<ChakraSelect.Field
Expand Down
4 changes: 4 additions & 0 deletions packages/chakra-ui/src/SelectWidget/SelectWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createListCollection, SelectValueChangeDetails, Select as ChakraSelect

import { Field } from '../components/ui/field';
import { SelectRoot, SelectTrigger, SelectValueText } from '../components/ui/select';
import { getChakra } from '../utils';

export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
props: WidgetProps<T, S, F>,
Expand All @@ -37,6 +38,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
onFocus,
rawErrors = [],
schema,
uiSchema,
} = props;
const { enumOptions, enumDisabled, emptyValue } = options;

Expand Down Expand Up @@ -114,6 +116,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
});

const containerRef = useRef(null);
const chakraProps = getChakra({ uiSchema });

return (
<Field
Expand All @@ -125,6 +128,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
invalid={rawErrors && rawErrors.length > 0}
label={labelValue(label, hideLabel || !label)}
position='relative'
{...chakraProps}
>
<SelectRoot
collection={selectOptions}
Expand Down
5 changes: 5 additions & 0 deletions packages/chakra-ui/src/TextareaWidget/TextareaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@rjsf/utils';

import { Field } from '../components/ui/field';
import { getChakra } from '../utils';

export default function TextareaWidget<
T = any,
Expand All @@ -30,12 +31,15 @@ export default function TextareaWidget<
options,
required,
rawErrors,
uiSchema,
}: WidgetProps<T, S, F>) {
const _onChange = ({ target: { value } }: ChangeEvent<HTMLTextAreaElement>) =>
onChange(value === '' ? options.emptyValue : value);
const _onBlur = ({ target }: FocusEvent<HTMLTextAreaElement>) => onBlur(id, target && target.value);
const _onFocus = ({ target }: FocusEvent<HTMLTextAreaElement>) => onFocus(id, target && target.value);

const chakraProps = getChakra({ uiSchema });

return (
<Field
mb={1}
Expand All @@ -44,6 +48,7 @@ export default function TextareaWidget<
readOnly={readonly}
invalid={rawErrors && rawErrors.length > 0}
label={labelValue(label, hideLabel || !label)}
{...chakraProps}
>
<Textarea
id={id}
Expand Down
4 changes: 4 additions & 0 deletions packages/chakra-ui/src/UpDownWidget/UpDownWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NumberInputValueChangeDetails } from '@chakra-ui/react';

import { Field } from '../components/ui/field';
import { NumberInputRoot } from '../components/ui/number-input';
import { getChakra } from '../utils';

export default function UpDownWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
props: WidgetProps<T, S, F>,
Expand All @@ -22,6 +23,8 @@ export default function UpDownWidget<T = any, S extends StrictRJSFSchema = RJSFS
const _onBlur = ({ target }: FocusEvent<HTMLInputElement | any>) => onBlur(id, target && target.value);
const _onFocus = ({ target }: FocusEvent<HTMLInputElement | any>) => onFocus(id, target && target.value);

const chakraProps = getChakra({ uiSchema: props.uiSchema });

return (
<Field
mb={1}
Expand All @@ -30,6 +33,7 @@ export default function UpDownWidget<T = any, S extends StrictRJSFSchema = RJSFS
readOnly={readonly}
invalid={rawErrors && rawErrors.length > 0}
label={labelValue(label, hideLabel || !label)}
{...chakraProps}
>
<NumberInputRoot
value={value}
Expand Down
2 changes: 2 additions & 0 deletions packages/chakra-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export { __createChakraFrameProvider } from './ChakraFrameProvider';

export type { ChakraUiSchema as UiSchema } from './utils';

export { getChakra } from './utils';

export default Form;