@rjsf/react-bootstrap 6.0.0-alpha.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/LICENSE.md +201 -0
- package/README.md +111 -0
- package/dist/index.js +940 -0
- package/dist/index.js.map +7 -0
- package/dist/react-bootstrap.esm.js +948 -0
- package/dist/react-bootstrap.esm.js.map +7 -0
- package/dist/react-bootstrap.umd.js +804 -0
- package/lib/AddButton/AddButton.d.ts +2 -0
- package/lib/AddButton/AddButton.js +9 -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/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +2 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +15 -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 +2 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +17 -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 +2 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js +19 -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/CheckboxWidget/CheckboxWidget.d.ts +2 -0
- package/lib/CheckboxWidget/CheckboxWidget.js +17 -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 +2 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js +24 -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/DescriptionField/DescriptionField.d.ts +2 -0
- package/lib/DescriptionField/DescriptionField.js +8 -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 +2 -0
- package/lib/ErrorList/ErrorList.js +11 -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 +6 -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 +6 -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 +2 -0
- package/lib/FieldTemplate/FieldTemplate.js +12 -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/IconButton.d.ts +7 -0
- package/lib/IconButton/IconButton.js +28 -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 +2 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +14 -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 +2 -0
- package/lib/RadioWidget/RadioWidget.js +18 -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 +2 -0
- package/lib/RangeWidget/RangeWidget.js +21 -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 +2 -0
- package/lib/SelectWidget/SelectWidget.js +36 -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 +2 -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 +6 -0
- package/lib/TextareaWidget/TextareaWidget.js +11 -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 +2 -0
- package/lib/TitleField/TitleField.js +7 -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/Widgets/Widgets.d.ts +4 -0
- package/lib/Widgets/Widgets.js +18 -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 +2 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +19 -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 +6 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +98 -0
- package/src/AddButton/AddButton.tsx +21 -0
- package/src/AddButton/index.ts +2 -0
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +94 -0
- package/src/ArrayFieldItemTemplate/index.ts +2 -0
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +86 -0
- package/src/ArrayFieldTemplate/index.ts +2 -0
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +77 -0
- package/src/BaseInputTemplate/index.ts +2 -0
- package/src/CheckboxWidget/CheckboxWidget.tsx +80 -0
- package/src/CheckboxWidget/index.ts +2 -0
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +68 -0
- package/src/CheckboxesWidget/index.ts +2 -0
- package/src/DescriptionField/DescriptionField.tsx +19 -0
- package/src/DescriptionField/index.ts +2 -0
- package/src/ErrorList/ErrorList.tsx +27 -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 +23 -0
- package/src/FieldHelpTemplate/index.ts +2 -0
- package/src/FieldTemplate/FieldTemplate.tsx +77 -0
- package/src/FieldTemplate/index.ts +2 -0
- package/src/Form/Form.tsx +15 -0
- package/src/Form/index.ts +2 -0
- package/src/IconButton/IconButton.tsx +62 -0
- package/src/IconButton/index.ts +2 -0
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +89 -0
- package/src/ObjectFieldTemplate/index.ts +2 -0
- package/src/RadioWidget/RadioWidget.tsx +65 -0
- package/src/RadioWidget/index.ts +2 -0
- package/src/RangeWidget/RangeWidget.tsx +31 -0
- package/src/RangeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +91 -0
- package/src/SelectWidget/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +18 -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 +56 -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 +15 -0
- package/src/TitleField/index.ts +2 -0
- package/src/Widgets/Widgets.ts +24 -0
- package/src/Widgets/index.ts +2 -0
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +79 -0
- package/src/WrapIfAdditionalTemplate/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/tsconfig.json +23 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { FocusEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
descriptionId,
|
|
5
|
+
getTemplate,
|
|
6
|
+
labelValue,
|
|
7
|
+
WidgetProps,
|
|
8
|
+
schemaRequiresTrueValue,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
RJSFSchema,
|
|
11
|
+
FormContextType,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
import Form from 'react-bootstrap/Form';
|
|
14
|
+
|
|
15
|
+
export default function CheckboxWidget<
|
|
16
|
+
T = any,
|
|
17
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
18
|
+
F extends FormContextType = any
|
|
19
|
+
>(props: WidgetProps<T, S, F>) {
|
|
20
|
+
const {
|
|
21
|
+
id,
|
|
22
|
+
value,
|
|
23
|
+
disabled,
|
|
24
|
+
readonly,
|
|
25
|
+
label,
|
|
26
|
+
hideLabel,
|
|
27
|
+
schema,
|
|
28
|
+
autofocus,
|
|
29
|
+
options,
|
|
30
|
+
onChange,
|
|
31
|
+
onBlur,
|
|
32
|
+
onFocus,
|
|
33
|
+
registry,
|
|
34
|
+
uiSchema,
|
|
35
|
+
} = props;
|
|
36
|
+
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
37
|
+
// the "required" attribute if the field value must be "true", due to the
|
|
38
|
+
// "const" or "enum" keywords
|
|
39
|
+
const required = schemaRequiresTrueValue<S>(schema);
|
|
40
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
41
|
+
'DescriptionFieldTemplate',
|
|
42
|
+
registry,
|
|
43
|
+
options
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const _onChange = ({ target: { checked } }: FocusEvent<HTMLInputElement>) => onChange(checked);
|
|
47
|
+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.checked);
|
|
48
|
+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.checked);
|
|
49
|
+
|
|
50
|
+
const description = options.description || schema.description;
|
|
51
|
+
return (
|
|
52
|
+
<Form.Group
|
|
53
|
+
className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}
|
|
54
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
55
|
+
>
|
|
56
|
+
{!hideLabel && !!description && (
|
|
57
|
+
<DescriptionFieldTemplate
|
|
58
|
+
id={descriptionId<T>(id)}
|
|
59
|
+
description={description}
|
|
60
|
+
schema={schema}
|
|
61
|
+
uiSchema={uiSchema}
|
|
62
|
+
registry={registry}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
65
|
+
<Form.Check
|
|
66
|
+
id={id}
|
|
67
|
+
name={id}
|
|
68
|
+
label={labelValue(label, hideLabel || !label)}
|
|
69
|
+
checked={typeof value === 'undefined' ? false : value}
|
|
70
|
+
required={required}
|
|
71
|
+
disabled={disabled || readonly}
|
|
72
|
+
autoFocus={autofocus}
|
|
73
|
+
onChange={_onChange}
|
|
74
|
+
type='checkbox'
|
|
75
|
+
onBlur={_onBlur}
|
|
76
|
+
onFocus={_onFocus}
|
|
77
|
+
/>
|
|
78
|
+
</Form.Group>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent } from 'react';
|
|
2
|
+
import Form from 'react-bootstrap/Form';
|
|
3
|
+
import {
|
|
4
|
+
ariaDescribedByIds,
|
|
5
|
+
enumOptionsDeselectValue,
|
|
6
|
+
enumOptionsIsSelected,
|
|
7
|
+
enumOptionsSelectValue,
|
|
8
|
+
enumOptionsValueForIndex,
|
|
9
|
+
optionId,
|
|
10
|
+
FormContextType,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
WidgetProps,
|
|
14
|
+
} from '@rjsf/utils';
|
|
15
|
+
|
|
16
|
+
export default function CheckboxesWidget<
|
|
17
|
+
T = any,
|
|
18
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
|
+
F extends FormContextType = any
|
|
20
|
+
>({ id, disabled, options, value, autofocus, readonly, required, onChange, onBlur, onFocus }: WidgetProps<T, S, F>) {
|
|
21
|
+
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
22
|
+
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
23
|
+
|
|
24
|
+
const _onChange =
|
|
25
|
+
(index: number) =>
|
|
26
|
+
({ target: { checked } }: ChangeEvent<HTMLInputElement>) => {
|
|
27
|
+
if (checked) {
|
|
28
|
+
onChange(enumOptionsSelectValue<S>(index, checkboxesValues, enumOptions));
|
|
29
|
+
} else {
|
|
30
|
+
onChange(enumOptionsDeselectValue<S>(index, checkboxesValues, enumOptions));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
|
|
35
|
+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
36
|
+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
|
|
37
|
+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Form.Group>
|
|
41
|
+
{Array.isArray(enumOptions) &&
|
|
42
|
+
enumOptions.map((option, index: number) => {
|
|
43
|
+
const checked = enumOptionsIsSelected<S>(option.value, checkboxesValues);
|
|
44
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Form.Check
|
|
48
|
+
key={option.value}
|
|
49
|
+
inline={inline}
|
|
50
|
+
required={required}
|
|
51
|
+
checked={checked}
|
|
52
|
+
className='bg-transparent border-0'
|
|
53
|
+
type={'checkbox'}
|
|
54
|
+
id={optionId(id, index)}
|
|
55
|
+
name={id}
|
|
56
|
+
label={option.label}
|
|
57
|
+
autoFocus={autofocus && index === 0}
|
|
58
|
+
onChange={_onChange(index)}
|
|
59
|
+
onBlur={_onBlur}
|
|
60
|
+
onFocus={_onFocus}
|
|
61
|
+
disabled={disabled || itemDisabled || readonly}
|
|
62
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
})}
|
|
66
|
+
</Form.Group>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
export default function DescriptionField<
|
|
4
|
+
T = any,
|
|
5
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
6
|
+
F extends FormContextType = any
|
|
7
|
+
>({ id, description }: DescriptionFieldProps<T, S, F>) {
|
|
8
|
+
if (description) {
|
|
9
|
+
return (
|
|
10
|
+
<div>
|
|
11
|
+
<div id={id} className='mb-3'>
|
|
12
|
+
{description}
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Card from 'react-bootstrap/Card';
|
|
2
|
+
import ListGroup from 'react-bootstrap/ListGroup';
|
|
3
|
+
|
|
4
|
+
import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
5
|
+
|
|
6
|
+
export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
7
|
+
errors,
|
|
8
|
+
registry,
|
|
9
|
+
}: ErrorListProps<T, S, F>) {
|
|
10
|
+
const { translateString } = registry;
|
|
11
|
+
return (
|
|
12
|
+
<Card border='danger' className='mb-4'>
|
|
13
|
+
<Card.Header className='alert-danger'>{translateString(TranslatableString.ErrorsLabel)}</Card.Header>
|
|
14
|
+
<Card.Body className='p-0'>
|
|
15
|
+
<ListGroup>
|
|
16
|
+
{errors.map((error, i: number) => {
|
|
17
|
+
return (
|
|
18
|
+
<ListGroup.Item key={i} className='border-0'>
|
|
19
|
+
<span>{error.stack}</span>
|
|
20
|
+
</ListGroup.Item>
|
|
21
|
+
);
|
|
22
|
+
})}
|
|
23
|
+
</ListGroup>
|
|
24
|
+
</Card.Body>
|
|
25
|
+
</Card>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema, errorId } from '@rjsf/utils';
|
|
2
|
+
import ListGroup from 'react-bootstrap/ListGroup';
|
|
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
|
+
<ListGroup as='ul' id={id}>
|
|
21
|
+
{errors.map((error, i) => {
|
|
22
|
+
return (
|
|
23
|
+
<ListGroup.Item as='li' key={i} className='border-0 m-0 p-0'>
|
|
24
|
+
<small className='m-0 text-danger'>{error}</small>
|
|
25
|
+
</ListGroup.Item>
|
|
26
|
+
);
|
|
27
|
+
})}
|
|
28
|
+
</ListGroup>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema, helpId } from '@rjsf/utils';
|
|
2
|
+
import Form from 'react-bootstrap/Form';
|
|
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, hasErrors } = props;
|
|
14
|
+
if (!help) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const id = helpId<T>(idSchema);
|
|
18
|
+
return (
|
|
19
|
+
<Form.Text className={hasErrors ? 'text-danger' : 'text-muted'} id={id}>
|
|
20
|
+
{help}
|
|
21
|
+
</Form.Text>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldTemplateProps,
|
|
3
|
+
FormContextType,
|
|
4
|
+
getTemplate,
|
|
5
|
+
getUiOptions,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
import Form from 'react-bootstrap/Form';
|
|
10
|
+
|
|
11
|
+
export default function FieldTemplate<
|
|
12
|
+
T = any,
|
|
13
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
14
|
+
F extends FormContextType = any
|
|
15
|
+
>({
|
|
16
|
+
id,
|
|
17
|
+
children,
|
|
18
|
+
displayLabel,
|
|
19
|
+
rawErrors = [],
|
|
20
|
+
errors,
|
|
21
|
+
help,
|
|
22
|
+
description,
|
|
23
|
+
rawDescription,
|
|
24
|
+
classNames,
|
|
25
|
+
style,
|
|
26
|
+
disabled,
|
|
27
|
+
label,
|
|
28
|
+
hidden,
|
|
29
|
+
onDropPropertyClick,
|
|
30
|
+
onKeyChange,
|
|
31
|
+
readonly,
|
|
32
|
+
required,
|
|
33
|
+
schema,
|
|
34
|
+
uiSchema,
|
|
35
|
+
registry,
|
|
36
|
+
}: FieldTemplateProps<T, S, F>) {
|
|
37
|
+
const uiOptions = getUiOptions(uiSchema);
|
|
38
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
39
|
+
'WrapIfAdditionalTemplate',
|
|
40
|
+
registry,
|
|
41
|
+
uiOptions
|
|
42
|
+
);
|
|
43
|
+
if (hidden) {
|
|
44
|
+
return <div className='hidden'>{children}</div>;
|
|
45
|
+
}
|
|
46
|
+
return (
|
|
47
|
+
<WrapIfAdditionalTemplate
|
|
48
|
+
classNames={classNames}
|
|
49
|
+
style={style}
|
|
50
|
+
disabled={disabled}
|
|
51
|
+
id={id}
|
|
52
|
+
label={label}
|
|
53
|
+
onDropPropertyClick={onDropPropertyClick}
|
|
54
|
+
onKeyChange={onKeyChange}
|
|
55
|
+
readonly={readonly}
|
|
56
|
+
required={required}
|
|
57
|
+
schema={schema}
|
|
58
|
+
uiSchema={uiSchema}
|
|
59
|
+
registry={registry}
|
|
60
|
+
>
|
|
61
|
+
<Form.Group>
|
|
62
|
+
{displayLabel && (
|
|
63
|
+
<Form.Label htmlFor={id} className={rawErrors.length > 0 ? 'text-danger' : ''}>
|
|
64
|
+
{label}
|
|
65
|
+
{required ? '*' : null}
|
|
66
|
+
</Form.Label>
|
|
67
|
+
)}
|
|
68
|
+
{children}
|
|
69
|
+
{displayLabel && rawDescription && (
|
|
70
|
+
<Form.Text className={rawErrors.length > 0 ? 'text-danger' : 'text-muted'}>{description}</Form.Text>
|
|
71
|
+
)}
|
|
72
|
+
{errors}
|
|
73
|
+
{help}
|
|
74
|
+
</Form.Group>
|
|
75
|
+
</WrapIfAdditionalTemplate>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import { withTheme, FormProps } from '@rjsf/core';
|
|
4
|
+
import { generateTheme } from '../Theme';
|
|
5
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
6
|
+
|
|
7
|
+
export function generateForm<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any
|
|
11
|
+
>(): ComponentType<FormProps<T, S, F>> {
|
|
12
|
+
return withTheme<T, S, F>(generateTheme<T, S, F>());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default generateForm();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
2
|
+
import Button, { ButtonProps } from 'react-bootstrap/Button';
|
|
3
|
+
import { IoIosCopy } from '@react-icons/all-files/io/IoIosCopy';
|
|
4
|
+
import { IoIosRemove } from '@react-icons/all-files/io/IoIosRemove';
|
|
5
|
+
import { AiOutlineArrowUp } from '@react-icons/all-files/ai/AiOutlineArrowUp';
|
|
6
|
+
import { AiOutlineArrowDown } from '@react-icons/all-files/ai/AiOutlineArrowDown';
|
|
7
|
+
|
|
8
|
+
export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
9
|
+
props: IconButtonProps<T, S, F> & ButtonProps
|
|
10
|
+
) {
|
|
11
|
+
const { icon, iconType, className, uiSchema, registry, ...otherProps } = props;
|
|
12
|
+
return (
|
|
13
|
+
<Button {...otherProps} variant={props.variant || 'light'} size='sm'>
|
|
14
|
+
{icon}
|
|
15
|
+
</Button>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
20
|
+
props: IconButtonProps<T, S, F>
|
|
21
|
+
) {
|
|
22
|
+
const {
|
|
23
|
+
registry: { translateString },
|
|
24
|
+
} = props;
|
|
25
|
+
return <IconButton title={translateString(TranslatableString.CopyButton)} {...props} icon={<IoIosCopy />} />;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
29
|
+
props: IconButtonProps<T, S, F>
|
|
30
|
+
) {
|
|
31
|
+
const {
|
|
32
|
+
registry: { translateString },
|
|
33
|
+
} = props;
|
|
34
|
+
return (
|
|
35
|
+
<IconButton title={translateString(TranslatableString.MoveDownButton)} {...props} icon={<AiOutlineArrowDown />} />
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
40
|
+
props: IconButtonProps<T, S, F>
|
|
41
|
+
) {
|
|
42
|
+
const {
|
|
43
|
+
registry: { translateString },
|
|
44
|
+
} = props;
|
|
45
|
+
return <IconButton title={translateString(TranslatableString.MoveUpButton)} {...props} icon={<AiOutlineArrowUp />} />;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
49
|
+
props: IconButtonProps<T, S, F>
|
|
50
|
+
) {
|
|
51
|
+
const {
|
|
52
|
+
registry: { translateString },
|
|
53
|
+
} = props;
|
|
54
|
+
return (
|
|
55
|
+
<IconButton
|
|
56
|
+
title={translateString(TranslatableString.RemoveButton)}
|
|
57
|
+
{...props}
|
|
58
|
+
variant='danger'
|
|
59
|
+
icon={<IoIosRemove />}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Row from 'react-bootstrap/Row';
|
|
2
|
+
import Col from 'react-bootstrap/Col';
|
|
3
|
+
import Container from 'react-bootstrap/Container';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
canExpand,
|
|
7
|
+
descriptionId,
|
|
8
|
+
FormContextType,
|
|
9
|
+
getTemplate,
|
|
10
|
+
getUiOptions,
|
|
11
|
+
ObjectFieldTemplateProps,
|
|
12
|
+
RJSFSchema,
|
|
13
|
+
StrictRJSFSchema,
|
|
14
|
+
titleId,
|
|
15
|
+
} from '@rjsf/utils';
|
|
16
|
+
|
|
17
|
+
export default function ObjectFieldTemplate<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any
|
|
21
|
+
>({
|
|
22
|
+
description,
|
|
23
|
+
title,
|
|
24
|
+
properties,
|
|
25
|
+
required,
|
|
26
|
+
uiSchema,
|
|
27
|
+
idSchema,
|
|
28
|
+
schema,
|
|
29
|
+
formData,
|
|
30
|
+
onAddClick,
|
|
31
|
+
disabled,
|
|
32
|
+
readonly,
|
|
33
|
+
registry,
|
|
34
|
+
}: ObjectFieldTemplateProps<T, S, F>) {
|
|
35
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
36
|
+
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, uiOptions);
|
|
37
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
38
|
+
'DescriptionFieldTemplate',
|
|
39
|
+
registry,
|
|
40
|
+
uiOptions
|
|
41
|
+
);
|
|
42
|
+
// Button templates are not overridden in the uiSchema
|
|
43
|
+
const {
|
|
44
|
+
ButtonTemplates: { AddButton },
|
|
45
|
+
} = registry.templates;
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
{title && (
|
|
49
|
+
<TitleFieldTemplate
|
|
50
|
+
id={titleId<T>(idSchema)}
|
|
51
|
+
title={title}
|
|
52
|
+
required={required}
|
|
53
|
+
schema={schema}
|
|
54
|
+
uiSchema={uiSchema}
|
|
55
|
+
registry={registry}
|
|
56
|
+
/>
|
|
57
|
+
)}
|
|
58
|
+
{description && (
|
|
59
|
+
<DescriptionFieldTemplate
|
|
60
|
+
id={descriptionId<T>(idSchema)}
|
|
61
|
+
description={description}
|
|
62
|
+
schema={schema}
|
|
63
|
+
uiSchema={uiSchema}
|
|
64
|
+
registry={registry}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
<Container fluid className='p-0'>
|
|
68
|
+
{properties.map((element: any, index: number) => (
|
|
69
|
+
<Row key={index} style={{ marginBottom: '10px' }} className={element.hidden ? 'd-none' : undefined}>
|
|
70
|
+
<Col xs={12}> {element.content}</Col>
|
|
71
|
+
</Row>
|
|
72
|
+
))}
|
|
73
|
+
{canExpand(schema, uiSchema, formData) ? (
|
|
74
|
+
<Row>
|
|
75
|
+
<Col xs={{ offset: 9, span: 3 }} className='py-4'>
|
|
76
|
+
<AddButton
|
|
77
|
+
onClick={onAddClick(schema)}
|
|
78
|
+
disabled={disabled || readonly}
|
|
79
|
+
className='object-property-expand'
|
|
80
|
+
uiSchema={uiSchema}
|
|
81
|
+
registry={registry}
|
|
82
|
+
/>
|
|
83
|
+
</Col>
|
|
84
|
+
</Row>
|
|
85
|
+
) : null}
|
|
86
|
+
</Container>
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent } from 'react';
|
|
2
|
+
import Form from 'react-bootstrap/Form';
|
|
3
|
+
import {
|
|
4
|
+
ariaDescribedByIds,
|
|
5
|
+
enumOptionsIsSelected,
|
|
6
|
+
enumOptionsValueForIndex,
|
|
7
|
+
optionId,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
WidgetProps,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
|
|
14
|
+
export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
15
|
+
id,
|
|
16
|
+
options,
|
|
17
|
+
value,
|
|
18
|
+
required,
|
|
19
|
+
disabled,
|
|
20
|
+
readonly,
|
|
21
|
+
onChange,
|
|
22
|
+
onBlur,
|
|
23
|
+
onFocus,
|
|
24
|
+
}: WidgetProps<T, S, F>) {
|
|
25
|
+
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
26
|
+
|
|
27
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
28
|
+
onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
29
|
+
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
|
|
30
|
+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
31
|
+
const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
|
|
32
|
+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
33
|
+
|
|
34
|
+
const inline = Boolean(options && options.inline);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Form.Group className='mb-0'>
|
|
38
|
+
{Array.isArray(enumOptions) &&
|
|
39
|
+
enumOptions.map((option, index) => {
|
|
40
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
41
|
+
const checked = enumOptionsIsSelected<S>(option.value, value);
|
|
42
|
+
|
|
43
|
+
const radio = (
|
|
44
|
+
<Form.Check
|
|
45
|
+
inline={inline}
|
|
46
|
+
label={option.label}
|
|
47
|
+
id={optionId(id, index)}
|
|
48
|
+
key={index}
|
|
49
|
+
name={id}
|
|
50
|
+
type='radio'
|
|
51
|
+
disabled={disabled || itemDisabled || readonly}
|
|
52
|
+
checked={checked}
|
|
53
|
+
required={required}
|
|
54
|
+
value={String(index)}
|
|
55
|
+
onChange={_onChange}
|
|
56
|
+
onBlur={_onBlur}
|
|
57
|
+
onFocus={_onFocus}
|
|
58
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
return radio;
|
|
62
|
+
})}
|
|
63
|
+
</Form.Group>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FormContextType, rangeSpec, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils';
|
|
2
|
+
import { ChangeEvent, FocusEvent } from 'react';
|
|
3
|
+
import FormRange from 'react-bootstrap/FormRange';
|
|
4
|
+
|
|
5
|
+
export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
6
|
+
props: WidgetProps<T, S, F>
|
|
7
|
+
) {
|
|
8
|
+
const { id, value, disabled, onChange, onBlur, onFocus, schema } = props;
|
|
9
|
+
|
|
10
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => onChange(value);
|
|
11
|
+
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value);
|
|
12
|
+
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value);
|
|
13
|
+
|
|
14
|
+
const rangeProps = {
|
|
15
|
+
value,
|
|
16
|
+
id,
|
|
17
|
+
name: id,
|
|
18
|
+
disabled,
|
|
19
|
+
onChange: _onChange,
|
|
20
|
+
onBlur: _onBlur,
|
|
21
|
+
onFocus: _onFocus,
|
|
22
|
+
...rangeSpec<S>(schema),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
<FormRange {...rangeProps} />
|
|
28
|
+
<span className='range-view'>{value}</span>
|
|
29
|
+
</>
|
|
30
|
+
);
|
|
31
|
+
}
|