@rjsf/primereact 6.0.0-beta.11
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/README.md +120 -0
- package/dist/index.js +1285 -0
- package/dist/index.js.map +7 -0
- package/dist/primereact.esm.js +1327 -0
- package/dist/primereact.esm.js.map +7 -0
- package/dist/primereact.umd.js +1135 -0
- package/lib/AddButton/AddButton.d.ts +4 -0
- package/lib/AddButton/AddButton.js +10 -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 +6 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +13 -0
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/ArrayFieldItemTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldItemTemplate/index.js +3 -0
- package/lib/ArrayFieldItemTemplate/index.js.map +1 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.d.ts +6 -0
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +30 -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/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.d.ts +6 -0
- package/lib/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.js +11 -0
- package/lib/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/ArrayFieldTitleTemplate/index.d.ts +2 -0
- package/lib/ArrayFieldTitleTemplate/index.js +3 -0
- package/lib/ArrayFieldTitleTemplate/index.js.map +1 -0
- package/lib/AutoCompleteWidget/AutoCompleteWidget.d.ts +7 -0
- package/lib/AutoCompleteWidget/AutoCompleteWidget.js +42 -0
- package/lib/AutoCompleteWidget/AutoCompleteWidget.js.map +1 -0
- package/lib/AutoCompleteWidget/index.d.ts +2 -0
- package/lib/AutoCompleteWidget/index.js +3 -0
- package/lib/AutoCompleteWidget/index.js.map +1 -0
- package/lib/BaseInputTemplate/BaseInputTemplate.d.ts +4 -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 +7 -0
- package/lib/CheckboxWidget/CheckboxWidget.js +23 -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 +7 -0
- package/lib/CheckboxesWidget/CheckboxesWidget.js +35 -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/ColorWidget/ColorWidget.d.ts +6 -0
- package/lib/ColorWidget/ColorWidget.js +18 -0
- package/lib/ColorWidget/ColorWidget.js.map +1 -0
- package/lib/ColorWidget/index.d.ts +2 -0
- package/lib/ColorWidget/index.js +3 -0
- package/lib/ColorWidget/index.js.map +1 -0
- package/lib/DescriptionField/DescriptionField.d.ts +6 -0
- package/lib/DescriptionField/DescriptionField.js +14 -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 +6 -0
- package/lib/ErrorList/ErrorList.js +21 -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 +15 -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 +13 -0
- package/lib/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/FieldTemplate/index.d.ts +2 -0
- package/lib/FieldTemplate/index.js +3 -0
- package/lib/FieldTemplate/index.js.map +1 -0
- package/lib/GridTemplate/GridTemplate.d.ts +8 -0
- package/lib/GridTemplate/GridTemplate.js +69 -0
- package/lib/GridTemplate/GridTemplate.js.map +1 -0
- package/lib/GridTemplate/index.d.ts +2 -0
- package/lib/GridTemplate/index.js +3 -0
- package/lib/GridTemplate/index.js.map +1 -0
- package/lib/IconButton/IconButton.d.ts +7 -0
- package/lib/IconButton/IconButton.js +25 -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/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.d.ts +2 -0
- package/lib/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.js +7 -0
- package/lib/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.js.map +1 -0
- package/lib/MultiSchemaFieldTemplate/index.d.ts +2 -0
- package/lib/MultiSchemaFieldTemplate/index.js +3 -0
- package/lib/MultiSchemaFieldTemplate/index.js.map +1 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.d.ts +8 -0
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +18 -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/PasswordWidget/PasswordWidget.d.ts +6 -0
- package/lib/PasswordWidget/PasswordWidget.js +17 -0
- package/lib/PasswordWidget/PasswordWidget.js.map +1 -0
- package/lib/PasswordWidget/index.d.ts +2 -0
- package/lib/PasswordWidget/index.js +3 -0
- package/lib/PasswordWidget/index.js.map +1 -0
- package/lib/PrimeForm/PrimeForm.d.ts +6 -0
- package/lib/PrimeForm/PrimeForm.js +7 -0
- package/lib/PrimeForm/PrimeForm.js.map +1 -0
- package/lib/PrimeForm/index.d.ts +2 -0
- package/lib/PrimeForm/index.js +3 -0
- package/lib/PrimeForm/index.js.map +1 -0
- package/lib/RadioWidget/RadioWidget.d.ts +7 -0
- package/lib/RadioWidget/RadioWidget.js +25 -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 +7 -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 +7 -0
- package/lib/SelectWidget/SelectWidget.js +47 -0
- package/lib/SelectWidget/SelectWidget.js.map +1 -0
- package/lib/SelectWidget/index.d.ts +2 -0
- package/lib/SelectWidget/index.js +3 -0
- package/lib/SelectWidget/index.js.map +1 -0
- package/lib/SubmitButton/SubmitButton.d.ts +4 -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 +45 -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 +20 -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 +6 -0
- package/lib/TitleField/TitleField.js +12 -0
- package/lib/TitleField/TitleField.js.map +1 -0
- package/lib/TitleField/index.d.ts +2 -0
- package/lib/TitleField/index.js +3 -0
- package/lib/TitleField/index.js.map +1 -0
- package/lib/UpDownWidget/UpDownWidget.d.ts +6 -0
- package/lib/UpDownWidget/UpDownWidget.js +19 -0
- package/lib/UpDownWidget/UpDownWidget.js.map +1 -0
- package/lib/UpDownWidget/index.d.ts +2 -0
- package/lib/UpDownWidget/index.js +3 -0
- package/lib/UpDownWidget/index.js.map +1 -0
- package/lib/Widgets/Widgets.d.ts +4 -0
- package/lib/Widgets/Widgets.js +26 -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 +7 -0
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +20 -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/lib/util.d.ts +5 -0
- package/lib/util.js +8 -0
- package/lib/util.js.map +1 -0
- package/package.json +104 -0
- package/src/AddButton/AddButton.tsx +23 -0
- package/src/AddButton/index.ts +2 -0
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +40 -0
- package/src/ArrayFieldItemTemplate/index.ts +2 -0
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +111 -0
- package/src/ArrayFieldTemplate/index.ts +2 -0
- package/src/ArrayFieldTitleTemplate/ArrayFieldTitleTemplate.tsx +25 -0
- package/src/ArrayFieldTitleTemplate/index.ts +2 -0
- package/src/AutoCompleteWidget/AutoCompleteWidget.tsx +96 -0
- package/src/AutoCompleteWidget/index.ts +2 -0
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +71 -0
- package/src/BaseInputTemplate/index.ts +2 -0
- package/src/CheckboxWidget/CheckboxWidget.tsx +86 -0
- package/src/CheckboxWidget/index.ts +2 -0
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +105 -0
- package/src/CheckboxesWidget/index.ts +2 -0
- package/src/ColorWidget/ColorWidget.tsx +62 -0
- package/src/ColorWidget/index.ts +2 -0
- package/src/DescriptionField/DescriptionField.tsx +22 -0
- package/src/DescriptionField/index.ts +2 -0
- package/src/ErrorList/ErrorList.tsx +44 -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 +18 -0
- package/src/FieldHelpTemplate/index.ts +2 -0
- package/src/FieldTemplate/FieldTemplate.tsx +40 -0
- package/src/FieldTemplate/index.ts +2 -0
- package/src/GridTemplate/GridTemplate.tsx +93 -0
- package/src/GridTemplate/index.ts +2 -0
- package/src/IconButton/IconButton.tsx +47 -0
- package/src/IconButton/index.ts +2 -0
- package/src/MultiSchemaFieldTemplate/MultiSchemaFieldTemplate.tsx +17 -0
- package/src/MultiSchemaFieldTemplate/index.ts +2 -0
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +88 -0
- package/src/ObjectFieldTemplate/index.ts +2 -0
- package/src/PasswordWidget/PasswordWidget.tsx +65 -0
- package/src/PasswordWidget/index.ts +2 -0
- package/src/PrimeForm/PrimeForm.ts +15 -0
- package/src/PrimeForm/index.ts +2 -0
- package/src/RadioWidget/RadioWidget.tsx +60 -0
- package/src/RadioWidget/index.ts +2 -0
- package/src/RangeWidget/RangeWidget.tsx +37 -0
- package/src/RangeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +139 -0
- package/src/SelectWidget/index.ts +2 -0
- package/src/SubmitButton/SubmitButton.tsx +16 -0
- package/src/SubmitButton/index.ts +2 -0
- package/src/Templates/Templates.ts +52 -0
- package/src/Templates/index.ts +2 -0
- package/src/TextareaWidget/TextareaWidget.tsx +41 -0
- package/src/TextareaWidget/index.ts +2 -0
- package/src/Theme/Theme.ts +18 -0
- package/src/Theme/index.ts +2 -0
- package/src/TitleField/TitleField.tsx +23 -0
- package/src/TitleField/index.ts +2 -0
- package/src/UpDownWidget/UpDownWidget.tsx +70 -0
- package/src/UpDownWidget/index.ts +2 -0
- package/src/Widgets/Widgets.tsx +33 -0
- package/src/Widgets/index.ts +2 -0
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +83 -0
- package/src/WrapIfAdditionalTemplate/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/tsconfig.json +24 -0
- package/src/util.tsx +11 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ChangeEvent, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
FormContextType,
|
|
5
|
+
getInputProps,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
WidgetProps,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
import { AutoComplete, AutoCompleteCompleteEvent } from 'primereact/autocomplete';
|
|
11
|
+
|
|
12
|
+
/** The `AutoCompleteWidget` is a widget for rendering a field with options.
|
|
13
|
+
* This is used instead of the base input template if the schema has examples.
|
|
14
|
+
*
|
|
15
|
+
* @param props - The `WidgetProps` for this component
|
|
16
|
+
*/
|
|
17
|
+
export default function AutoCompleteWidget<
|
|
18
|
+
T = any,
|
|
19
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
+
F extends FormContextType = any,
|
|
21
|
+
>(props: WidgetProps<T, S, F>) {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
placeholder,
|
|
25
|
+
value,
|
|
26
|
+
required,
|
|
27
|
+
readonly,
|
|
28
|
+
disabled,
|
|
29
|
+
onChange,
|
|
30
|
+
onChangeOverride,
|
|
31
|
+
onBlur,
|
|
32
|
+
onFocus,
|
|
33
|
+
autofocus,
|
|
34
|
+
options,
|
|
35
|
+
schema,
|
|
36
|
+
type,
|
|
37
|
+
rawErrors = [],
|
|
38
|
+
} = props;
|
|
39
|
+
const inputProps = getInputProps<T, S, F>(schema, type, options);
|
|
40
|
+
const primeProps = (options.prime || {}) as object;
|
|
41
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
42
|
+
onChange(value === '' ? options.emptyValue : value);
|
|
43
|
+
const _onBlur = () => onBlur && onBlur(id, value);
|
|
44
|
+
const _onFocus = () => onFocus && onFocus(id, value);
|
|
45
|
+
|
|
46
|
+
const examples = (schema.examples as string[]).concat(
|
|
47
|
+
schema.default && !(schema.examples as string[]).includes(schema.default.toString())
|
|
48
|
+
? [schema.default.toString()]
|
|
49
|
+
: [],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const [items, setItems] = useState<string[]>([]);
|
|
53
|
+
|
|
54
|
+
const search = (event: AutoCompleteCompleteEvent) => {
|
|
55
|
+
setItems(examples.filter((example) => example.toString().toLowerCase().includes(event.query.toLowerCase())));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<AutoComplete
|
|
60
|
+
id={id}
|
|
61
|
+
name={id}
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
{...primeProps}
|
|
64
|
+
{...inputProps}
|
|
65
|
+
loadingIcon={<></>}
|
|
66
|
+
required={required}
|
|
67
|
+
autoFocus={autofocus}
|
|
68
|
+
disabled={disabled || readonly}
|
|
69
|
+
suggestions={items}
|
|
70
|
+
completeMethod={search}
|
|
71
|
+
value={value || value === 0 ? value : ''}
|
|
72
|
+
dropdown
|
|
73
|
+
invalid={rawErrors.length > 0}
|
|
74
|
+
onChange={(onChangeOverride as any) || _onChange}
|
|
75
|
+
onBlur={_onBlur}
|
|
76
|
+
onFocus={_onFocus}
|
|
77
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
78
|
+
/* Make autocomplete look like a dropdown, which looks much nicer */
|
|
79
|
+
pt={{
|
|
80
|
+
root: {
|
|
81
|
+
className: 'p-dropdown',
|
|
82
|
+
},
|
|
83
|
+
input: {
|
|
84
|
+
root: {
|
|
85
|
+
style: { border: 'none' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
dropdownButton: {
|
|
89
|
+
root: {
|
|
90
|
+
className: 'p-button-text p-button-secondary',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
BaseInputTemplateProps,
|
|
5
|
+
examplesId,
|
|
6
|
+
FormContextType,
|
|
7
|
+
getInputProps,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
import { InputText } from 'primereact/inputtext';
|
|
12
|
+
|
|
13
|
+
/** The `BaseInputTemplate` is the template the fallback if no widget is specified.
|
|
14
|
+
*/
|
|
15
|
+
export default function BaseInputTemplate<
|
|
16
|
+
T = any,
|
|
17
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
18
|
+
F extends FormContextType = any,
|
|
19
|
+
>(props: BaseInputTemplateProps<T, S, F>) {
|
|
20
|
+
const {
|
|
21
|
+
id,
|
|
22
|
+
placeholder,
|
|
23
|
+
value,
|
|
24
|
+
required,
|
|
25
|
+
readonly,
|
|
26
|
+
disabled,
|
|
27
|
+
onChange,
|
|
28
|
+
onChangeOverride,
|
|
29
|
+
onBlur,
|
|
30
|
+
onFocus,
|
|
31
|
+
autofocus,
|
|
32
|
+
options,
|
|
33
|
+
schema,
|
|
34
|
+
type,
|
|
35
|
+
registry,
|
|
36
|
+
rawErrors = [],
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const { AutoCompleteWidget } = registry.widgets;
|
|
40
|
+
|
|
41
|
+
if (Array.isArray(schema.examples)) {
|
|
42
|
+
return <AutoCompleteWidget {...props} />;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const inputProps = getInputProps<T, S, F>(schema, type, options);
|
|
46
|
+
const primeProps = (options.prime || {}) as object;
|
|
47
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
48
|
+
onChange(value === '' ? options.emptyValue : value);
|
|
49
|
+
const _onBlur = () => onBlur && onBlur(id, value);
|
|
50
|
+
const _onFocus = () => onFocus && onFocus(id, value);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<InputText
|
|
54
|
+
id={id}
|
|
55
|
+
name={id}
|
|
56
|
+
placeholder={placeholder}
|
|
57
|
+
{...primeProps}
|
|
58
|
+
{...inputProps}
|
|
59
|
+
required={required}
|
|
60
|
+
autoFocus={autofocus}
|
|
61
|
+
disabled={disabled || readonly}
|
|
62
|
+
list={schema.examples ? examplesId<T>(id) : undefined}
|
|
63
|
+
value={value || value === 0 ? value : ''}
|
|
64
|
+
invalid={rawErrors.length > 0}
|
|
65
|
+
onChange={onChangeOverride || _onChange}
|
|
66
|
+
onBlur={_onBlur}
|
|
67
|
+
onFocus={_onFocus}
|
|
68
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ariaDescribedByIds,
|
|
3
|
+
descriptionId,
|
|
4
|
+
getTemplate,
|
|
5
|
+
labelValue,
|
|
6
|
+
schemaRequiresTrueValue,
|
|
7
|
+
FormContextType,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
WidgetProps,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { Checkbox, CheckboxChangeEvent } from 'primereact/checkbox';
|
|
13
|
+
|
|
14
|
+
import { Label } 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
|
+
schema,
|
|
39
|
+
uiSchema,
|
|
40
|
+
registry,
|
|
41
|
+
} = props;
|
|
42
|
+
|
|
43
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
44
|
+
'DescriptionFieldTemplate',
|
|
45
|
+
registry,
|
|
46
|
+
options,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const required = schemaRequiresTrueValue<S>(schema);
|
|
50
|
+
const _onChange = (e: CheckboxChangeEvent) => onChange && onChange(e.checked);
|
|
51
|
+
const _onBlur = () => onBlur && onBlur(id, value);
|
|
52
|
+
const _onFocus = () => onFocus && onFocus(id, value);
|
|
53
|
+
const checked = value === 'true' || value === true;
|
|
54
|
+
const description = options.description ?? schema.description;
|
|
55
|
+
const primeProps = (options.prime || {}) as object;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
{!hideLabel && !!description && (
|
|
60
|
+
<DescriptionFieldTemplate
|
|
61
|
+
id={descriptionId<T>(id)}
|
|
62
|
+
description={description}
|
|
63
|
+
schema={schema}
|
|
64
|
+
uiSchema={uiSchema}
|
|
65
|
+
registry={registry}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
68
|
+
<div style={{ display: 'flex', flexDirection: 'row', gap: '0.5rem', alignItems: 'center' }}>
|
|
69
|
+
<Checkbox
|
|
70
|
+
inputId={id}
|
|
71
|
+
name={id}
|
|
72
|
+
{...primeProps}
|
|
73
|
+
disabled={disabled || readonly}
|
|
74
|
+
autoFocus={autofocus}
|
|
75
|
+
checked={typeof value === 'undefined' ? false : checked}
|
|
76
|
+
onChange={_onChange}
|
|
77
|
+
onBlur={_onBlur}
|
|
78
|
+
onFocus={_onFocus}
|
|
79
|
+
required={required}
|
|
80
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
81
|
+
/>
|
|
82
|
+
{labelValue(<Label id={id} text={label} />, hideLabel, false)}
|
|
83
|
+
</div>
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Checkbox, CheckboxChangeEvent } from 'primereact/checkbox';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
enumOptionsDeselectValue,
|
|
5
|
+
enumOptionsIsSelected,
|
|
6
|
+
enumOptionsSelectValue,
|
|
7
|
+
optionId,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
WidgetProps,
|
|
12
|
+
descriptionId,
|
|
13
|
+
getTemplate,
|
|
14
|
+
} from '@rjsf/utils';
|
|
15
|
+
|
|
16
|
+
import { Label } 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
|
+
onChange,
|
|
36
|
+
onBlur,
|
|
37
|
+
onFocus,
|
|
38
|
+
schema,
|
|
39
|
+
uiSchema,
|
|
40
|
+
registry,
|
|
41
|
+
hideLabel,
|
|
42
|
+
} = props;
|
|
43
|
+
const { enumOptions, enumDisabled } = options;
|
|
44
|
+
const primeProps = (options.prime || {}) as object;
|
|
45
|
+
const checkboxesValues = Array.isArray(value) ? value : [value];
|
|
46
|
+
|
|
47
|
+
const _onChange = (index: number) => (e: CheckboxChangeEvent) => {
|
|
48
|
+
if (e.checked) {
|
|
49
|
+
onChange(enumOptionsSelectValue<S>(index, checkboxesValues, enumOptions));
|
|
50
|
+
} else {
|
|
51
|
+
onChange(enumOptionsDeselectValue<S>(index, checkboxesValues, enumOptions));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
56
|
+
'DescriptionFieldTemplate',
|
|
57
|
+
registry,
|
|
58
|
+
options,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const _onBlur = () => onBlur(id, value);
|
|
62
|
+
const _onFocus = () => onFocus(id, value);
|
|
63
|
+
|
|
64
|
+
const description = options.description ?? schema.description;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div
|
|
68
|
+
id={id}
|
|
69
|
+
style={{ display: 'flex', flexDirection: 'column', gap: '1rem', marginTop: '0.5rem', marginBottom: '0.5rem' }}
|
|
70
|
+
>
|
|
71
|
+
{!hideLabel && !!description && (
|
|
72
|
+
<DescriptionFieldTemplate
|
|
73
|
+
id={descriptionId<T>(id)}
|
|
74
|
+
description={description}
|
|
75
|
+
schema={schema}
|
|
76
|
+
uiSchema={uiSchema}
|
|
77
|
+
registry={registry}
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
{Array.isArray(enumOptions) &&
|
|
81
|
+
enumOptions.map((option, index) => {
|
|
82
|
+
const checked = enumOptionsIsSelected<S>(option.value, checkboxesValues);
|
|
83
|
+
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
|
|
84
|
+
return (
|
|
85
|
+
<div key={index} style={{ display: 'flex', flexDirection: 'row', gap: '0.5rem', alignItems: 'center' }}>
|
|
86
|
+
<Checkbox
|
|
87
|
+
inputId={optionId(id, index)}
|
|
88
|
+
name={id}
|
|
89
|
+
{...primeProps}
|
|
90
|
+
value={option.value}
|
|
91
|
+
checked={checked}
|
|
92
|
+
disabled={disabled || itemDisabled || readonly}
|
|
93
|
+
autoFocus={autofocus && index === 0}
|
|
94
|
+
onChange={_onChange(index)}
|
|
95
|
+
onBlur={_onBlur}
|
|
96
|
+
onFocus={_onFocus}
|
|
97
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
98
|
+
/>
|
|
99
|
+
<Label id={optionId(id, index)} text={option.label} />
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
})}
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
FormContextType,
|
|
5
|
+
getInputProps,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
WidgetProps,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
import { ColorPicker } from 'primereact/colorpicker';
|
|
11
|
+
|
|
12
|
+
/** The `ColorWidget` component renders a color picker.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `WidgetProps` for this component
|
|
15
|
+
*/
|
|
16
|
+
export default function ColorWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
17
|
+
props: WidgetProps<T, S, F>,
|
|
18
|
+
) {
|
|
19
|
+
const {
|
|
20
|
+
id,
|
|
21
|
+
placeholder,
|
|
22
|
+
value,
|
|
23
|
+
required,
|
|
24
|
+
readonly,
|
|
25
|
+
disabled,
|
|
26
|
+
onChange,
|
|
27
|
+
onChangeOverride,
|
|
28
|
+
onBlur,
|
|
29
|
+
onFocus,
|
|
30
|
+
autofocus,
|
|
31
|
+
options,
|
|
32
|
+
schema,
|
|
33
|
+
type,
|
|
34
|
+
} = props;
|
|
35
|
+
const inputProps = getInputProps<T, S, F>(schema, type, options);
|
|
36
|
+
const { inline } = options;
|
|
37
|
+
const primeProps = (options.prime || {}) as object;
|
|
38
|
+
|
|
39
|
+
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
|
|
40
|
+
onChange(value === '' ? options.emptyValue : value);
|
|
41
|
+
const _onBlur = () => onBlur && onBlur(id, value);
|
|
42
|
+
const _onFocus = () => onFocus && onFocus(id, value);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<ColorPicker
|
|
46
|
+
id={id}
|
|
47
|
+
name={id}
|
|
48
|
+
placeholder={placeholder}
|
|
49
|
+
{...primeProps}
|
|
50
|
+
{...inputProps}
|
|
51
|
+
required={required}
|
|
52
|
+
inline={inline}
|
|
53
|
+
autoFocus={autofocus}
|
|
54
|
+
disabled={disabled || readonly}
|
|
55
|
+
value={value || ''}
|
|
56
|
+
onChange={onChangeOverride || _onChange}
|
|
57
|
+
onBlur={_onBlur}
|
|
58
|
+
onFocus={_onFocus}
|
|
59
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { RichDescription } from '@rjsf/core';
|
|
3
|
+
|
|
4
|
+
/** The `DescriptionField` is the template to use to render the description of a field
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `DescriptionFieldProps` for this component
|
|
7
|
+
*/
|
|
8
|
+
export default function DescriptionField<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any,
|
|
12
|
+
>(props: DescriptionFieldProps<T, S, F>) {
|
|
13
|
+
const { id, description, registry, uiSchema } = props;
|
|
14
|
+
if (!description) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return (
|
|
18
|
+
<span id={id}>
|
|
19
|
+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
|
|
20
|
+
</span>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Message } from 'primereact/message';
|
|
2
|
+
import { TimesCircleIcon } from 'primereact/icons/timescircle';
|
|
3
|
+
import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
4
|
+
|
|
5
|
+
/** The `ErrorList` component is the template that renders all the errors associated with the fields in the `Form`
|
|
6
|
+
*
|
|
7
|
+
* @param props - The `ErrorListProps` for this component
|
|
8
|
+
*/
|
|
9
|
+
export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
10
|
+
errors,
|
|
11
|
+
registry,
|
|
12
|
+
}: ErrorListProps<T, S, F>) {
|
|
13
|
+
const { translateString } = registry;
|
|
14
|
+
|
|
15
|
+
const content = (
|
|
16
|
+
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
17
|
+
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', gap: '0.5rem' }}>
|
|
18
|
+
<TimesCircleIcon style={{ width: '1.5rem', height: '1.5rem' }} />
|
|
19
|
+
<div className='p-message-summary'>{translateString(TranslatableString.ErrorsLabel)}</div>
|
|
20
|
+
</div>
|
|
21
|
+
<ul className='p-message-list'>
|
|
22
|
+
{errors.map((error, index) => (
|
|
23
|
+
<li key={`error-${index}`}>{error.stack}</li>
|
|
24
|
+
))}
|
|
25
|
+
</ul>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Message
|
|
31
|
+
className='p-message'
|
|
32
|
+
style={{
|
|
33
|
+
borderStyle: 'solid',
|
|
34
|
+
borderColor: '#ff5757',
|
|
35
|
+
borderWidth: '0 0 0 6px',
|
|
36
|
+
width: '100%',
|
|
37
|
+
justifyContent: 'start',
|
|
38
|
+
marginBottom: '1rem',
|
|
39
|
+
}}
|
|
40
|
+
severity='error'
|
|
41
|
+
content={content}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { Message } from 'primereact/message';
|
|
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
|
+
>({ errors, idSchema }: FieldErrorProps<T, S, F>) {
|
|
13
|
+
if (errors && errors.length > 0) {
|
|
14
|
+
const id = errorId<T>(idSchema);
|
|
15
|
+
const content = errors.map((error, i: number) => {
|
|
16
|
+
return <div key={i}>{error}</div>;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Message
|
|
21
|
+
id={id}
|
|
22
|
+
severity='error'
|
|
23
|
+
style={{ justifyContent: 'left' }}
|
|
24
|
+
text={content}
|
|
25
|
+
pt={{ text: { style: { fontSize: 'smaller' } } }}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema, helpId } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
/** The `FieldHelpTemplate` component renders any help desired for a field
|
|
4
|
+
*
|
|
5
|
+
* @param props - The `FieldHelpProps` to be rendered
|
|
6
|
+
*/
|
|
7
|
+
export default function FieldHelpTemplate<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any,
|
|
11
|
+
>(props: FieldHelpProps<T, S, F>) {
|
|
12
|
+
const { idSchema, help } = props;
|
|
13
|
+
if (help) {
|
|
14
|
+
const id = helpId<T>(idSchema);
|
|
15
|
+
return <small id={id}>{help}</small>;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldTemplateProps,
|
|
3
|
+
FormContextType,
|
|
4
|
+
getTemplate,
|
|
5
|
+
getUiOptions,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
} from '@rjsf/utils';
|
|
9
|
+
|
|
10
|
+
import { Label } from '../util';
|
|
11
|
+
|
|
12
|
+
export default function FieldTemplate<
|
|
13
|
+
T = any,
|
|
14
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
15
|
+
F extends FormContextType = any,
|
|
16
|
+
>(props: FieldTemplateProps<T, S, F>) {
|
|
17
|
+
const { children, errors, help, displayLabel, description, rawDescription, hidden, uiSchema, registry } = props;
|
|
18
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
19
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
20
|
+
'WrapIfAdditionalTemplate',
|
|
21
|
+
registry,
|
|
22
|
+
uiOptions,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (hidden) {
|
|
26
|
+
return <div style={{ display: 'none' }}>{children}</div>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<WrapIfAdditionalTemplate {...props}>
|
|
31
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', marginBottom: '1rem' }}>
|
|
32
|
+
{displayLabel && <Label id={props.id} text={props.label} required={props.required} />}
|
|
33
|
+
{children}
|
|
34
|
+
{displayLabel && rawDescription && <small>{description}</small>}
|
|
35
|
+
{errors}
|
|
36
|
+
{help}
|
|
37
|
+
</div>
|
|
38
|
+
</WrapIfAdditionalTemplate>
|
|
39
|
+
);
|
|
40
|
+
}
|