@rjsf/chakra-ui 5.11.2 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chakra-ui.esm.js +845 -946
- package/dist/chakra-ui.esm.js.map +7 -1
- package/dist/chakra-ui.umd.js +1339 -0
- package/dist/index.js +1500 -5
- package/dist/index.js.map +7 -0
- package/lib/AddButton/AddButton.d.ts +3 -0
- package/lib/AddButton/AddButton.js +11 -0
- package/lib/AddButton/AddButton.js.map +1 -0
- package/lib/AddButton/index.d.ts +2 -0
- package/lib/AddButton/index.js +3 -0
- package/lib/AddButton/index.js.map +1 -0
- package/lib/AltDateTimeWidget/AltDateTimeWidget.d.ts +15 -0
- package/lib/AltDateTimeWidget/AltDateTimeWidget.js +9 -0
- package/lib/AltDateTimeWidget/AltDateTimeWidget.js.map +1 -0
- package/lib/AltDateTimeWidget/index.d.ts +2 -0
- package/lib/AltDateTimeWidget/index.js +3 -0
- package/lib/AltDateTimeWidget/index.js.map +1 -0
- package/lib/AltDateWidget/AltDateWidget.d.ts +15 -0
- package/lib/AltDateWidget/AltDateWidget.js +80 -0
- package/lib/AltDateWidget/AltDateWidget.js.map +1 -0
- package/lib/AltDateWidget/index.d.ts +2 -0
- package/lib/AltDateWidget/index.js +3 -0
- package/lib/AltDateWidget/index.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +3 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +13 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldItemTemplate/index.js +3 -0
- package/lib/ArrayFieldItemTemplate/index.js.map +1 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +3 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +19 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -0
- package/lib/ArrayFieldTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldTemplate/index.js +3 -0
- package/lib/ArrayFieldTemplate/index.js.map +1 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.d.ts +3 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js +18 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -0
- package/lib/BaseInputTemplate/index.d.ts +2 -0
- package/lib/BaseInputTemplate/index.js +3 -0
- package/lib/BaseInputTemplate/index.js.map +1 -0
- package/lib/ChakraFrameProvider.d.ts +2 -0
- package/lib/ChakraFrameProvider.js +28 -0
- package/lib/ChakraFrameProvider.js.map +1 -0
- package/lib/CheckboxWidget/CheckboxWidget.d.ts +3 -0
- package/lib/CheckboxWidget/CheckboxWidget.js +19 -0
- package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -0
- package/lib/CheckboxWidget/index.d.ts +2 -0
- package/lib/CheckboxWidget/index.js +3 -0
- package/lib/CheckboxWidget/index.js.map +1 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.d.ts +3 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js +21 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -0
- package/lib/CheckboxesWidget/index.d.ts +2 -0
- package/lib/CheckboxesWidget/index.js +3 -0
- package/lib/CheckboxesWidget/index.js.map +1 -0
- package/lib/CssReset.d.ts +24 -0
- package/lib/CssReset.js +266 -0
- package/lib/CssReset.js.map +1 -0
- package/lib/DescriptionField/DescriptionField.d.ts +3 -0
- package/lib/DescriptionField/DescriptionField.js +12 -0
- package/lib/DescriptionField/DescriptionField.js.map +1 -0
- package/lib/DescriptionField/index.d.ts +2 -0
- package/lib/DescriptionField/index.js +3 -0
- package/lib/DescriptionField/index.js.map +1 -0
- package/lib/ErrorList/ErrorList.d.ts +3 -0
- package/lib/ErrorList/ErrorList.js +9 -0
- package/lib/ErrorList/ErrorList.js.map +1 -0
- package/lib/ErrorList/index.d.ts +2 -0
- package/lib/ErrorList/index.js +3 -0
- package/lib/ErrorList/index.js.map +1 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.d.ts +7 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js +18 -0
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -0
- package/lib/FieldErrorTemplate/index.d.ts +2 -0
- package/lib/FieldErrorTemplate/index.js +3 -0
- package/lib/FieldErrorTemplate/index.js.map +1 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.d.ts +7 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +16 -0
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -0
- package/lib/FieldHelpTemplate/index.d.ts +2 -0
- package/lib/FieldHelpTemplate/index.js +3 -0
- package/lib/FieldHelpTemplate/index.js.map +1 -0
- package/lib/FieldTemplate/FieldTemplate.d.ts +3 -0
- package/lib/FieldTemplate/FieldTemplate.js +13 -0
- package/lib/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/FieldTemplate/index.d.ts +2 -0
- package/lib/FieldTemplate/index.js +3 -0
- package/lib/FieldTemplate/index.js.map +1 -0
- package/lib/Form/Form.d.ts +6 -0
- package/lib/Form/Form.js +7 -0
- package/lib/Form/Form.js.map +1 -0
- package/lib/Form/index.d.ts +2 -0
- package/lib/Form/index.js +3 -0
- package/lib/Form/index.js.map +1 -0
- package/lib/IconButton/ChakraIconButton.d.ts +8 -0
- package/lib/IconButton/ChakraIconButton.js +11 -0
- package/lib/IconButton/ChakraIconButton.js.map +1 -0
- package/lib/IconButton/IconButton.d.ts +6 -0
- package/lib/IconButton/IconButton.js +21 -0
- package/lib/IconButton/IconButton.js.map +1 -0
- package/lib/IconButton/index.d.ts +2 -0
- package/lib/IconButton/index.js +3 -0
- package/lib/IconButton/index.js.map +1 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +3 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +13 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -0
- package/lib/ObjectFieldTemplate/index.d.ts +2 -0
- package/lib/ObjectFieldTemplate/index.js +3 -0
- package/lib/ObjectFieldTemplate/index.js.map +1 -0
- package/lib/RadioWidget/RadioWidget.d.ts +3 -0
- package/lib/RadioWidget/RadioWidget.js +20 -0
- package/lib/RadioWidget/RadioWidget.js.map +1 -0
- package/lib/RadioWidget/index.d.ts +2 -0
- package/lib/RadioWidget/index.js +3 -0
- package/lib/RadioWidget/index.js.map +1 -0
- package/lib/RangeWidget/RangeWidget.d.ts +3 -0
- package/lib/RangeWidget/RangeWidget.js +13 -0
- package/lib/RangeWidget/RangeWidget.js.map +1 -0
- package/lib/RangeWidget/index.d.ts +2 -0
- package/lib/RangeWidget/index.js +3 -0
- package/lib/RangeWidget/index.js.map +1 -0
- package/lib/SelectWidget/SelectWidget.d.ts +3 -0
- package/lib/SelectWidget/SelectWidget.js +47 -0
- package/lib/SelectWidget/SelectWidget.js.map +1 -0
- package/lib/SelectWidget/index.d.ts +2 -0
- package/lib/SelectWidget/index.js +3 -0
- package/lib/SelectWidget/index.js.map +1 -0
- package/lib/SubmitButton/SubmitButton.d.ts +3 -0
- package/lib/SubmitButton/SubmitButton.js +11 -0
- package/lib/SubmitButton/SubmitButton.js.map +1 -0
- package/lib/SubmitButton/index.d.ts +2 -0
- package/lib/SubmitButton/index.js +3 -0
- package/lib/SubmitButton/index.js.map +1 -0
- package/lib/Templates/Templates.d.ts +4 -0
- package/lib/Templates/Templates.js +39 -0
- package/lib/Templates/Templates.js.map +1 -0
- package/lib/Templates/index.d.ts +2 -0
- package/lib/Templates/index.js +3 -0
- package/lib/Templates/index.js.map +1 -0
- package/lib/TextareaWidget/TextareaWidget.d.ts +3 -0
- package/lib/TextareaWidget/TextareaWidget.js +12 -0
- package/lib/TextareaWidget/TextareaWidget.js.map +1 -0
- package/lib/TextareaWidget/index.d.ts +2 -0
- package/lib/TextareaWidget/index.js +3 -0
- package/lib/TextareaWidget/index.js.map +1 -0
- package/lib/Theme/Theme.d.ts +5 -0
- package/lib/Theme/Theme.js +10 -0
- package/lib/Theme/Theme.js.map +1 -0
- package/lib/Theme/index.d.ts +2 -0
- package/lib/Theme/index.js +3 -0
- package/lib/Theme/index.js.map +1 -0
- package/lib/TitleField/TitleField.d.ts +3 -0
- package/lib/TitleField/TitleField.js +6 -0
- package/lib/TitleField/TitleField.js.map +1 -0
- package/lib/TitleField/index.d.ts +2 -0
- package/lib/TitleField/index.js +3 -0
- package/lib/TitleField/index.js.map +1 -0
- package/lib/UpDownWidget/UpDownWidget.d.ts +3 -0
- package/lib/UpDownWidget/UpDownWidget.js +13 -0
- package/lib/UpDownWidget/UpDownWidget.js.map +1 -0
- package/lib/UpDownWidget/index.d.ts +2 -0
- package/lib/UpDownWidget/index.js +3 -0
- package/lib/UpDownWidget/index.js.map +1 -0
- package/lib/Widgets/Widgets.d.ts +4 -0
- package/lib/Widgets/Widgets.js +24 -0
- package/lib/Widgets/Widgets.js.map +1 -0
- package/lib/Widgets/index.d.ts +2 -0
- package/lib/Widgets/index.js +3 -0
- package/lib/Widgets/index.js.map +1 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.d.ts +3 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +17 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/WrapIfAdditionalTemplate/index.d.ts +2 -0
- package/lib/WrapIfAdditionalTemplate/index.js +3 -0
- package/lib/WrapIfAdditionalTemplate/index.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/utils.d.ts +13 -0
- package/lib/utils.js +18 -0
- package/lib/utils.js.map +1 -0
- package/package.json +22 -14
- package/src/AddButton/AddButton.tsx +16 -0
- package/src/AddButton/index.ts +2 -0
- package/src/AltDateTimeWidget/AltDateTimeWidget.tsx +16 -0
- package/src/AltDateTimeWidget/index.ts +2 -0
- package/src/AltDateWidget/AltDateWidget.tsx +165 -0
- package/src/AltDateWidget/index.ts +2 -0
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +78 -0
- package/src/ArrayFieldItemTemplate/index.ts +2 -0
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +79 -0
- package/src/ArrayFieldTemplate/index.ts +2 -0
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +87 -0
- package/src/BaseInputTemplate/index.ts +2 -0
- package/src/ChakraFrameProvider.tsx +40 -0
- package/src/CheckboxWidget/CheckboxWidget.tsx +77 -0
- package/src/CheckboxWidget/index.ts +2 -0
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +93 -0
- package/src/CheckboxesWidget/index.ts +2 -0
- package/src/CssReset.tsx +270 -0
- package/src/DescriptionField/DescriptionField.tsx +22 -0
- package/src/DescriptionField/index.ts +2 -0
- package/src/ErrorList/ErrorList.tsx +23 -0
- package/src/ErrorList/index.ts +2 -0
- package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +30 -0
- package/src/FieldErrorTemplate/index.ts +2 -0
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +19 -0
- package/src/FieldHelpTemplate/index.ts +2 -0
- package/src/FieldTemplate/FieldTemplate.tsx +72 -0
- package/src/FieldTemplate/index.ts +2 -0
- package/src/Form/Form.tsx +14 -0
- package/src/Form/index.ts +2 -0
- package/src/IconButton/ChakraIconButton.tsx +15 -0
- package/src/IconButton/IconButton.tsx +60 -0
- package/src/IconButton/index.ts +2 -0
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +88 -0
- package/src/ObjectFieldTemplate/index.ts +2 -0
- package/src/RadioWidget/RadioWidget.tsx +78 -0
- package/src/RadioWidget/index.ts +2 -0
- package/src/RangeWidget/RangeWidget.tsx +56 -0
- package/src/RangeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +121 -0
- package/src/SelectWidget/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +21 -0
- package/src/SubmitButton/index.ts +2 -0
- package/src/Templates/Templates.ts +45 -0
- package/src/Templates/index.ts +2 -0
- package/src/TextareaWidget/TextareaWidget.tsx +64 -0
- package/src/TextareaWidget/index.ts +2 -0
- package/src/Theme/Theme.tsx +18 -0
- package/src/Theme/index.ts +2 -0
- package/src/TitleField/TitleField.tsx +14 -0
- package/src/TitleField/index.ts +2 -0
- package/src/UpDownWidget/UpDownWidget.tsx +58 -0
- package/src/UpDownWidget/index.ts +2 -0
- package/src/Widgets/Widgets.ts +30 -0
- package/src/Widgets/index.ts +2 -0
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +76 -0
- package/src/WrapIfAdditionalTemplate/index.ts +2 -0
- package/src/index.ts +11 -0
- package/src/utils.ts +31 -0
- package/dist/chakra-ui.cjs.development.js +0 -1657
- package/dist/chakra-ui.cjs.development.js.map +0 -1
- package/dist/chakra-ui.cjs.production.min.js +0 -2
- package/dist/chakra-ui.cjs.production.min.js.map +0 -1
- package/dist/chakra-ui.umd.development.js +0 -1652
- package/dist/chakra-ui.umd.development.js.map +0 -1
- package/dist/chakra-ui.umd.production.min.js +0 -2
- package/dist/chakra-ui.umd.production.min.js.map +0 -1
- package/dist/index.d.ts +0 -28
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent } from 'react';
|
|
2
|
+
import { Checkbox, FormControl, Text } from '@chakra-ui/react';
|
|
3
|
+
import {
|
|
4
|
+
ariaDescribedByIds,
|
|
5
|
+
descriptionId,
|
|
6
|
+
getTemplate,
|
|
7
|
+
labelValue,
|
|
8
|
+
WidgetProps,
|
|
9
|
+
schemaRequiresTrueValue,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
FormContextType,
|
|
13
|
+
} from '@rjsf/utils';
|
|
14
|
+
import { getChakra } from '../utils';
|
|
15
|
+
|
|
16
|
+
export default function CheckboxWidget<
|
|
17
|
+
T = any,
|
|
18
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
|
+
F extends FormContextType = any
|
|
20
|
+
>(props: WidgetProps<T, S, F>) {
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
value,
|
|
24
|
+
disabled,
|
|
25
|
+
readonly,
|
|
26
|
+
onChange,
|
|
27
|
+
onBlur,
|
|
28
|
+
onFocus,
|
|
29
|
+
label,
|
|
30
|
+
hideLabel,
|
|
31
|
+
registry,
|
|
32
|
+
options,
|
|
33
|
+
uiSchema,
|
|
34
|
+
schema,
|
|
35
|
+
} = props;
|
|
36
|
+
const chakraProps = getChakra({ uiSchema });
|
|
37
|
+
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
38
|
+
// the "required" attribute if the field value must be "true", due to the
|
|
39
|
+
// "const" or "enum" keywords
|
|
40
|
+
const required = schemaRequiresTrueValue<S>(schema);
|
|
41
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
42
|
+
'DescriptionFieldTemplate',
|
|
43
|
+
registry,
|
|
44
|
+
options
|
|
45
|
+
);
|
|
46
|
+
const description = options.description || schema.description;
|
|
47
|
+
|
|
48
|
+
const _onChange = ({ target: { checked } }: ChangeEvent<HTMLInputElement>) => onChange(checked);
|
|
49
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement | any>) => onBlur(id, value);
|
|
50
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement | any>) => onFocus(id, value);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<FormControl mb={1} {...chakraProps} isRequired={required}>
|
|
54
|
+
{!hideLabel && !!description && (
|
|
55
|
+
<DescriptionFieldTemplate
|
|
56
|
+
id={descriptionId<T>(id)}
|
|
57
|
+
description={description}
|
|
58
|
+
schema={schema}
|
|
59
|
+
uiSchema={uiSchema}
|
|
60
|
+
registry={registry}
|
|
61
|
+
/>
|
|
62
|
+
)}
|
|
63
|
+
<Checkbox
|
|
64
|
+
id={id}
|
|
65
|
+
name={id}
|
|
66
|
+
isChecked={typeof value === 'undefined' ? false : value}
|
|
67
|
+
isDisabled={disabled || readonly}
|
|
68
|
+
onChange={_onChange}
|
|
69
|
+
onBlur={_onBlur}
|
|
70
|
+
onFocus={_onFocus}
|
|
71
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
72
|
+
>
|
|
73
|
+
{labelValue(<Text>{label}</Text>, hideLabel || !label)}
|
|
74
|
+
</Checkbox>
|
|
75
|
+
</FormControl>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { FocusEvent } from 'react';
|
|
2
|
+
import { CheckboxGroup, Checkbox, FormLabel, FormControl, Text, Stack } from '@chakra-ui/react';
|
|
3
|
+
import {
|
|
4
|
+
ariaDescribedByIds,
|
|
5
|
+
enumOptionsIndexForValue,
|
|
6
|
+
enumOptionsIsSelected,
|
|
7
|
+
enumOptionsValueForIndex,
|
|
8
|
+
labelValue,
|
|
9
|
+
optionId,
|
|
10
|
+
FormContextType,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
WidgetProps,
|
|
14
|
+
} from '@rjsf/utils';
|
|
15
|
+
import { getChakra } from '../utils';
|
|
16
|
+
|
|
17
|
+
export default function CheckboxesWidget<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any
|
|
21
|
+
>(props: WidgetProps<T, S, F>) {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
disabled,
|
|
25
|
+
options,
|
|
26
|
+
value,
|
|
27
|
+
readonly,
|
|
28
|
+
onChange,
|
|
29
|
+
onBlur,
|
|
30
|
+
onFocus,
|
|
31
|
+
required,
|
|
32
|
+
label,
|
|
33
|
+
hideLabel,
|
|
34
|
+
uiSchema,
|
|
35
|
+
rawErrors = [],
|
|
36
|
+
} = props;
|
|
37
|
+
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
38
|
+
const chakraProps = getChakra({ uiSchema });
|
|
39
|
+
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
40
|
+
|
|
41
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement | any>) =>
|
|
42
|
+
onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
43
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement | any>) =>
|
|
44
|
+
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
45
|
+
|
|
46
|
+
const row = options ? options.inline : false;
|
|
47
|
+
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, true) as string[];
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<FormControl
|
|
51
|
+
mb={1}
|
|
52
|
+
{...chakraProps}
|
|
53
|
+
isDisabled={disabled || readonly}
|
|
54
|
+
isRequired={required}
|
|
55
|
+
isReadOnly={readonly}
|
|
56
|
+
isInvalid={rawErrors && rawErrors.length > 0}
|
|
57
|
+
>
|
|
58
|
+
{labelValue(
|
|
59
|
+
<FormLabel htmlFor={id} id={`${id}-label`}>
|
|
60
|
+
{label}
|
|
61
|
+
</FormLabel>,
|
|
62
|
+
hideLabel || !label
|
|
63
|
+
)}
|
|
64
|
+
<CheckboxGroup
|
|
65
|
+
onChange={(option) => onChange(enumOptionsValueForIndex<S>(option, enumOptions, emptyValue))}
|
|
66
|
+
defaultValue={selectedIndexes}
|
|
67
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
68
|
+
>
|
|
69
|
+
<Stack direction={row ? 'row' : 'column'}>
|
|
70
|
+
{Array.isArray(enumOptions) &&
|
|
71
|
+
enumOptions.map((option, index) => {
|
|
72
|
+
const checked = enumOptionsIsSelected<S>(option.value, checkboxesValues);
|
|
73
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
74
|
+
return (
|
|
75
|
+
<Checkbox
|
|
76
|
+
key={index}
|
|
77
|
+
id={optionId(id, index)}
|
|
78
|
+
name={id}
|
|
79
|
+
value={String(index)}
|
|
80
|
+
isChecked={checked}
|
|
81
|
+
isDisabled={disabled || itemDisabled || readonly}
|
|
82
|
+
onBlur={_onBlur}
|
|
83
|
+
onFocus={_onFocus}
|
|
84
|
+
>
|
|
85
|
+
{option.label && <Text>{option.label}</Text>}
|
|
86
|
+
</Checkbox>
|
|
87
|
+
);
|
|
88
|
+
})}
|
|
89
|
+
</Stack>
|
|
90
|
+
</CheckboxGroup>
|
|
91
|
+
</FormControl>
|
|
92
|
+
);
|
|
93
|
+
}
|
package/src/CssReset.tsx
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Global } from '@emotion/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* The reason we need this is for ChakraProvider styling in Playground.
|
|
6
|
+
* The User Developer would be responsible for styling with ChakraProvider in their app.
|
|
7
|
+
*
|
|
8
|
+
* Exact duplicate of `@chakra-ui/react`'s `CSSReset` component. Except for the following:
|
|
9
|
+
*
|
|
10
|
+
```css
|
|
11
|
+
input {
|
|
12
|
+
border-width: revert;
|
|
13
|
+
border-color: revert;
|
|
14
|
+
border-style: revert;
|
|
15
|
+
}
|
|
16
|
+
.array-item > hr {
|
|
17
|
+
margin-top: 16px;
|
|
18
|
+
margin-bottom: 16px;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It is located at the bottom of the styles string.
|
|
23
|
+
*/
|
|
24
|
+
export const CSSReset = () => (
|
|
25
|
+
<Global
|
|
26
|
+
styles={`
|
|
27
|
+
html {
|
|
28
|
+
line-height: 1.5;
|
|
29
|
+
-webkit-text-size-adjust: 100%;
|
|
30
|
+
font-family: system-ui, sans-serif;
|
|
31
|
+
-webkit-font-smoothing: antialiased;
|
|
32
|
+
text-rendering: optimizeLegibility;
|
|
33
|
+
-moz-osx-font-smoothing: grayscale;
|
|
34
|
+
touch-action: manipulation;
|
|
35
|
+
}
|
|
36
|
+
body {
|
|
37
|
+
position: relative;
|
|
38
|
+
min-height: 100%;
|
|
39
|
+
font-feature-settings: 'kern';
|
|
40
|
+
}
|
|
41
|
+
*,
|
|
42
|
+
*::before,
|
|
43
|
+
*::after {
|
|
44
|
+
border-width: 0;
|
|
45
|
+
border-style: solid;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
}
|
|
48
|
+
main {
|
|
49
|
+
display: block;
|
|
50
|
+
}
|
|
51
|
+
hr {
|
|
52
|
+
border-top-width: 1px;
|
|
53
|
+
box-sizing: content-box;
|
|
54
|
+
height: 0;
|
|
55
|
+
overflow: visible;
|
|
56
|
+
}
|
|
57
|
+
pre,
|
|
58
|
+
code,
|
|
59
|
+
kbd,
|
|
60
|
+
samp {
|
|
61
|
+
font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
62
|
+
font-size: 1em;
|
|
63
|
+
}
|
|
64
|
+
a {
|
|
65
|
+
background-color: transparent;
|
|
66
|
+
color: inherit;
|
|
67
|
+
text-decoration: inherit;
|
|
68
|
+
}
|
|
69
|
+
abbr[title] {
|
|
70
|
+
border-bottom: none;
|
|
71
|
+
text-decoration: underline;
|
|
72
|
+
-webkit-text-decoration: underline dotted;
|
|
73
|
+
text-decoration: underline dotted;
|
|
74
|
+
}
|
|
75
|
+
b,
|
|
76
|
+
strong {
|
|
77
|
+
font-weight: bold;
|
|
78
|
+
}
|
|
79
|
+
small {
|
|
80
|
+
font-size: 80%;
|
|
81
|
+
}
|
|
82
|
+
sub,
|
|
83
|
+
sup {
|
|
84
|
+
font-size: 75%;
|
|
85
|
+
line-height: 0;
|
|
86
|
+
position: relative;
|
|
87
|
+
vertical-align: baseline;
|
|
88
|
+
}
|
|
89
|
+
sub {
|
|
90
|
+
bottom: -0.25em;
|
|
91
|
+
}
|
|
92
|
+
sup {
|
|
93
|
+
top: -0.5em;
|
|
94
|
+
}
|
|
95
|
+
img {
|
|
96
|
+
border-style: none;
|
|
97
|
+
}
|
|
98
|
+
button,
|
|
99
|
+
input,
|
|
100
|
+
optgroup,
|
|
101
|
+
select,
|
|
102
|
+
textarea {
|
|
103
|
+
font-family: inherit;
|
|
104
|
+
font-size: 100%;
|
|
105
|
+
line-height: 1.15;
|
|
106
|
+
margin: 0;
|
|
107
|
+
}
|
|
108
|
+
button,
|
|
109
|
+
input {
|
|
110
|
+
overflow: visible;
|
|
111
|
+
}
|
|
112
|
+
button,
|
|
113
|
+
select {
|
|
114
|
+
text-transform: none;
|
|
115
|
+
}
|
|
116
|
+
button::-moz-focus-inner,
|
|
117
|
+
[type="button"]::-moz-focus-inner,
|
|
118
|
+
[type="reset"]::-moz-focus-inner,
|
|
119
|
+
[type="submit"]::-moz-focus-inner {
|
|
120
|
+
border-style: none;
|
|
121
|
+
padding: 0;
|
|
122
|
+
}
|
|
123
|
+
fieldset {
|
|
124
|
+
padding: 0.35em 0.75em 0.625em;
|
|
125
|
+
}
|
|
126
|
+
legend {
|
|
127
|
+
box-sizing: border-box;
|
|
128
|
+
color: inherit;
|
|
129
|
+
display: table;
|
|
130
|
+
max-width: 100%;
|
|
131
|
+
padding: 0;
|
|
132
|
+
white-space: normal;
|
|
133
|
+
}
|
|
134
|
+
progress {
|
|
135
|
+
vertical-align: baseline;
|
|
136
|
+
}
|
|
137
|
+
textarea {
|
|
138
|
+
overflow: auto;
|
|
139
|
+
}
|
|
140
|
+
[type="checkbox"],
|
|
141
|
+
[type="radio"] {
|
|
142
|
+
box-sizing: border-box;
|
|
143
|
+
padding: 0;
|
|
144
|
+
}
|
|
145
|
+
[type="number"]::-webkit-inner-spin-button,
|
|
146
|
+
[type="number"]::-webkit-outer-spin-button {
|
|
147
|
+
-webkit-appearance: none !important;
|
|
148
|
+
}
|
|
149
|
+
input[type="number"] {
|
|
150
|
+
-moz-appearance: textfield;
|
|
151
|
+
}
|
|
152
|
+
[type="search"] {
|
|
153
|
+
-webkit-appearance: textfield;
|
|
154
|
+
outline-offset: -2px;
|
|
155
|
+
}
|
|
156
|
+
[type="search"]::-webkit-search-decoration {
|
|
157
|
+
-webkit-appearance: none !important;
|
|
158
|
+
}
|
|
159
|
+
::-webkit-file-upload-button {
|
|
160
|
+
-webkit-appearance: button;
|
|
161
|
+
font: inherit;
|
|
162
|
+
}
|
|
163
|
+
details {
|
|
164
|
+
display: block;
|
|
165
|
+
}
|
|
166
|
+
summary {
|
|
167
|
+
display: list-item;
|
|
168
|
+
}
|
|
169
|
+
template {
|
|
170
|
+
display: none;
|
|
171
|
+
}
|
|
172
|
+
[hidden] {
|
|
173
|
+
display: none !important;
|
|
174
|
+
}
|
|
175
|
+
body,
|
|
176
|
+
blockquote,
|
|
177
|
+
dl,
|
|
178
|
+
dd,
|
|
179
|
+
h1,
|
|
180
|
+
h2,
|
|
181
|
+
h3,
|
|
182
|
+
h4,
|
|
183
|
+
h5,
|
|
184
|
+
h6,
|
|
185
|
+
hr,
|
|
186
|
+
figure,
|
|
187
|
+
p,
|
|
188
|
+
pre {
|
|
189
|
+
margin: 0;
|
|
190
|
+
}
|
|
191
|
+
button {
|
|
192
|
+
background: transparent;
|
|
193
|
+
padding: 0;
|
|
194
|
+
}
|
|
195
|
+
fieldset {
|
|
196
|
+
margin: 0;
|
|
197
|
+
padding: 0;
|
|
198
|
+
}
|
|
199
|
+
ol,
|
|
200
|
+
ul {
|
|
201
|
+
margin: 0;
|
|
202
|
+
padding: 0;
|
|
203
|
+
}
|
|
204
|
+
textarea {
|
|
205
|
+
resize: vertical;
|
|
206
|
+
}
|
|
207
|
+
button,
|
|
208
|
+
[role="button"] {
|
|
209
|
+
cursor: pointer;
|
|
210
|
+
}
|
|
211
|
+
button::-moz-focus-inner {
|
|
212
|
+
border: 0 !important;
|
|
213
|
+
}
|
|
214
|
+
table {
|
|
215
|
+
border-collapse: collapse;
|
|
216
|
+
}
|
|
217
|
+
h1,
|
|
218
|
+
h2,
|
|
219
|
+
h3,
|
|
220
|
+
h4,
|
|
221
|
+
h5,
|
|
222
|
+
h6 {
|
|
223
|
+
font-size: inherit;
|
|
224
|
+
font-weight: inherit;
|
|
225
|
+
}
|
|
226
|
+
button,
|
|
227
|
+
input,
|
|
228
|
+
optgroup,
|
|
229
|
+
select,
|
|
230
|
+
textarea {
|
|
231
|
+
padding: 0;
|
|
232
|
+
line-height: inherit;
|
|
233
|
+
color: inherit;
|
|
234
|
+
}
|
|
235
|
+
img,
|
|
236
|
+
svg,
|
|
237
|
+
video,
|
|
238
|
+
canvas,
|
|
239
|
+
audio,
|
|
240
|
+
iframe,
|
|
241
|
+
embed,
|
|
242
|
+
object {
|
|
243
|
+
display: block;
|
|
244
|
+
}
|
|
245
|
+
img,
|
|
246
|
+
video {
|
|
247
|
+
max-width: 100%;
|
|
248
|
+
height: auto;
|
|
249
|
+
}
|
|
250
|
+
[data-js-focus-visible] :focus:not([data-focus-visible-added]) {
|
|
251
|
+
outline: none;
|
|
252
|
+
box-shadow: none;
|
|
253
|
+
}
|
|
254
|
+
select::-ms-expand {
|
|
255
|
+
display: none;
|
|
256
|
+
}
|
|
257
|
+
input {
|
|
258
|
+
border-width: revert;
|
|
259
|
+
border-color: revert;
|
|
260
|
+
border-style: revert;
|
|
261
|
+
}
|
|
262
|
+
.array-item > hr {
|
|
263
|
+
margin-top: 16px;
|
|
264
|
+
margin-bottom: 16px;
|
|
265
|
+
}
|
|
266
|
+
`}
|
|
267
|
+
/>
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
export default CSSReset;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { Text } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
export default function DescriptionField<
|
|
5
|
+
T = any,
|
|
6
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
7
|
+
F extends FormContextType = any
|
|
8
|
+
>({ description, id }: DescriptionFieldProps<T, S, F>) {
|
|
9
|
+
if (!description) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof description === 'string') {
|
|
14
|
+
return (
|
|
15
|
+
<Text id={id} mt={2} mb={4}>
|
|
16
|
+
{description}
|
|
17
|
+
</Text>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return <>{description}</>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
2
|
+
import { List, ListIcon, ListItem, Alert, AlertTitle } from '@chakra-ui/react';
|
|
3
|
+
import { WarningIcon } from '@chakra-ui/icons';
|
|
4
|
+
|
|
5
|
+
export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
6
|
+
errors,
|
|
7
|
+
registry,
|
|
8
|
+
}: ErrorListProps<T, S, F>) {
|
|
9
|
+
const { translateString } = registry;
|
|
10
|
+
return (
|
|
11
|
+
<Alert flexDirection='column' alignItems='flex-start' gap={3} status='error'>
|
|
12
|
+
<AlertTitle>{translateString(TranslatableString.ErrorsLabel)}</AlertTitle>
|
|
13
|
+
<List>
|
|
14
|
+
{errors.map((error, i) => (
|
|
15
|
+
<ListItem key={i}>
|
|
16
|
+
<ListIcon as={WarningIcon} color='red.500' />
|
|
17
|
+
{error.stack}
|
|
18
|
+
</ListItem>
|
|
19
|
+
))}
|
|
20
|
+
</List>
|
|
21
|
+
</Alert>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { FormErrorMessage, List, ListItem } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
/** The `FieldErrorTemplate` component renders the errors local to the particular field
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `FieldErrorProps` for the errors being rendered
|
|
7
|
+
*/
|
|
8
|
+
export default function FieldErrorTemplate<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any
|
|
12
|
+
>(props: FieldErrorProps<T, S, F>) {
|
|
13
|
+
const { errors = [], idSchema } = props;
|
|
14
|
+
if (errors.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const id = errorId<T>(idSchema);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<List>
|
|
21
|
+
{errors.map((error, i: number) => {
|
|
22
|
+
return (
|
|
23
|
+
<ListItem key={i}>
|
|
24
|
+
<FormErrorMessage id={id}>{error}</FormErrorMessage>
|
|
25
|
+
</ListItem>
|
|
26
|
+
);
|
|
27
|
+
})}
|
|
28
|
+
</List>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { helpId, FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { FormHelperText } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
/** The `FieldHelpTemplate` component renders any help desired for a field
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `FieldHelpProps` to be rendered
|
|
7
|
+
*/
|
|
8
|
+
export default function FieldHelpTemplate<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any
|
|
12
|
+
>(props: FieldHelpProps<T, S, F>) {
|
|
13
|
+
const { idSchema, help } = props;
|
|
14
|
+
if (!help) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const id = helpId<T>(idSchema);
|
|
18
|
+
return <FormHelperText id={id}>{help}</FormHelperText>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldTemplateProps,
|
|
3
|
+
FormContextType,
|
|
4
|
+
getTemplate,
|
|
5
|
+
getUiOptions,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
import { Text, FormControl } from '@chakra-ui/react';
|
|
10
|
+
|
|
11
|
+
export default function FieldTemplate<
|
|
12
|
+
T = any,
|
|
13
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
14
|
+
F extends FormContextType = any
|
|
15
|
+
>(props: FieldTemplateProps<T, S, F>) {
|
|
16
|
+
const {
|
|
17
|
+
id,
|
|
18
|
+
children,
|
|
19
|
+
classNames,
|
|
20
|
+
style,
|
|
21
|
+
disabled,
|
|
22
|
+
displayLabel,
|
|
23
|
+
hidden,
|
|
24
|
+
label,
|
|
25
|
+
onDropPropertyClick,
|
|
26
|
+
onKeyChange,
|
|
27
|
+
readonly,
|
|
28
|
+
registry,
|
|
29
|
+
required,
|
|
30
|
+
rawErrors = [],
|
|
31
|
+
errors,
|
|
32
|
+
help,
|
|
33
|
+
description,
|
|
34
|
+
rawDescription,
|
|
35
|
+
schema,
|
|
36
|
+
uiSchema,
|
|
37
|
+
} = props;
|
|
38
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
39
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
40
|
+
'WrapIfAdditionalTemplate',
|
|
41
|
+
registry,
|
|
42
|
+
uiOptions
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (hidden) {
|
|
46
|
+
return <div style={{ display: 'none' }}>{children}</div>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<WrapIfAdditionalTemplate
|
|
51
|
+
classNames={classNames}
|
|
52
|
+
style={style}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
id={id}
|
|
55
|
+
label={label}
|
|
56
|
+
onDropPropertyClick={onDropPropertyClick}
|
|
57
|
+
onKeyChange={onKeyChange}
|
|
58
|
+
readonly={readonly}
|
|
59
|
+
required={required}
|
|
60
|
+
schema={schema}
|
|
61
|
+
uiSchema={uiSchema}
|
|
62
|
+
registry={registry}
|
|
63
|
+
>
|
|
64
|
+
<FormControl isRequired={required} isInvalid={rawErrors && rawErrors.length > 0}>
|
|
65
|
+
{children}
|
|
66
|
+
{displayLabel && rawDescription ? <Text mt={2}>{description}</Text> : null}
|
|
67
|
+
{errors}
|
|
68
|
+
{help}
|
|
69
|
+
</FormControl>
|
|
70
|
+
</WrapIfAdditionalTemplate>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { withTheme, FormProps } from '@rjsf/core';
|
|
3
|
+
import { generateTheme } from '../Theme';
|
|
4
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
5
|
+
|
|
6
|
+
export function generateForm<
|
|
7
|
+
T = any,
|
|
8
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
9
|
+
F extends FormContextType = any
|
|
10
|
+
>(): ComponentType<FormProps<T, S, F>> {
|
|
11
|
+
return withTheme<T, S, F>(generateTheme<T, S, F>());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default generateForm();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { IconButton } from '@chakra-ui/react';
|
|
3
|
+
type ChakraIconButtonProps = React.ComponentProps<typeof IconButton>;
|
|
4
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
5
|
+
|
|
6
|
+
function ChakraIconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
7
|
+
props: IconButtonProps<T, S, F>
|
|
8
|
+
) {
|
|
9
|
+
const { icon, iconType, uiSchema, registry, ...otherProps } = props;
|
|
10
|
+
return <IconButton aria-label={props.title!} {...otherProps} icon={icon as ChakraIconButtonProps['icon']} />;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
ChakraIconButton.displayName = 'ChakraIconButton';
|
|
14
|
+
|
|
15
|
+
export default memo(ChakraIconButton) as typeof ChakraIconButton;
|