@rjsf/core 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/core.umd.js +3464 -0
- package/dist/index.esm.js +3814 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +3714 -5
- package/dist/index.js.map +7 -0
- package/{dist/index.d.ts → lib/components/Form.d.ts} +321 -337
- package/lib/components/Form.js +474 -0
- package/lib/components/Form.js.map +1 -0
- package/lib/components/fields/ArrayField.d.ts +179 -0
- package/lib/components/fields/ArrayField.js +568 -0
- package/lib/components/fields/ArrayField.js.map +1 -0
- package/lib/components/fields/BooleanField.d.ts +9 -0
- package/lib/components/fields/BooleanField.js +62 -0
- package/lib/components/fields/BooleanField.js.map +1 -0
- package/lib/components/fields/MultiSchemaField.d.ts +47 -0
- package/lib/components/fields/MultiSchemaField.js +129 -0
- package/lib/components/fields/MultiSchemaField.js.map +1 -0
- package/lib/components/fields/NullField.d.ts +8 -0
- package/lib/components/fields/NullField.js +17 -0
- package/lib/components/fields/NullField.js.map +1 -0
- package/lib/components/fields/NumberField.d.ts +21 -0
- package/lib/components/fields/NumberField.js +70 -0
- package/lib/components/fields/NumberField.js.map +1 -0
- package/lib/components/fields/ObjectField.d.ts +73 -0
- package/lib/components/fields/ObjectField.js +222 -0
- package/lib/components/fields/ObjectField.js.map +1 -0
- package/lib/components/fields/SchemaField.d.ts +10 -0
- package/lib/components/fields/SchemaField.js +172 -0
- package/lib/components/fields/SchemaField.js.map +1 -0
- package/lib/components/fields/StringField.d.ts +8 -0
- package/lib/components/fields/StringField.js +25 -0
- package/lib/components/fields/StringField.js.map +1 -0
- package/lib/components/fields/index.d.ts +3 -0
- package/lib/components/fields/index.js +24 -0
- package/lib/components/fields/index.js.map +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js +20 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTemplate.d.ts +7 -0
- package/lib/components/templates/ArrayFieldTemplate.js +22 -0
- package/lib/components/templates/ArrayFieldTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +8 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js +18 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/components/templates/BaseInputTemplate.d.ts +9 -0
- package/lib/components/templates/BaseInputTemplate.js +39 -0
- package/lib/components/templates/BaseInputTemplate.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js +10 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +7 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js +24 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +5 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +12 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/index.d.ts +3 -0
- package/lib/components/templates/ButtonTemplates/index.js +15 -0
- package/lib/components/templates/ButtonTemplates/index.js.map +1 -0
- package/lib/components/templates/DescriptionField.d.ts +7 -0
- package/lib/components/templates/DescriptionField.js +18 -0
- package/lib/components/templates/DescriptionField.js.map +1 -0
- package/lib/components/templates/ErrorList.d.ts +7 -0
- package/lib/components/templates/ErrorList.js +13 -0
- package/lib/components/templates/ErrorList.js.map +1 -0
- package/lib/components/templates/FieldErrorTemplate.d.ts +7 -0
- package/lib/components/templates/FieldErrorTemplate.js +19 -0
- package/lib/components/templates/FieldErrorTemplate.js.map +1 -0
- package/lib/components/templates/FieldHelpTemplate.d.ts +7 -0
- package/lib/components/templates/FieldHelpTemplate.js +18 -0
- package/lib/components/templates/FieldHelpTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +8 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +18 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/Label.d.ts +14 -0
- package/lib/components/templates/FieldTemplate/Label.js +14 -0
- package/lib/components/templates/FieldTemplate/Label.js.map +1 -0
- package/lib/components/templates/FieldTemplate/index.d.ts +2 -0
- package/lib/components/templates/FieldTemplate/index.js +3 -0
- package/lib/components/templates/FieldTemplate/index.js.map +1 -0
- package/lib/components/templates/ObjectFieldTemplate.d.ts +9 -0
- package/lib/components/templates/ObjectFieldTemplate.js +18 -0
- package/lib/components/templates/ObjectFieldTemplate.js.map +1 -0
- package/lib/components/templates/TitleField.d.ts +7 -0
- package/lib/components/templates/TitleField.js +11 -0
- package/lib/components/templates/TitleField.js.map +1 -0
- package/lib/components/templates/UnsupportedField.d.ts +9 -0
- package/lib/components/templates/UnsupportedField.js +28 -0
- package/lib/components/templates/UnsupportedField.js.map +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +8 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js +21 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/components/templates/index.d.ts +3 -0
- package/lib/components/templates/index.js +36 -0
- package/lib/components/templates/index.js.map +1 -0
- package/lib/components/widgets/AltDateTimeWidget.d.ts +9 -0
- package/lib/components/widgets/AltDateTimeWidget.js +14 -0
- package/lib/components/widgets/AltDateTimeWidget.js.map +1 -0
- package/lib/components/widgets/AltDateWidget.d.ts +7 -0
- package/lib/components/widgets/AltDateWidget.js +77 -0
- package/lib/components/widgets/AltDateWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxWidget.js +23 -0
- package/lib/components/widgets/CheckboxWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxesWidget.d.ts +9 -0
- package/lib/components/widgets/CheckboxesWidget.js +31 -0
- package/lib/components/widgets/CheckboxesWidget.js.map +1 -0
- package/lib/components/widgets/ColorWidget.d.ts +8 -0
- package/lib/components/widgets/ColorWidget.js +13 -0
- package/lib/components/widgets/ColorWidget.js.map +1 -0
- package/lib/components/widgets/DateTimeWidget.d.ts +8 -0
- package/lib/components/widgets/DateTimeWidget.js +13 -0
- package/lib/components/widgets/DateTimeWidget.js.map +1 -0
- package/lib/components/widgets/DateWidget.d.ts +8 -0
- package/lib/components/widgets/DateWidget.js +15 -0
- package/lib/components/widgets/DateWidget.js.map +1 -0
- package/lib/components/widgets/EmailWidget.d.ts +7 -0
- package/lib/components/widgets/EmailWidget.js +12 -0
- package/lib/components/widgets/EmailWidget.js.map +1 -0
- package/lib/components/widgets/FileWidget.d.ts +8 -0
- package/lib/components/widgets/FileWidget.js +105 -0
- package/lib/components/widgets/FileWidget.js.map +1 -0
- package/lib/components/widgets/HiddenWidget.d.ts +9 -0
- package/lib/components/widgets/HiddenWidget.js +11 -0
- package/lib/components/widgets/HiddenWidget.js.map +1 -0
- package/lib/components/widgets/PasswordWidget.d.ts +7 -0
- package/lib/components/widgets/PasswordWidget.js +12 -0
- package/lib/components/widgets/PasswordWidget.js.map +1 -0
- package/lib/components/widgets/RadioWidget.d.ts +9 -0
- package/lib/components/widgets/RadioWidget.js +24 -0
- package/lib/components/widgets/RadioWidget.js.map +1 -0
- package/lib/components/widgets/RangeWidget.d.ts +8 -0
- package/lib/components/widgets/RangeWidget.js +11 -0
- package/lib/components/widgets/RangeWidget.js.map +1 -0
- package/lib/components/widgets/SelectWidget.d.ts +9 -0
- package/lib/components/widgets/SelectWidget.js +41 -0
- package/lib/components/widgets/SelectWidget.js.map +1 -0
- package/lib/components/widgets/TextWidget.d.ts +7 -0
- package/lib/components/widgets/TextWidget.js +12 -0
- package/lib/components/widgets/TextWidget.js.map +1 -0
- package/lib/components/widgets/TextareaWidget.d.ts +14 -0
- package/lib/components/widgets/TextareaWidget.js +19 -0
- package/lib/components/widgets/TextareaWidget.js.map +1 -0
- package/lib/components/widgets/TimeWidget.d.ts +8 -0
- package/lib/components/widgets/TimeWidget.js +15 -0
- package/lib/components/widgets/TimeWidget.js.map +1 -0
- package/lib/components/widgets/URLWidget.d.ts +7 -0
- package/lib/components/widgets/URLWidget.js +12 -0
- package/lib/components/widgets/URLWidget.js.map +1 -0
- package/lib/components/widgets/UpDownWidget.d.ts +7 -0
- package/lib/components/widgets/UpDownWidget.js +12 -0
- package/lib/components/widgets/UpDownWidget.js.map +1 -0
- package/lib/components/widgets/index.d.ts +3 -0
- package/lib/components/widgets/index.js +44 -0
- package/lib/components/widgets/index.js.map +1 -0
- package/lib/getDefaultRegistry.d.ts +6 -0
- package/lib/getDefaultRegistry.js +19 -0
- package/lib/getDefaultRegistry.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/withTheme.d.ts +9 -0
- package/lib/withTheme.js +16 -0
- package/lib/withTheme.js.map +1 -0
- package/package.json +23 -16
- package/src/components/Form.tsx +853 -0
- package/src/components/fields/ArrayField.tsx +875 -0
- package/src/components/fields/BooleanField.tsx +114 -0
- package/src/components/fields/MultiSchemaField.tsx +221 -0
- package/src/components/fields/NullField.tsx +22 -0
- package/src/components/fields/NumberField.tsx +86 -0
- package/src/components/fields/ObjectField.tsx +331 -0
- package/src/components/fields/SchemaField.tsx +360 -0
- package/src/components/fields/StringField.tsx +71 -0
- package/src/components/fields/index.ts +31 -0
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +41 -0
- package/src/components/templates/ArrayFieldItemTemplate.tsx +90 -0
- package/src/components/templates/ArrayFieldTemplate.tsx +88 -0
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +43 -0
- package/src/components/templates/BaseInputTemplate.tsx +102 -0
- package/src/components/templates/ButtonTemplates/AddButton.tsx +29 -0
- package/src/components/templates/ButtonTemplates/IconButton.tsx +77 -0
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +21 -0
- package/src/components/templates/ButtonTemplates/index.ts +22 -0
- package/src/components/templates/DescriptionField.tsx +29 -0
- package/src/components/templates/ErrorList.tsx +35 -0
- package/src/components/templates/FieldErrorTemplate.tsx +33 -0
- package/src/components/templates/FieldHelpTemplate.tsx +29 -0
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +41 -0
- package/src/components/templates/FieldTemplate/Label.tsx +27 -0
- package/src/components/templates/FieldTemplate/index.ts +3 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +83 -0
- package/src/components/templates/TitleField.tsx +19 -0
- package/src/components/templates/UnsupportedField.tsx +37 -0
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +80 -0
- package/src/components/templates/index.ts +43 -0
- package/src/components/widgets/AltDateTimeWidget.tsx +16 -0
- package/src/components/widgets/AltDateWidget.tsx +198 -0
- package/src/components/widgets/CheckboxWidget.tsx +92 -0
- package/src/components/widgets/CheckboxesWidget.tsx +92 -0
- package/src/components/widgets/ColorWidget.tsx +14 -0
- package/src/components/widgets/DateTimeWidget.tsx +31 -0
- package/src/components/widgets/DateWidget.tsx +17 -0
- package/src/components/widgets/EmailWidget.tsx +13 -0
- package/src/components/widgets/FileWidget.tsx +178 -0
- package/src/components/widgets/HiddenWidget.tsx +15 -0
- package/src/components/widgets/PasswordWidget.tsx +15 -0
- package/src/components/widgets/RadioWidget.tsx +88 -0
- package/src/components/widgets/RangeWidget.tsx +23 -0
- package/src/components/widgets/SelectWidget.tsx +100 -0
- package/src/components/widgets/TextWidget.tsx +13 -0
- package/src/components/widgets/TextareaWidget.tsx +61 -0
- package/src/components/widgets/TimeWidget.tsx +17 -0
- package/src/components/widgets/URLWidget.tsx +13 -0
- package/src/components/widgets/UpDownWidget.tsx +13 -0
- package/src/components/widgets/index.ts +51 -0
- package/src/getDefaultRegistry.ts +24 -0
- package/src/index.ts +8 -0
- package/src/withTheme.tsx +42 -0
- package/dist/core.cjs.development.js +0 -4403
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -4383
- package/dist/core.esm.js.map +0 -1
- package/dist/core.umd.development.js +0 -4393
- package/dist/core.umd.development.js.map +0 -1
- package/dist/core.umd.production.min.js +0 -2
- package/dist/core.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getWidget,
|
|
3
|
+
getUiOptions,
|
|
4
|
+
optionsList,
|
|
5
|
+
hasWidget,
|
|
6
|
+
FieldProps,
|
|
7
|
+
FormContextType,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
|
|
12
|
+
/** The `StringField` component is used to render a schema field that represents a string type
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `FieldProps` for this template
|
|
15
|
+
*/
|
|
16
|
+
function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
17
|
+
props: FieldProps<T, S, F>
|
|
18
|
+
) {
|
|
19
|
+
const {
|
|
20
|
+
schema,
|
|
21
|
+
name,
|
|
22
|
+
uiSchema,
|
|
23
|
+
idSchema,
|
|
24
|
+
formData,
|
|
25
|
+
required,
|
|
26
|
+
disabled = false,
|
|
27
|
+
readonly = false,
|
|
28
|
+
autofocus = false,
|
|
29
|
+
onChange,
|
|
30
|
+
onBlur,
|
|
31
|
+
onFocus,
|
|
32
|
+
registry,
|
|
33
|
+
rawErrors,
|
|
34
|
+
} = props;
|
|
35
|
+
const { title, format } = schema;
|
|
36
|
+
const { widgets, formContext, schemaUtils, globalUiOptions } = registry;
|
|
37
|
+
const enumOptions = schemaUtils.isSelect(schema) ? optionsList(schema) : undefined;
|
|
38
|
+
let defaultWidget = enumOptions ? 'select' : 'text';
|
|
39
|
+
if (format && hasWidget<T, S, F>(schema, format, widgets)) {
|
|
40
|
+
defaultWidget = format;
|
|
41
|
+
}
|
|
42
|
+
const { widget = defaultWidget, placeholder = '', title: uiTitle, ...options } = getUiOptions<T, S, F>(uiSchema);
|
|
43
|
+
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
44
|
+
const label = uiTitle ?? title ?? name;
|
|
45
|
+
const Widget = getWidget<T, S, F>(schema, widget, widgets);
|
|
46
|
+
return (
|
|
47
|
+
<Widget
|
|
48
|
+
options={{ ...options, enumOptions }}
|
|
49
|
+
schema={schema}
|
|
50
|
+
uiSchema={uiSchema}
|
|
51
|
+
id={idSchema.$id}
|
|
52
|
+
name={name}
|
|
53
|
+
label={label}
|
|
54
|
+
hideLabel={!displayLabel}
|
|
55
|
+
value={formData}
|
|
56
|
+
onChange={onChange}
|
|
57
|
+
onBlur={onBlur}
|
|
58
|
+
onFocus={onFocus}
|
|
59
|
+
required={required}
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
readonly={readonly}
|
|
62
|
+
formContext={formContext}
|
|
63
|
+
autofocus={autofocus}
|
|
64
|
+
registry={registry}
|
|
65
|
+
placeholder={placeholder}
|
|
66
|
+
rawErrors={rawErrors}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default StringField;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Field, FormContextType, RegistryFieldsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import ArrayField from './ArrayField';
|
|
4
|
+
import BooleanField from './BooleanField';
|
|
5
|
+
import MultiSchemaField from './MultiSchemaField';
|
|
6
|
+
import NumberField from './NumberField';
|
|
7
|
+
import ObjectField from './ObjectField';
|
|
8
|
+
import SchemaField from './SchemaField';
|
|
9
|
+
import StringField from './StringField';
|
|
10
|
+
import NullField from './NullField';
|
|
11
|
+
|
|
12
|
+
function fields<
|
|
13
|
+
T = any,
|
|
14
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
15
|
+
F extends FormContextType = any
|
|
16
|
+
>(): RegistryFieldsType<T, S, F> {
|
|
17
|
+
return {
|
|
18
|
+
AnyOfField: MultiSchemaField,
|
|
19
|
+
ArrayField: ArrayField as unknown as Field<T, S, F>,
|
|
20
|
+
// ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
|
|
21
|
+
BooleanField,
|
|
22
|
+
NumberField,
|
|
23
|
+
ObjectField,
|
|
24
|
+
OneOfField: MultiSchemaField,
|
|
25
|
+
SchemaField,
|
|
26
|
+
StringField,
|
|
27
|
+
NullField,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default fields;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
descriptionId,
|
|
3
|
+
getTemplate,
|
|
4
|
+
getUiOptions,
|
|
5
|
+
ArrayFieldDescriptionProps,
|
|
6
|
+
FormContextType,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
|
|
11
|
+
/** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
|
|
12
|
+
* the `idSchema`.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `ArrayFieldDescriptionProps` for the component
|
|
15
|
+
*/
|
|
16
|
+
export default function ArrayFieldDescriptionTemplate<
|
|
17
|
+
T = any,
|
|
18
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
|
+
F extends FormContextType = any
|
|
20
|
+
>(props: ArrayFieldDescriptionProps<T, S, F>) {
|
|
21
|
+
const { idSchema, description, registry, schema, uiSchema } = props;
|
|
22
|
+
const options = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
|
|
23
|
+
const { label: displayLabel = true } = options;
|
|
24
|
+
if (!description || !displayLabel) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
28
|
+
'DescriptionFieldTemplate',
|
|
29
|
+
registry,
|
|
30
|
+
options
|
|
31
|
+
);
|
|
32
|
+
return (
|
|
33
|
+
<DescriptionFieldTemplate
|
|
34
|
+
id={descriptionId<T>(idSchema)}
|
|
35
|
+
description={description}
|
|
36
|
+
schema={schema}
|
|
37
|
+
uiSchema={uiSchema}
|
|
38
|
+
registry={registry}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
/** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
7
|
+
*/
|
|
8
|
+
export default function ArrayFieldItemTemplate<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any
|
|
12
|
+
>(props: ArrayFieldTemplateItemType<T, S, F>) {
|
|
13
|
+
const {
|
|
14
|
+
children,
|
|
15
|
+
className,
|
|
16
|
+
disabled,
|
|
17
|
+
hasToolbar,
|
|
18
|
+
hasMoveDown,
|
|
19
|
+
hasMoveUp,
|
|
20
|
+
hasRemove,
|
|
21
|
+
hasCopy,
|
|
22
|
+
index,
|
|
23
|
+
onCopyIndexClick,
|
|
24
|
+
onDropIndexClick,
|
|
25
|
+
onReorderClick,
|
|
26
|
+
readonly,
|
|
27
|
+
registry,
|
|
28
|
+
uiSchema,
|
|
29
|
+
} = props;
|
|
30
|
+
const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates;
|
|
31
|
+
const btnStyle: CSSProperties = {
|
|
32
|
+
flex: 1,
|
|
33
|
+
paddingLeft: 6,
|
|
34
|
+
paddingRight: 6,
|
|
35
|
+
fontWeight: 'bold',
|
|
36
|
+
};
|
|
37
|
+
return (
|
|
38
|
+
<div className={className}>
|
|
39
|
+
<div className={hasToolbar ? 'col-xs-9' : 'col-xs-12'}>{children}</div>
|
|
40
|
+
{hasToolbar && (
|
|
41
|
+
<div className='col-xs-3 array-item-toolbox'>
|
|
42
|
+
<div
|
|
43
|
+
className='btn-group'
|
|
44
|
+
style={{
|
|
45
|
+
display: 'flex',
|
|
46
|
+
justifyContent: 'space-around',
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
{(hasMoveUp || hasMoveDown) && (
|
|
50
|
+
<MoveUpButton
|
|
51
|
+
style={btnStyle}
|
|
52
|
+
disabled={disabled || readonly || !hasMoveUp}
|
|
53
|
+
onClick={onReorderClick(index, index - 1)}
|
|
54
|
+
uiSchema={uiSchema}
|
|
55
|
+
registry={registry}
|
|
56
|
+
/>
|
|
57
|
+
)}
|
|
58
|
+
{(hasMoveUp || hasMoveDown) && (
|
|
59
|
+
<MoveDownButton
|
|
60
|
+
style={btnStyle}
|
|
61
|
+
disabled={disabled || readonly || !hasMoveDown}
|
|
62
|
+
onClick={onReorderClick(index, index + 1)}
|
|
63
|
+
uiSchema={uiSchema}
|
|
64
|
+
registry={registry}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
{hasCopy && (
|
|
68
|
+
<CopyButton
|
|
69
|
+
style={btnStyle}
|
|
70
|
+
disabled={disabled || readonly}
|
|
71
|
+
onClick={onCopyIndexClick(index)}
|
|
72
|
+
uiSchema={uiSchema}
|
|
73
|
+
registry={registry}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
{hasRemove && (
|
|
77
|
+
<RemoveButton
|
|
78
|
+
style={btnStyle}
|
|
79
|
+
disabled={disabled || readonly}
|
|
80
|
+
onClick={onDropIndexClick(index)}
|
|
81
|
+
uiSchema={uiSchema}
|
|
82
|
+
registry={registry}
|
|
83
|
+
/>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTemplate,
|
|
3
|
+
getUiOptions,
|
|
4
|
+
ArrayFieldTemplateProps,
|
|
5
|
+
ArrayFieldTemplateItemType,
|
|
6
|
+
FormContextType,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
|
|
11
|
+
/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
|
|
12
|
+
*
|
|
13
|
+
* @param props - The `ArrayFieldTemplateItemType` props for the component
|
|
14
|
+
*/
|
|
15
|
+
export default function ArrayFieldTemplate<
|
|
16
|
+
T = any,
|
|
17
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
18
|
+
F extends FormContextType = any
|
|
19
|
+
>(props: ArrayFieldTemplateProps<T, S, F>) {
|
|
20
|
+
const {
|
|
21
|
+
canAdd,
|
|
22
|
+
className,
|
|
23
|
+
disabled,
|
|
24
|
+
idSchema,
|
|
25
|
+
uiSchema,
|
|
26
|
+
items,
|
|
27
|
+
onAddClick,
|
|
28
|
+
readonly,
|
|
29
|
+
registry,
|
|
30
|
+
required,
|
|
31
|
+
schema,
|
|
32
|
+
title,
|
|
33
|
+
} = props;
|
|
34
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
35
|
+
const ArrayFieldDescriptionTemplate = getTemplate<'ArrayFieldDescriptionTemplate', T, S, F>(
|
|
36
|
+
'ArrayFieldDescriptionTemplate',
|
|
37
|
+
registry,
|
|
38
|
+
uiOptions
|
|
39
|
+
);
|
|
40
|
+
const ArrayFieldItemTemplate = getTemplate<'ArrayFieldItemTemplate', T, S, F>(
|
|
41
|
+
'ArrayFieldItemTemplate',
|
|
42
|
+
registry,
|
|
43
|
+
uiOptions
|
|
44
|
+
);
|
|
45
|
+
const ArrayFieldTitleTemplate = getTemplate<'ArrayFieldTitleTemplate', T, S, F>(
|
|
46
|
+
'ArrayFieldTitleTemplate',
|
|
47
|
+
registry,
|
|
48
|
+
uiOptions
|
|
49
|
+
);
|
|
50
|
+
// Button templates are not overridden in the uiSchema
|
|
51
|
+
const {
|
|
52
|
+
ButtonTemplates: { AddButton },
|
|
53
|
+
} = registry.templates;
|
|
54
|
+
return (
|
|
55
|
+
<fieldset className={className} id={idSchema.$id}>
|
|
56
|
+
<ArrayFieldTitleTemplate
|
|
57
|
+
idSchema={idSchema}
|
|
58
|
+
title={uiOptions.title || title}
|
|
59
|
+
required={required}
|
|
60
|
+
schema={schema}
|
|
61
|
+
uiSchema={uiSchema}
|
|
62
|
+
registry={registry}
|
|
63
|
+
/>
|
|
64
|
+
<ArrayFieldDescriptionTemplate
|
|
65
|
+
idSchema={idSchema}
|
|
66
|
+
description={uiOptions.description || schema.description}
|
|
67
|
+
schema={schema}
|
|
68
|
+
uiSchema={uiSchema}
|
|
69
|
+
registry={registry}
|
|
70
|
+
/>
|
|
71
|
+
<div className='row array-item-list'>
|
|
72
|
+
{items &&
|
|
73
|
+
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>) => (
|
|
74
|
+
<ArrayFieldItemTemplate key={key} {...itemProps} />
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
{canAdd && (
|
|
78
|
+
<AddButton
|
|
79
|
+
className='array-item-add'
|
|
80
|
+
onClick={onAddClick}
|
|
81
|
+
disabled={disabled || readonly}
|
|
82
|
+
uiSchema={uiSchema}
|
|
83
|
+
registry={registry}
|
|
84
|
+
/>
|
|
85
|
+
)}
|
|
86
|
+
</fieldset>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTemplate,
|
|
3
|
+
getUiOptions,
|
|
4
|
+
titleId,
|
|
5
|
+
ArrayFieldTitleProps,
|
|
6
|
+
FormContextType,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
TemplatesType,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
|
|
12
|
+
/** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
|
|
13
|
+
* the `idSchema`.
|
|
14
|
+
*
|
|
15
|
+
* @param props - The `ArrayFieldTitleProps` for the component
|
|
16
|
+
*/
|
|
17
|
+
export default function ArrayFieldTitleTemplate<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any
|
|
21
|
+
>(props: ArrayFieldTitleProps<T, S, F>) {
|
|
22
|
+
const { idSchema, title, schema, uiSchema, required, registry } = props;
|
|
23
|
+
const options = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
|
|
24
|
+
const { label: displayLabel = true } = options;
|
|
25
|
+
if (!title || !displayLabel) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const TitleFieldTemplate: TemplatesType<T, S, F>['TitleFieldTemplate'] = getTemplate<'TitleFieldTemplate', T, S, F>(
|
|
29
|
+
'TitleFieldTemplate',
|
|
30
|
+
registry,
|
|
31
|
+
options
|
|
32
|
+
);
|
|
33
|
+
return (
|
|
34
|
+
<TitleFieldTemplate
|
|
35
|
+
id={titleId<T>(idSchema)}
|
|
36
|
+
title={title}
|
|
37
|
+
required={required}
|
|
38
|
+
schema={schema}
|
|
39
|
+
uiSchema={uiSchema}
|
|
40
|
+
registry={registry}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
BaseInputTemplateProps,
|
|
5
|
+
examplesId,
|
|
6
|
+
getInputProps,
|
|
7
|
+
FormContextType,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
|
|
12
|
+
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
13
|
+
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
14
|
+
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `WidgetProps` for this template
|
|
17
|
+
*/
|
|
18
|
+
export default function BaseInputTemplate<
|
|
19
|
+
T = any,
|
|
20
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
21
|
+
F extends FormContextType = any
|
|
22
|
+
>(props: BaseInputTemplateProps<T, S, F>) {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
name, // remove this from ...rest
|
|
26
|
+
value,
|
|
27
|
+
readonly,
|
|
28
|
+
disabled,
|
|
29
|
+
autofocus,
|
|
30
|
+
onBlur,
|
|
31
|
+
onFocus,
|
|
32
|
+
onChange,
|
|
33
|
+
onChangeOverride,
|
|
34
|
+
options,
|
|
35
|
+
schema,
|
|
36
|
+
uiSchema,
|
|
37
|
+
formContext,
|
|
38
|
+
registry,
|
|
39
|
+
rawErrors,
|
|
40
|
+
type,
|
|
41
|
+
hideLabel, // remove this from ...rest
|
|
42
|
+
hideError, // remove this from ...rest
|
|
43
|
+
...rest
|
|
44
|
+
} = props;
|
|
45
|
+
|
|
46
|
+
// Note: since React 15.2.0 we can't forward unknown element attributes, so we
|
|
47
|
+
// exclude the "options" and "schema" ones here.
|
|
48
|
+
if (!id) {
|
|
49
|
+
console.log('No id for', props);
|
|
50
|
+
throw new Error(`no id for props ${JSON.stringify(props)}`);
|
|
51
|
+
}
|
|
52
|
+
const inputProps = {
|
|
53
|
+
...rest,
|
|
54
|
+
...getInputProps<T, S, F>(schema, type, options),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
let inputValue;
|
|
58
|
+
if (inputProps.type === 'number' || inputProps.type === 'integer') {
|
|
59
|
+
inputValue = value || value === 0 ? value : '';
|
|
60
|
+
} else {
|
|
61
|
+
inputValue = value == null ? '' : value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const _onChange = useCallback(
|
|
65
|
+
({ target: { value } }: ChangeEvent<HTMLInputElement>) => onChange(value === '' ? options.emptyValue : value),
|
|
66
|
+
[onChange, options]
|
|
67
|
+
);
|
|
68
|
+
const _onBlur = useCallback(({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value), [onBlur, id]);
|
|
69
|
+
const _onFocus = useCallback(
|
|
70
|
+
({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value),
|
|
71
|
+
[onFocus, id]
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<input
|
|
77
|
+
id={id}
|
|
78
|
+
name={id}
|
|
79
|
+
className='form-control'
|
|
80
|
+
readOnly={readonly}
|
|
81
|
+
disabled={disabled}
|
|
82
|
+
autoFocus={autofocus}
|
|
83
|
+
value={inputValue}
|
|
84
|
+
{...inputProps}
|
|
85
|
+
list={schema.examples ? examplesId<T>(id) : undefined}
|
|
86
|
+
onChange={onChangeOverride || _onChange}
|
|
87
|
+
onBlur={_onBlur}
|
|
88
|
+
onFocus={_onFocus}
|
|
89
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
90
|
+
/>
|
|
91
|
+
{Array.isArray(schema.examples) && (
|
|
92
|
+
<datalist key={`datalist_${id}`} id={examplesId<T>(id)}>
|
|
93
|
+
{(schema.examples as string[])
|
|
94
|
+
.concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
|
|
95
|
+
.map((example: any) => {
|
|
96
|
+
return <option key={example} value={example} />;
|
|
97
|
+
})}
|
|
98
|
+
</datalist>
|
|
99
|
+
)}
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import IconButton from './IconButton';
|
|
4
|
+
|
|
5
|
+
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
6
|
+
*/
|
|
7
|
+
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
8
|
+
className,
|
|
9
|
+
onClick,
|
|
10
|
+
disabled,
|
|
11
|
+
registry,
|
|
12
|
+
}: IconButtonProps<T, S, F>) {
|
|
13
|
+
const { translateString } = registry;
|
|
14
|
+
return (
|
|
15
|
+
<div className='row'>
|
|
16
|
+
<p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
|
|
17
|
+
<IconButton
|
|
18
|
+
iconType='info'
|
|
19
|
+
icon='plus'
|
|
20
|
+
className='btn-add col-xs-12'
|
|
21
|
+
title={translateString(TranslatableString.AddButton)}
|
|
22
|
+
onClick={onClick}
|
|
23
|
+
disabled={disabled}
|
|
24
|
+
registry={registry}
|
|
25
|
+
/>
|
|
26
|
+
</p>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
4
|
+
props: IconButtonProps<T, S, F>
|
|
5
|
+
) {
|
|
6
|
+
const { iconType = 'default', icon, className, uiSchema, registry, ...otherProps } = props;
|
|
7
|
+
return (
|
|
8
|
+
<button type='button' className={`btn btn-${iconType} ${className}`} {...otherProps}>
|
|
9
|
+
<i className={`glyphicon glyphicon-${icon}`} />
|
|
10
|
+
</button>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
15
|
+
props: IconButtonProps<T, S, F>
|
|
16
|
+
) {
|
|
17
|
+
const {
|
|
18
|
+
registry: { translateString },
|
|
19
|
+
} = props;
|
|
20
|
+
return (
|
|
21
|
+
<IconButton
|
|
22
|
+
title={translateString(TranslatableString.CopyButton)}
|
|
23
|
+
className='array-item-copy'
|
|
24
|
+
{...props}
|
|
25
|
+
icon='copy'
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
31
|
+
props: IconButtonProps<T, S, F>
|
|
32
|
+
) {
|
|
33
|
+
const {
|
|
34
|
+
registry: { translateString },
|
|
35
|
+
} = props;
|
|
36
|
+
return (
|
|
37
|
+
<IconButton
|
|
38
|
+
title={translateString(TranslatableString.MoveDownButton)}
|
|
39
|
+
className='array-item-move-down'
|
|
40
|
+
{...props}
|
|
41
|
+
icon='arrow-down'
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
47
|
+
props: IconButtonProps<T, S, F>
|
|
48
|
+
) {
|
|
49
|
+
const {
|
|
50
|
+
registry: { translateString },
|
|
51
|
+
} = props;
|
|
52
|
+
return (
|
|
53
|
+
<IconButton
|
|
54
|
+
title={translateString(TranslatableString.MoveUpButton)}
|
|
55
|
+
className='array-item-move-up'
|
|
56
|
+
{...props}
|
|
57
|
+
icon='arrow-up'
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
63
|
+
props: IconButtonProps<T, S, F>
|
|
64
|
+
) {
|
|
65
|
+
const {
|
|
66
|
+
registry: { translateString },
|
|
67
|
+
} = props;
|
|
68
|
+
return (
|
|
69
|
+
<IconButton
|
|
70
|
+
title={translateString(TranslatableString.RemoveButton)}
|
|
71
|
+
className='array-item-remove'
|
|
72
|
+
{...props}
|
|
73
|
+
iconType='danger'
|
|
74
|
+
icon='remove'
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getSubmitButtonOptions, FormContextType, RJSFSchema, StrictRJSFSchema, SubmitButtonProps } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
4
|
+
*/
|
|
5
|
+
export default function SubmitButton<
|
|
6
|
+
T = any,
|
|
7
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
8
|
+
F extends FormContextType = any
|
|
9
|
+
>({ uiSchema }: SubmitButtonProps<T, S, F>) {
|
|
10
|
+
const { submitText, norender, props: submitButtonProps = {} } = getSubmitButtonOptions<T, S, F>(uiSchema);
|
|
11
|
+
if (norender) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return (
|
|
15
|
+
<div>
|
|
16
|
+
<button type='submit' {...submitButtonProps} className={`btn btn-info ${submitButtonProps.className || ''}`}>
|
|
17
|
+
{submitText}
|
|
18
|
+
</button>
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import SubmitButton from './SubmitButton';
|
|
4
|
+
import AddButton from './AddButton';
|
|
5
|
+
import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from './IconButton';
|
|
6
|
+
|
|
7
|
+
function buttonTemplates<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any
|
|
11
|
+
>(): TemplatesType<T, S, F>['ButtonTemplates'] {
|
|
12
|
+
return {
|
|
13
|
+
SubmitButton,
|
|
14
|
+
AddButton,
|
|
15
|
+
CopyButton,
|
|
16
|
+
MoveDownButton,
|
|
17
|
+
MoveUpButton,
|
|
18
|
+
RemoveButton,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default buttonTemplates;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `DescriptionField` is the template to use to render the description of a field
|
|
4
|
+
*
|
|
5
|
+
* @param props - The `DescriptionFieldProps` for this component
|
|
6
|
+
*/
|
|
7
|
+
export default function DescriptionField<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any
|
|
11
|
+
>(props: DescriptionFieldProps<T, S, F>) {
|
|
12
|
+
const { id, description } = props;
|
|
13
|
+
if (!description) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof description === 'string') {
|
|
17
|
+
return (
|
|
18
|
+
<p id={id} className='field-description'>
|
|
19
|
+
{description}
|
|
20
|
+
</p>
|
|
21
|
+
);
|
|
22
|
+
} else {
|
|
23
|
+
return (
|
|
24
|
+
<div id={id} className='field-description'>
|
|
25
|
+
{description}
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ErrorListProps,
|
|
3
|
+
FormContextType,
|
|
4
|
+
RJSFValidationError,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
TranslatableString,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
|
|
10
|
+
/** The `ErrorList` component is the template that renders the all the errors associated with the fields in the `Form`
|
|
11
|
+
*
|
|
12
|
+
* @param props - The `ErrorListProps` for this component
|
|
13
|
+
*/
|
|
14
|
+
export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
15
|
+
errors,
|
|
16
|
+
registry,
|
|
17
|
+
}: ErrorListProps<T, S, F>) {
|
|
18
|
+
const { translateString } = registry;
|
|
19
|
+
return (
|
|
20
|
+
<div className='panel panel-danger errors'>
|
|
21
|
+
<div className='panel-heading'>
|
|
22
|
+
<h3 className='panel-title'>{translateString(TranslatableString.ErrorsLabel)}</h3>
|
|
23
|
+
</div>
|
|
24
|
+
<ul className='list-group'>
|
|
25
|
+
{errors.map((error: RJSFValidationError, i: number) => {
|
|
26
|
+
return (
|
|
27
|
+
<li key={i} className='list-group-item text-danger'>
|
|
28
|
+
{error.stack}
|
|
29
|
+
</li>
|
|
30
|
+
);
|
|
31
|
+
})}
|
|
32
|
+
</ul>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|