@rjsf/semantic-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/index.js +1128 -5
- package/dist/index.js.map +7 -0
- package/dist/semantic-ui.esm.js +641 -809
- package/dist/semantic-ui.esm.js.map +7 -1
- package/dist/semantic-ui.umd.js +997 -0
- package/lib/AddButton/AddButton.d.ts +5 -0
- package/lib/AddButton/AddButton.js +12 -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 +7 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +21 -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 +7 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +40 -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 +9 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.js +28 -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 +8 -0
- package/lib/CheckboxWidget/CheckboxWidget.js +33 -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 +8 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js +42 -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 +7 -0
- package/lib/DescriptionField/DescriptionField.js +13 -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 +7 -0
- package/lib/ErrorList/ErrorList.js +12 -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 +30 -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 +8 -0
- package/lib/FieldTemplate/FieldTemplate.js +22 -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/IconButton/IconButton.d.ts +8 -0
- package/lib/IconButton/IconButton.js +26 -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 +9 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +23 -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 +8 -0
- package/lib/RadioWidget/RadioWidget.js +32 -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 +8 -0
- package/lib/RangeWidget/RangeWidget.js +26 -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 +8 -0
- package/lib/SelectWidget/SelectWidget.js +51 -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/SemanticUIForm/SemanticUIForm.d.ts +6 -0
- package/lib/SemanticUIForm/SemanticUIForm.js +7 -0
- package/lib/SemanticUIForm/SemanticUIForm.js.map +1 -0
- package/lib/SemanticUIForm/index.d.ts +2 -0
- package/lib/SemanticUIForm/index.js +3 -0
- package/lib/SemanticUIForm/index.js.map +1 -0
- package/lib/SubmitButton/SubmitButton.d.ts +5 -0
- package/lib/SubmitButton/SubmitButton.js +13 -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 +7 -0
- package/lib/TextareaWidget/TextareaWidget.js +22 -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 +12 -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 +7 -0
- package/lib/TitleField/TitleField.js +22 -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 +8 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +23 -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/util.d.ts +60 -0
- package/lib/util.js +69 -0
- package/lib/util.js.map +1 -0
- package/package.json +23 -15
- package/src/AddButton/AddButton.tsx +24 -0
- package/src/AddButton/index.ts +2 -0
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +102 -0
- package/src/ArrayFieldItemTemplate/index.ts +2 -0
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +114 -0
- package/src/ArrayFieldTemplate/index.ts +2 -0
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +90 -0
- package/src/BaseInputTemplate/index.ts +2 -0
- package/src/CheckboxWidget/CheckboxWidget.tsx +95 -0
- package/src/CheckboxWidget/index.ts +2 -0
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +102 -0
- package/src/CheckboxesWidget/index.ts +2 -0
- package/src/DescriptionField/DescriptionField.tsx +21 -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 +43 -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 +77 -0
- package/src/FieldTemplate/index.ts +2 -0
- package/src/IconButton/IconButton.tsx +55 -0
- package/src/IconButton/index.ts +2 -0
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +94 -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 +65 -0
- package/src/RangeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +111 -0
- package/src/SelectWidget/index.ts +2 -0
- package/src/SemanticUIForm/SemanticUIForm.ts +15 -0
- package/src/SemanticUIForm/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +20 -0
- package/src/SubmitButton/index.ts +2 -0
- package/src/Templates/Templates.ts +46 -0
- package/src/Templates/index.ts +2 -0
- package/src/TextareaWidget/TextareaWidget.tsx +69 -0
- package/src/TextareaWidget/index.ts +2 -0
- package/src/Theme/Theme.ts +20 -0
- package/src/Theme/index.ts +2 -0
- package/src/TitleField/TitleField.tsx +32 -0
- package/src/TitleField/index.ts +2 -0
- package/src/Widgets/Widgets.tsx +25 -0
- package/src/Widgets/index.ts +2 -0
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +95 -0
- package/src/WrapIfAdditionalTemplate/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/util.tsx +126 -0
- package/dist/index.d.ts +0 -17
- package/dist/semantic-ui.cjs.development.js +0 -1335
- package/dist/semantic-ui.cjs.development.js.map +0 -1
- package/dist/semantic-ui.cjs.production.min.js +0 -2
- package/dist/semantic-ui.cjs.production.min.js.map +0 -1
- package/dist/semantic-ui.umd.development.js +0 -1333
- package/dist/semantic-ui.umd.development.js.map +0 -1
- package/dist/semantic-ui.umd.production.min.js +0 -2
- package/dist/semantic-ui.umd.production.min.js.map +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { Form } from 'semantic-ui-react';
|
|
3
|
+
import { getSemanticProps } from '../util';
|
|
4
|
+
import {
|
|
5
|
+
ariaDescribedByIds,
|
|
6
|
+
BaseInputTemplateProps,
|
|
7
|
+
examplesId,
|
|
8
|
+
getInputProps,
|
|
9
|
+
labelValue,
|
|
10
|
+
FormContextType,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
} from '@rjsf/utils';
|
|
14
|
+
|
|
15
|
+
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
16
|
+
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
17
|
+
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this template
|
|
20
|
+
*/
|
|
21
|
+
export default function BaseInputTemplate<
|
|
22
|
+
T = any,
|
|
23
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
24
|
+
F extends FormContextType = any
|
|
25
|
+
>(props: BaseInputTemplateProps<T, S, F>) {
|
|
26
|
+
const {
|
|
27
|
+
id,
|
|
28
|
+
placeholder,
|
|
29
|
+
label,
|
|
30
|
+
hideLabel,
|
|
31
|
+
value,
|
|
32
|
+
required,
|
|
33
|
+
readonly,
|
|
34
|
+
disabled,
|
|
35
|
+
onChange,
|
|
36
|
+
onChangeOverride,
|
|
37
|
+
onBlur,
|
|
38
|
+
onFocus,
|
|
39
|
+
autofocus,
|
|
40
|
+
options,
|
|
41
|
+
schema,
|
|
42
|
+
uiSchema,
|
|
43
|
+
formContext,
|
|
44
|
+
type,
|
|
45
|
+
rawErrors = [],
|
|
46
|
+
} = props;
|
|
47
|
+
const inputProps = getInputProps<T, S, F>(schema, type, options);
|
|
48
|
+
const semanticProps = getSemanticProps<T, S, F>({
|
|
49
|
+
uiSchema,
|
|
50
|
+
formContext,
|
|
51
|
+
options,
|
|
52
|
+
});
|
|
53
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
54
|
+
onChange(value === '' ? options.emptyValue : value);
|
|
55
|
+
const _onBlur = () => onBlur && onBlur(id, value);
|
|
56
|
+
const _onFocus = () => onFocus && onFocus(id, value);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<>
|
|
60
|
+
<Form.Input
|
|
61
|
+
key={id}
|
|
62
|
+
id={id}
|
|
63
|
+
name={id}
|
|
64
|
+
placeholder={placeholder}
|
|
65
|
+
{...inputProps}
|
|
66
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
67
|
+
required={required}
|
|
68
|
+
autoFocus={autofocus}
|
|
69
|
+
disabled={disabled || readonly}
|
|
70
|
+
list={schema.examples ? examplesId<T>(id) : undefined}
|
|
71
|
+
{...semanticProps}
|
|
72
|
+
value={value || value === 0 ? value : ''}
|
|
73
|
+
error={rawErrors.length > 0}
|
|
74
|
+
onChange={onChangeOverride || _onChange}
|
|
75
|
+
onBlur={_onBlur}
|
|
76
|
+
onFocus={_onFocus}
|
|
77
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
78
|
+
/>
|
|
79
|
+
{Array.isArray(schema.examples) && (
|
|
80
|
+
<datalist id={examplesId<T>(id)}>
|
|
81
|
+
{(schema.examples as string[])
|
|
82
|
+
.concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
|
|
83
|
+
.map((example) => {
|
|
84
|
+
return <option key={example} value={example} />;
|
|
85
|
+
})}
|
|
86
|
+
</datalist>
|
|
87
|
+
)}
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { FormEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
descriptionId,
|
|
5
|
+
getTemplate,
|
|
6
|
+
labelValue,
|
|
7
|
+
schemaRequiresTrueValue,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
WidgetProps,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
import { Form, CheckboxProps } from 'semantic-ui-react';
|
|
14
|
+
import { getSemanticProps } from '../util';
|
|
15
|
+
|
|
16
|
+
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
|
|
17
|
+
* It is typically used to represent a boolean.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this component
|
|
20
|
+
*/
|
|
21
|
+
export default function CheckboxWidget<
|
|
22
|
+
T = any,
|
|
23
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
24
|
+
F extends FormContextType = any
|
|
25
|
+
>(props: WidgetProps<T, S, F>) {
|
|
26
|
+
const {
|
|
27
|
+
id,
|
|
28
|
+
value,
|
|
29
|
+
disabled,
|
|
30
|
+
readonly,
|
|
31
|
+
label = '',
|
|
32
|
+
hideLabel,
|
|
33
|
+
autofocus,
|
|
34
|
+
onChange,
|
|
35
|
+
onBlur,
|
|
36
|
+
options,
|
|
37
|
+
onFocus,
|
|
38
|
+
formContext,
|
|
39
|
+
schema,
|
|
40
|
+
uiSchema,
|
|
41
|
+
rawErrors = [],
|
|
42
|
+
registry,
|
|
43
|
+
} = props;
|
|
44
|
+
const semanticProps = getSemanticProps<T, S, F>({
|
|
45
|
+
options,
|
|
46
|
+
formContext,
|
|
47
|
+
uiSchema,
|
|
48
|
+
defaultSchemaProps: {
|
|
49
|
+
inverted: 'false',
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
53
|
+
'DescriptionFieldTemplate',
|
|
54
|
+
registry,
|
|
55
|
+
options
|
|
56
|
+
);
|
|
57
|
+
// Because an unchecked checkbox will cause html5 validation to fail, only add
|
|
58
|
+
// the "required" attribute if the field value must be "true", due to the
|
|
59
|
+
// "const" or "enum" keywords
|
|
60
|
+
const required = schemaRequiresTrueValue<S>(schema);
|
|
61
|
+
const _onChange = (_: FormEvent<HTMLInputElement>, data: CheckboxProps) => onChange && onChange(data.checked);
|
|
62
|
+
const _onBlur = () => onBlur && onBlur(id, value);
|
|
63
|
+
const _onFocus = () => onFocus && onFocus(id, value);
|
|
64
|
+
const checked = value == 'true' || value == true;
|
|
65
|
+
const description = options.description ?? schema.description;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
{!hideLabel && !!description && (
|
|
70
|
+
<DescriptionFieldTemplate
|
|
71
|
+
id={descriptionId<T>(id)}
|
|
72
|
+
description={description}
|
|
73
|
+
schema={schema}
|
|
74
|
+
uiSchema={uiSchema}
|
|
75
|
+
registry={registry}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
<Form.Checkbox
|
|
79
|
+
id={id}
|
|
80
|
+
name={id}
|
|
81
|
+
disabled={disabled || readonly}
|
|
82
|
+
autoFocus={autofocus}
|
|
83
|
+
{...semanticProps}
|
|
84
|
+
checked={typeof value === 'undefined' ? false : checked}
|
|
85
|
+
error={rawErrors.length > 0}
|
|
86
|
+
onChange={_onChange}
|
|
87
|
+
onBlur={_onBlur}
|
|
88
|
+
onFocus={_onFocus}
|
|
89
|
+
required={required}
|
|
90
|
+
label={labelValue(label, hideLabel, false)}
|
|
91
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
92
|
+
/>
|
|
93
|
+
</>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import { Form } from 'semantic-ui-react';
|
|
3
|
+
import {
|
|
4
|
+
ariaDescribedByIds,
|
|
5
|
+
enumOptionsDeselectValue,
|
|
6
|
+
enumOptionsIsSelected,
|
|
7
|
+
enumOptionsSelectValue,
|
|
8
|
+
getTemplate,
|
|
9
|
+
optionId,
|
|
10
|
+
titleId,
|
|
11
|
+
FormContextType,
|
|
12
|
+
RJSFSchema,
|
|
13
|
+
StrictRJSFSchema,
|
|
14
|
+
WidgetProps,
|
|
15
|
+
} from '@rjsf/utils';
|
|
16
|
+
import { getSemanticProps } from '../util';
|
|
17
|
+
|
|
18
|
+
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
|
|
19
|
+
* It is typically used to represent an array of enums.
|
|
20
|
+
*
|
|
21
|
+
* @param props - The `WidgetProps` for this component
|
|
22
|
+
*/
|
|
23
|
+
export default function CheckboxesWidget<
|
|
24
|
+
T = any,
|
|
25
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
26
|
+
F extends FormContextType = any
|
|
27
|
+
>(props: WidgetProps<T, S, F>) {
|
|
28
|
+
const {
|
|
29
|
+
id,
|
|
30
|
+
disabled,
|
|
31
|
+
options,
|
|
32
|
+
value,
|
|
33
|
+
autofocus,
|
|
34
|
+
readonly,
|
|
35
|
+
label,
|
|
36
|
+
hideLabel,
|
|
37
|
+
onChange,
|
|
38
|
+
onBlur,
|
|
39
|
+
onFocus,
|
|
40
|
+
formContext,
|
|
41
|
+
schema,
|
|
42
|
+
uiSchema,
|
|
43
|
+
rawErrors = [],
|
|
44
|
+
registry,
|
|
45
|
+
} = props;
|
|
46
|
+
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, options);
|
|
47
|
+
const { enumOptions, enumDisabled, inline } = options;
|
|
48
|
+
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
49
|
+
const semanticProps = getSemanticProps<T, S, F>({
|
|
50
|
+
options,
|
|
51
|
+
formContext,
|
|
52
|
+
uiSchema,
|
|
53
|
+
defaultSchemaProps: {
|
|
54
|
+
inverted: 'false',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const _onChange =
|
|
58
|
+
(index: number) =>
|
|
59
|
+
({ target: { checked } }: ChangeEvent<HTMLInputElement>) => {
|
|
60
|
+
// eslint-disable-next-line no-shadow
|
|
61
|
+
if (checked) {
|
|
62
|
+
onChange(enumOptionsSelectValue<S>(index, checkboxesValues, enumOptions));
|
|
63
|
+
} else {
|
|
64
|
+
onChange(enumOptionsDeselectValue<S>(index, checkboxesValues, enumOptions));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const _onBlur = () => onBlur(id, value);
|
|
69
|
+
const _onFocus = () => onFocus(id, value);
|
|
70
|
+
const inlineOption = inline ? { inline: true } : { grouped: true };
|
|
71
|
+
return (
|
|
72
|
+
<>
|
|
73
|
+
{!hideLabel && !!label && (
|
|
74
|
+
<TitleFieldTemplate id={titleId<T>(id)} title={label} schema={schema} uiSchema={uiSchema} registry={registry} />
|
|
75
|
+
)}
|
|
76
|
+
<Form.Group id={id} name={id} {...inlineOption}>
|
|
77
|
+
{Array.isArray(enumOptions) &&
|
|
78
|
+
enumOptions.map((option, index) => {
|
|
79
|
+
const checked = enumOptionsIsSelected<S>(option.value, checkboxesValues);
|
|
80
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
81
|
+
return (
|
|
82
|
+
<Form.Checkbox
|
|
83
|
+
id={optionId(id, index)}
|
|
84
|
+
name={id}
|
|
85
|
+
key={index}
|
|
86
|
+
label={option.label}
|
|
87
|
+
{...semanticProps}
|
|
88
|
+
checked={checked}
|
|
89
|
+
error={rawErrors.length > 0}
|
|
90
|
+
disabled={disabled || itemDisabled || readonly}
|
|
91
|
+
autoFocus={autofocus && index === 0}
|
|
92
|
+
onChange={_onChange(index)}
|
|
93
|
+
onBlur={_onBlur}
|
|
94
|
+
onFocus={_onFocus}
|
|
95
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
})}
|
|
99
|
+
</Form.Group>
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
return (
|
|
17
|
+
<p id={id} className='sui-description'>
|
|
18
|
+
{description}
|
|
19
|
+
</p>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Message } from 'semantic-ui-react';
|
|
2
|
+
import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
/** The `ErrorList` component is the template that renders the all the errors associated with the fields in the `Form`
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `ErrorListProps` for this component
|
|
7
|
+
*/
|
|
8
|
+
export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
9
|
+
errors,
|
|
10
|
+
registry,
|
|
11
|
+
}: ErrorListProps<T, S, F>) {
|
|
12
|
+
const { translateString } = registry;
|
|
13
|
+
return (
|
|
14
|
+
<Message negative>
|
|
15
|
+
<Message.Header>{translateString(TranslatableString.ErrorsLabel)}</Message.Header>
|
|
16
|
+
<Message.List>
|
|
17
|
+
{errors.map((error, index) => (
|
|
18
|
+
<Message.Item key={`error-${index}`}>{error.stack}</Message.Item>
|
|
19
|
+
))}
|
|
20
|
+
</Message.List>
|
|
21
|
+
</Message>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { nanoid } from 'nanoid';
|
|
3
|
+
import { Label, List } from 'semantic-ui-react';
|
|
4
|
+
|
|
5
|
+
import { getSemanticErrorProps } from '../util';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_OPTIONS = {
|
|
8
|
+
options: {
|
|
9
|
+
pointing: 'above',
|
|
10
|
+
size: 'small',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** The `FieldErrorTemplate` component renders the errors local to the particular field
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `FieldErrorProps` for the errors being rendered
|
|
17
|
+
*/
|
|
18
|
+
export default function FieldErrorTemplate<
|
|
19
|
+
T = any,
|
|
20
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
21
|
+
F extends FormContextType = any
|
|
22
|
+
>({ errors, idSchema, uiSchema, registry }: FieldErrorProps<T, S, F>) {
|
|
23
|
+
const { formContext } = registry;
|
|
24
|
+
const options = getSemanticErrorProps<T, S, F>({
|
|
25
|
+
formContext,
|
|
26
|
+
uiSchema,
|
|
27
|
+
defaultProps: DEFAULT_OPTIONS,
|
|
28
|
+
});
|
|
29
|
+
const { pointing, size } = options;
|
|
30
|
+
if (errors && errors.length > 0) {
|
|
31
|
+
const id = errorId<T>(idSchema);
|
|
32
|
+
return (
|
|
33
|
+
<Label id={id} color='red' pointing={pointing || 'above'} size={size || 'small'} basic>
|
|
34
|
+
<List bulleted>
|
|
35
|
+
{errors.map((error) => (
|
|
36
|
+
<List.Item key={nanoid()}>{error}</List.Item>
|
|
37
|
+
))}
|
|
38
|
+
</List>
|
|
39
|
+
</Label>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Message } from 'semantic-ui-react';
|
|
2
|
+
import { FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema, helpId } from '@rjsf/utils';
|
|
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
|
+
const id = helpId<T>(idSchema);
|
|
16
|
+
return <Message size='mini' info id={id} content={help} />;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldTemplateProps,
|
|
3
|
+
FormContextType,
|
|
4
|
+
RJSFSchema,
|
|
5
|
+
StrictRJSFSchema,
|
|
6
|
+
getTemplate,
|
|
7
|
+
getUiOptions,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
import { Form } from 'semantic-ui-react';
|
|
10
|
+
import { getSemanticProps, MaybeWrap } from '../util';
|
|
11
|
+
|
|
12
|
+
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
|
|
13
|
+
* content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
|
|
14
|
+
*
|
|
15
|
+
* @param props - The `FieldTemplateProps` for this component
|
|
16
|
+
*/
|
|
17
|
+
export default function FieldTemplate<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any
|
|
21
|
+
>(props: FieldTemplateProps<T, S, F>) {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
children,
|
|
25
|
+
classNames,
|
|
26
|
+
style,
|
|
27
|
+
displayLabel,
|
|
28
|
+
label,
|
|
29
|
+
errors,
|
|
30
|
+
help,
|
|
31
|
+
hidden,
|
|
32
|
+
description,
|
|
33
|
+
rawDescription,
|
|
34
|
+
registry,
|
|
35
|
+
schema,
|
|
36
|
+
uiSchema,
|
|
37
|
+
...otherProps
|
|
38
|
+
} = props;
|
|
39
|
+
const semanticProps = getSemanticProps<T, S, F>(otherProps);
|
|
40
|
+
const { wrapLabel, wrapContent } = semanticProps;
|
|
41
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
42
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
43
|
+
'WrapIfAdditionalTemplate',
|
|
44
|
+
registry,
|
|
45
|
+
uiOptions
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (hidden) {
|
|
49
|
+
return <div style={{ display: 'none' }}>{children}</div>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<WrapIfAdditionalTemplate
|
|
54
|
+
classNames={classNames}
|
|
55
|
+
style={style}
|
|
56
|
+
id={id}
|
|
57
|
+
label={label}
|
|
58
|
+
registry={registry}
|
|
59
|
+
schema={schema}
|
|
60
|
+
uiSchema={uiSchema}
|
|
61
|
+
{...otherProps}
|
|
62
|
+
>
|
|
63
|
+
<Form.Group key={id} widths='equal' grouped>
|
|
64
|
+
<MaybeWrap wrap={wrapContent} className='sui-field-content'>
|
|
65
|
+
{children}
|
|
66
|
+
{displayLabel && rawDescription && (
|
|
67
|
+
<MaybeWrap wrap={wrapLabel} className='sui-field-label'>
|
|
68
|
+
{description}
|
|
69
|
+
</MaybeWrap>
|
|
70
|
+
)}
|
|
71
|
+
{help}
|
|
72
|
+
{errors}
|
|
73
|
+
</MaybeWrap>
|
|
74
|
+
</Form.Group>
|
|
75
|
+
</WrapIfAdditionalTemplate>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Button, ButtonProps } from 'semantic-ui-react';
|
|
2
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
5
|
+
props: IconButtonProps<T, S, F>
|
|
6
|
+
) {
|
|
7
|
+
const { icon, iconType, color, className, uiSchema, registry, ...otherProps } = props;
|
|
8
|
+
return (
|
|
9
|
+
<Button
|
|
10
|
+
icon={icon}
|
|
11
|
+
size={iconType as ButtonProps['size']}
|
|
12
|
+
color={color as ButtonProps['color']}
|
|
13
|
+
className={className}
|
|
14
|
+
{...otherProps}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default IconButton;
|
|
20
|
+
|
|
21
|
+
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
22
|
+
props: IconButtonProps<T, S, F>
|
|
23
|
+
) {
|
|
24
|
+
const {
|
|
25
|
+
registry: { translateString },
|
|
26
|
+
} = props;
|
|
27
|
+
return <IconButton title={translateString(TranslatableString.CopyButton)} {...props} icon='copy' />;
|
|
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 <IconButton title={translateString(TranslatableString.MoveDownButton)} {...props} icon='angle down' />;
|
|
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='angle up' />;
|
|
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 <IconButton title={translateString(TranslatableString.RemoveButton)} {...props} icon='trash' />;
|
|
55
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Grid } from 'semantic-ui-react';
|
|
2
|
+
import {
|
|
3
|
+
FormContextType,
|
|
4
|
+
ObjectFieldTemplateProps,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
canExpand,
|
|
8
|
+
descriptionId,
|
|
9
|
+
getTemplate,
|
|
10
|
+
getUiOptions,
|
|
11
|
+
titleId,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
|
|
14
|
+
/** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
|
|
15
|
+
* title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
|
|
16
|
+
* the properties.
|
|
17
|
+
*
|
|
18
|
+
* @param props - The `ObjectFieldTemplateProps` for this component
|
|
19
|
+
*/
|
|
20
|
+
export default function ObjectFieldTemplate<
|
|
21
|
+
T = any,
|
|
22
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
23
|
+
F extends FormContextType = any
|
|
24
|
+
>(props: ObjectFieldTemplateProps<T, S, F>) {
|
|
25
|
+
const {
|
|
26
|
+
description,
|
|
27
|
+
onAddClick,
|
|
28
|
+
title,
|
|
29
|
+
properties,
|
|
30
|
+
disabled,
|
|
31
|
+
readonly,
|
|
32
|
+
required,
|
|
33
|
+
uiSchema,
|
|
34
|
+
schema,
|
|
35
|
+
formData,
|
|
36
|
+
idSchema,
|
|
37
|
+
registry,
|
|
38
|
+
} = props;
|
|
39
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
40
|
+
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, uiOptions);
|
|
41
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
42
|
+
'DescriptionFieldTemplate',
|
|
43
|
+
registry,
|
|
44
|
+
uiOptions
|
|
45
|
+
);
|
|
46
|
+
// Button templates are not overridden in the uiSchema
|
|
47
|
+
const {
|
|
48
|
+
ButtonTemplates: { AddButton },
|
|
49
|
+
} = registry.templates;
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
{title && (
|
|
53
|
+
<TitleFieldTemplate
|
|
54
|
+
id={titleId<T>(idSchema)}
|
|
55
|
+
title={title}
|
|
56
|
+
required={required}
|
|
57
|
+
schema={schema}
|
|
58
|
+
uiSchema={uiSchema}
|
|
59
|
+
registry={registry}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
{description && (
|
|
63
|
+
<DescriptionFieldTemplate
|
|
64
|
+
id={descriptionId<T>(idSchema)}
|
|
65
|
+
description={description}
|
|
66
|
+
schema={schema}
|
|
67
|
+
uiSchema={uiSchema}
|
|
68
|
+
registry={registry}
|
|
69
|
+
/>
|
|
70
|
+
)}
|
|
71
|
+
{properties.map((prop) => prop.content)}
|
|
72
|
+
{canExpand<T, S, F>(schema, uiSchema, formData) && (
|
|
73
|
+
<Grid.Column width={16} verticalAlign='middle'>
|
|
74
|
+
<Grid.Row>
|
|
75
|
+
<div
|
|
76
|
+
style={{
|
|
77
|
+
marginTop: '1rem',
|
|
78
|
+
position: 'relative',
|
|
79
|
+
textAlign: 'right',
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
<AddButton
|
|
83
|
+
onClick={onAddClick(schema)}
|
|
84
|
+
disabled={disabled || readonly}
|
|
85
|
+
uiSchema={uiSchema}
|
|
86
|
+
registry={registry}
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
</Grid.Row>
|
|
90
|
+
</Grid.Column>
|
|
91
|
+
)}
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
}
|