@rjsf/mantine 6.0.0-beta.14
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 +153 -0
- package/dist/index.js +1918 -0
- package/dist/index.js.map +7 -0
- package/dist/mantine.esm.js +1967 -0
- package/dist/mantine.esm.js.map +7 -0
- package/dist/mantine.umd.js +1714 -0
- package/lib/Form/index.d.ts +6 -0
- package/lib/Form/index.js +7 -0
- package/lib/Form/index.js.map +1 -0
- package/lib/Theme/index.d.ts +5 -0
- package/lib/Theme/index.js +10 -0
- package/lib/Theme/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/templates/ArrayFieldItemTemplate.d.ts +6 -0
- package/lib/templates/ArrayFieldItemTemplate.js +14 -0
- package/lib/templates/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/templates/ArrayFieldTemplate.d.ts +6 -0
- package/lib/templates/ArrayFieldTemplate.js +20 -0
- package/lib/templates/ArrayFieldTemplate.js.map +1 -0
- package/lib/templates/ArrayFieldTitleTemplate.d.ts +7 -0
- package/lib/templates/ArrayFieldTitleTemplate.js +18 -0
- package/lib/templates/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/templates/BaseInputTemplate.d.ts +8 -0
- package/lib/templates/BaseInputTemplate.js +36 -0
- package/lib/templates/BaseInputTemplate.js.map +1 -0
- package/lib/templates/ButtonTemplates/AddButton.d.ts +4 -0
- package/lib/templates/ButtonTemplates/AddButton.js +11 -0
- package/lib/templates/ButtonTemplates/AddButton.js.map +1 -0
- package/lib/templates/ButtonTemplates/IconButton.d.ts +8 -0
- package/lib/templates/ButtonTemplates/IconButton.js +25 -0
- package/lib/templates/ButtonTemplates/IconButton.js.map +1 -0
- package/lib/templates/ButtonTemplates/SubmitButton.d.ts +4 -0
- package/lib/templates/ButtonTemplates/SubmitButton.js +13 -0
- package/lib/templates/ButtonTemplates/SubmitButton.js.map +1 -0
- package/lib/templates/ButtonTemplates/index.d.ts +3 -0
- package/lib/templates/ButtonTemplates/index.js +15 -0
- package/lib/templates/ButtonTemplates/index.js.map +1 -0
- package/lib/templates/DescriptionField.d.ts +6 -0
- package/lib/templates/DescriptionField.js +15 -0
- package/lib/templates/DescriptionField.js.map +1 -0
- package/lib/templates/ErrorList.d.ts +6 -0
- package/lib/templates/ErrorList.js +13 -0
- package/lib/templates/ErrorList.js.map +1 -0
- package/lib/templates/FieldErrorTemplate.d.ts +6 -0
- package/lib/templates/FieldErrorTemplate.js +16 -0
- package/lib/templates/FieldErrorTemplate.js.map +1 -0
- package/lib/templates/FieldHelpTemplate.d.ts +6 -0
- package/lib/templates/FieldHelpTemplate.js +13 -0
- package/lib/templates/FieldHelpTemplate.js.map +1 -0
- package/lib/templates/FieldTemplate.d.ts +7 -0
- package/lib/templates/FieldTemplate.js +18 -0
- package/lib/templates/FieldTemplate.js.map +1 -0
- package/lib/templates/GridTemplate.d.ts +7 -0
- package/lib/templates/GridTemplate.js +20 -0
- package/lib/templates/GridTemplate.js.map +1 -0
- package/lib/templates/MultiSchemaFieldTemplate.d.ts +2 -0
- package/lib/templates/MultiSchemaFieldTemplate.js +6 -0
- package/lib/templates/MultiSchemaFieldTemplate.js.map +1 -0
- package/lib/templates/ObjectFieldTemplate.d.ts +8 -0
- package/lib/templates/ObjectFieldTemplate.js +24 -0
- package/lib/templates/ObjectFieldTemplate.js.map +1 -0
- package/lib/templates/TitleField.d.ts +6 -0
- package/lib/templates/TitleField.js +11 -0
- package/lib/templates/TitleField.js.map +1 -0
- package/lib/templates/WrapIfAdditionalTemplate.d.ts +7 -0
- package/lib/templates/WrapIfAdditionalTemplate.js +29 -0
- package/lib/templates/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/templates/icons.d.ts +11 -0
- package/lib/templates/icons.js +20 -0
- package/lib/templates/icons.js.map +1 -0
- package/lib/templates/index.d.ts +4 -0
- package/lib/templates/index.js +36 -0
- package/lib/templates/index.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +35 -0
- package/lib/utils.js.map +1 -0
- package/lib/widgets/CheckboxWidget.d.ts +8 -0
- package/lib/widgets/CheckboxWidget.js +33 -0
- package/lib/widgets/CheckboxWidget.js.map +1 -0
- package/lib/widgets/CheckboxesWidget.d.ts +7 -0
- package/lib/widgets/CheckboxesWidget.js +33 -0
- package/lib/widgets/CheckboxesWidget.js.map +1 -0
- package/lib/widgets/ColorWidget.d.ts +6 -0
- package/lib/widgets/ColorWidget.js +28 -0
- package/lib/widgets/ColorWidget.js.map +1 -0
- package/lib/widgets/DateTime/AltDateTimeWidget.d.ts +13 -0
- package/lib/widgets/DateTime/AltDateTimeWidget.js +16 -0
- package/lib/widgets/DateTime/AltDateTimeWidget.js.map +1 -0
- package/lib/widgets/DateTime/AltDateWidget.d.ts +11 -0
- package/lib/widgets/DateTime/AltDateWidget.js +51 -0
- package/lib/widgets/DateTime/AltDateWidget.js.map +1 -0
- package/lib/widgets/DateTime/DateTimeInput.d.ts +5 -0
- package/lib/widgets/DateTime/DateTimeInput.js +39 -0
- package/lib/widgets/DateTime/DateTimeInput.js.map +1 -0
- package/lib/widgets/DateTime/DateTimeWidget.d.ts +6 -0
- package/lib/widgets/DateTime/DateTimeWidget.js +11 -0
- package/lib/widgets/DateTime/DateTimeWidget.js.map +1 -0
- package/lib/widgets/DateTime/DateWidget.d.ts +6 -0
- package/lib/widgets/DateTime/DateWidget.js +11 -0
- package/lib/widgets/DateTime/DateWidget.js.map +1 -0
- package/lib/widgets/DateTime/TimeWidget.d.ts +6 -0
- package/lib/widgets/DateTime/TimeWidget.js +27 -0
- package/lib/widgets/DateTime/TimeWidget.js.map +1 -0
- package/lib/widgets/DateTime/index.d.ts +5 -0
- package/lib/widgets/DateTime/index.js +6 -0
- package/lib/widgets/DateTime/index.js.map +1 -0
- package/lib/widgets/FileWidget.d.ts +7 -0
- package/lib/widgets/FileWidget.js +106 -0
- package/lib/widgets/FileWidget.js.map +1 -0
- package/lib/widgets/PasswordWidget.d.ts +7 -0
- package/lib/widgets/PasswordWidget.js +30 -0
- package/lib/widgets/PasswordWidget.js.map +1 -0
- package/lib/widgets/RadioWidget.d.ts +7 -0
- package/lib/widgets/RadioWidget.js +33 -0
- package/lib/widgets/RadioWidget.js.map +1 -0
- package/lib/widgets/RangeWidget.d.ts +7 -0
- package/lib/widgets/RangeWidget.js +34 -0
- package/lib/widgets/RangeWidget.js.map +1 -0
- package/lib/widgets/SelectWidget.d.ts +7 -0
- package/lib/widgets/SelectWidget.js +45 -0
- package/lib/widgets/SelectWidget.js.map +1 -0
- package/lib/widgets/TextareaWidget.d.ts +7 -0
- package/lib/widgets/TextareaWidget.js +30 -0
- package/lib/widgets/TextareaWidget.js.map +1 -0
- package/lib/widgets/index.d.ts +4 -0
- package/lib/widgets/index.js +34 -0
- package/lib/widgets/index.js.map +1 -0
- package/package.json +110 -0
- package/src/Form/index.ts +15 -0
- package/src/Theme/index.ts +18 -0
- package/src/index.ts +8 -0
- package/src/templates/ArrayFieldItemTemplate.tsx +40 -0
- package/src/templates/ArrayFieldTemplate.tsx +103 -0
- package/src/templates/ArrayFieldTitleTemplate.tsx +33 -0
- package/src/templates/BaseInputTemplate.tsx +134 -0
- package/src/templates/ButtonTemplates/AddButton.tsx +17 -0
- package/src/templates/ButtonTemplates/IconButton.tsx +87 -0
- package/src/templates/ButtonTemplates/SubmitButton.tsx +20 -0
- package/src/templates/ButtonTemplates/index.ts +21 -0
- package/src/templates/DescriptionField.tsx +24 -0
- package/src/templates/ErrorList.tsx +36 -0
- package/src/templates/FieldErrorTemplate.tsx +27 -0
- package/src/templates/FieldHelpTemplate.tsx +22 -0
- package/src/templates/FieldTemplate.tsx +66 -0
- package/src/templates/GridTemplate.tsx +30 -0
- package/src/templates/MultiSchemaFieldTemplate.tsx +15 -0
- package/src/templates/ObjectFieldTemplate.tsx +104 -0
- package/src/templates/TitleField.tsx +17 -0
- package/src/templates/WrapIfAdditionalTemplate.tsx +99 -0
- package/src/templates/icons.tsx +141 -0
- package/src/templates/index.ts +43 -0
- package/src/tsconfig.json +23 -0
- package/src/utils.ts +37 -0
- package/src/widgets/CheckboxWidget.tsx +110 -0
- package/src/widgets/CheckboxesWidget.tsx +112 -0
- package/src/widgets/ColorWidget.tsx +85 -0
- package/src/widgets/DateTime/AltDateTimeWidget.tsx +22 -0
- package/src/widgets/DateTime/AltDateWidget.tsx +139 -0
- package/src/widgets/DateTime/DateTimeInput.tsx +97 -0
- package/src/widgets/DateTime/DateTimeWidget.tsx +24 -0
- package/src/widgets/DateTime/DateWidget.tsx +22 -0
- package/src/widgets/DateTime/TimeWidget.tsx +83 -0
- package/src/widgets/DateTime/index.ts +5 -0
- package/src/widgets/FileWidget.tsx +176 -0
- package/src/widgets/PasswordWidget.tsx +88 -0
- package/src/widgets/RadioWidget.tsx +103 -0
- package/src/widgets/RangeWidget.tsx +95 -0
- package/src/widgets/SelectWidget.tsx +109 -0
- package/src/widgets/TextareaWidget.tsx +87 -0
- package/src/widgets/index.ts +42 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
enumOptionsIndexForValue,
|
|
5
|
+
enumOptionsValueForIndex,
|
|
6
|
+
optionId,
|
|
7
|
+
FormContextType,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
WidgetProps,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { Radio, Flex } from '@mantine/core';
|
|
13
|
+
|
|
14
|
+
import { cleanupOptions } from '../utils';
|
|
15
|
+
|
|
16
|
+
/** The `RadioWidget` is a widget for rendering a radio group.
|
|
17
|
+
* It is typically used with a string property constrained with enum options.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this component
|
|
20
|
+
*/
|
|
21
|
+
export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
22
|
+
props: WidgetProps<T, S, F>,
|
|
23
|
+
) {
|
|
24
|
+
const {
|
|
25
|
+
id,
|
|
26
|
+
value,
|
|
27
|
+
required,
|
|
28
|
+
disabled,
|
|
29
|
+
readonly,
|
|
30
|
+
autofocus,
|
|
31
|
+
label,
|
|
32
|
+
hideLabel,
|
|
33
|
+
rawErrors,
|
|
34
|
+
options,
|
|
35
|
+
onChange,
|
|
36
|
+
onBlur,
|
|
37
|
+
onFocus,
|
|
38
|
+
} = props;
|
|
39
|
+
|
|
40
|
+
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
41
|
+
const themeProps = cleanupOptions(options);
|
|
42
|
+
|
|
43
|
+
const handleChange = useCallback(
|
|
44
|
+
(nextValue: any) => {
|
|
45
|
+
if (!disabled && !readonly && onChange) {
|
|
46
|
+
onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
[onChange, disabled, readonly, enumOptions, emptyValue],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const handleBlur = useCallback(
|
|
53
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
54
|
+
if (onBlur) {
|
|
55
|
+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
[onBlur, id, enumOptions, emptyValue],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const handleFocus = useCallback(
|
|
62
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
63
|
+
if (onFocus) {
|
|
64
|
+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
[onFocus, id, enumOptions, emptyValue],
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const selected = enumOptionsIndexForValue<S>(value, enumOptions) as string;
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<Radio.Group
|
|
74
|
+
id={id}
|
|
75
|
+
name={id}
|
|
76
|
+
value={selected}
|
|
77
|
+
label={!hideLabel ? label : undefined}
|
|
78
|
+
onChange={handleChange}
|
|
79
|
+
required={required}
|
|
80
|
+
readOnly={disabled || readonly}
|
|
81
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
82
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
83
|
+
{...themeProps}
|
|
84
|
+
>
|
|
85
|
+
{Array.isArray(enumOptions) ? (
|
|
86
|
+
<Flex mt='xs' direction={inline ? 'row' : 'column'} gap='xs' wrap='wrap'>
|
|
87
|
+
{enumOptions.map((option, i) => (
|
|
88
|
+
<Radio
|
|
89
|
+
key={i}
|
|
90
|
+
id={optionId(id, i)}
|
|
91
|
+
value={String(i)}
|
|
92
|
+
label={option.label}
|
|
93
|
+
disabled={Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1}
|
|
94
|
+
autoFocus={i === 0 && autofocus}
|
|
95
|
+
onBlur={handleBlur}
|
|
96
|
+
onFocus={handleFocus}
|
|
97
|
+
/>
|
|
98
|
+
))}
|
|
99
|
+
</Flex>
|
|
100
|
+
) : null}
|
|
101
|
+
</Radio.Group>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
rangeSpec,
|
|
5
|
+
FormContextType,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
WidgetProps,
|
|
9
|
+
titleId,
|
|
10
|
+
} from '@rjsf/utils';
|
|
11
|
+
import { Slider, Input } from '@mantine/core';
|
|
12
|
+
|
|
13
|
+
import { cleanupOptions } from '../utils';
|
|
14
|
+
|
|
15
|
+
/** The `RangeWidget` component uses the `BaseInputTemplate` changing the type to `range` and wrapping the result
|
|
16
|
+
* in a div, with the value alongside it.
|
|
17
|
+
*
|
|
18
|
+
* @param props - The `WidgetProps` for this component
|
|
19
|
+
*/
|
|
20
|
+
export default function RangeWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
21
|
+
props: WidgetProps<T, S, F>,
|
|
22
|
+
) {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
name,
|
|
26
|
+
value,
|
|
27
|
+
required,
|
|
28
|
+
disabled,
|
|
29
|
+
readonly,
|
|
30
|
+
autofocus,
|
|
31
|
+
label,
|
|
32
|
+
hideLabel,
|
|
33
|
+
rawErrors,
|
|
34
|
+
options,
|
|
35
|
+
onChange,
|
|
36
|
+
onBlur,
|
|
37
|
+
onFocus,
|
|
38
|
+
schema,
|
|
39
|
+
} = props;
|
|
40
|
+
|
|
41
|
+
const themeProps = cleanupOptions(options);
|
|
42
|
+
const { min, max, step } = rangeSpec(schema);
|
|
43
|
+
|
|
44
|
+
const handleChange = useCallback(
|
|
45
|
+
(nextValue: any) => {
|
|
46
|
+
if (!disabled && !readonly && onChange) {
|
|
47
|
+
onChange(nextValue);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
[onChange, disabled, readonly],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const handleBlur = useCallback(() => {
|
|
54
|
+
if (onBlur) {
|
|
55
|
+
onBlur(id, value);
|
|
56
|
+
}
|
|
57
|
+
}, [onBlur, id, value]);
|
|
58
|
+
|
|
59
|
+
const handleFocus = useCallback(() => {
|
|
60
|
+
if (onFocus) {
|
|
61
|
+
onFocus(id, value);
|
|
62
|
+
}
|
|
63
|
+
}, [onFocus, id, value]);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{!hideLabel && !!label && (
|
|
68
|
+
<Input.Label id={titleId<T>(id)} required={required}>
|
|
69
|
+
{label}
|
|
70
|
+
</Input.Label>
|
|
71
|
+
)}
|
|
72
|
+
{options?.description && <Input.Description>{options.description}</Input.Description>}
|
|
73
|
+
<Slider
|
|
74
|
+
id={id}
|
|
75
|
+
name={name}
|
|
76
|
+
value={value}
|
|
77
|
+
max={max}
|
|
78
|
+
min={min}
|
|
79
|
+
step={step}
|
|
80
|
+
disabled={disabled || readonly}
|
|
81
|
+
autoFocus={autofocus}
|
|
82
|
+
onChange={handleChange}
|
|
83
|
+
onBlur={handleBlur}
|
|
84
|
+
onFocus={handleFocus}
|
|
85
|
+
{...themeProps}
|
|
86
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
87
|
+
/>
|
|
88
|
+
{rawErrors &&
|
|
89
|
+
rawErrors?.length > 0 &&
|
|
90
|
+
rawErrors.map((error: string, index: number) => (
|
|
91
|
+
<Input.Error key={`range-widget-input-errors-${index}`}>{error}</Input.Error>
|
|
92
|
+
))}
|
|
93
|
+
</>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { FocusEvent, useCallback, useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
enumOptionsIndexForValue,
|
|
5
|
+
enumOptionsValueForIndex,
|
|
6
|
+
labelValue,
|
|
7
|
+
FormContextType,
|
|
8
|
+
RJSFSchema,
|
|
9
|
+
StrictRJSFSchema,
|
|
10
|
+
WidgetProps,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { Select, MultiSelect } from '@mantine/core';
|
|
13
|
+
|
|
14
|
+
import { cleanupOptions } from '../utils';
|
|
15
|
+
|
|
16
|
+
/** The `SelectWidget` is a widget for rendering dropdowns.
|
|
17
|
+
* It is typically used with string properties constrained with enum options.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this component
|
|
20
|
+
*/
|
|
21
|
+
export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
22
|
+
props: WidgetProps<T, S, F>,
|
|
23
|
+
) {
|
|
24
|
+
const {
|
|
25
|
+
id,
|
|
26
|
+
value,
|
|
27
|
+
placeholder,
|
|
28
|
+
required,
|
|
29
|
+
disabled,
|
|
30
|
+
readonly,
|
|
31
|
+
autofocus,
|
|
32
|
+
label,
|
|
33
|
+
hideLabel,
|
|
34
|
+
multiple,
|
|
35
|
+
rawErrors,
|
|
36
|
+
options,
|
|
37
|
+
onChange,
|
|
38
|
+
onBlur,
|
|
39
|
+
onFocus,
|
|
40
|
+
} = props;
|
|
41
|
+
|
|
42
|
+
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
43
|
+
const themeProps = cleanupOptions(options);
|
|
44
|
+
|
|
45
|
+
const handleChange = useCallback(
|
|
46
|
+
(nextValue: any) => {
|
|
47
|
+
if (!disabled && !readonly && onChange) {
|
|
48
|
+
onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
[onChange, disabled, readonly, enumOptions, emptyValue],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const handleBlur = useCallback(
|
|
55
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
56
|
+
if (onBlur) {
|
|
57
|
+
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[onBlur, id, enumOptions, emptyValue],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const handleFocus = useCallback(
|
|
64
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
65
|
+
if (onFocus) {
|
|
66
|
+
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[onFocus, id, enumOptions, emptyValue],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
|
|
73
|
+
|
|
74
|
+
const selectOptions = useMemo(() => {
|
|
75
|
+
if (Array.isArray(enumOptions)) {
|
|
76
|
+
return enumOptions.map((option, index) => ({
|
|
77
|
+
key: String(index),
|
|
78
|
+
value: String(index),
|
|
79
|
+
label: option.label,
|
|
80
|
+
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
}, [enumDisabled, enumOptions]);
|
|
85
|
+
|
|
86
|
+
const Component = multiple ? MultiSelect : Select;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Component
|
|
90
|
+
id={id}
|
|
91
|
+
name={id}
|
|
92
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
93
|
+
data={selectOptions}
|
|
94
|
+
value={multiple ? (selectedIndexes as any) : (selectedIndexes as string)}
|
|
95
|
+
onChange={!readonly ? handleChange : undefined}
|
|
96
|
+
onBlur={!readonly ? handleBlur : undefined}
|
|
97
|
+
onFocus={!readonly ? handleFocus : undefined}
|
|
98
|
+
autoFocus={autofocus}
|
|
99
|
+
placeholder={placeholder}
|
|
100
|
+
disabled={disabled || readonly}
|
|
101
|
+
required={required}
|
|
102
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
103
|
+
searchable
|
|
104
|
+
{...themeProps}
|
|
105
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
106
|
+
comboboxProps={{ withinPortal: false }}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ReactElement, ChangeEvent, FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StrictRJSFSchema,
|
|
4
|
+
RJSFSchema,
|
|
5
|
+
FormContextType,
|
|
6
|
+
WidgetProps,
|
|
7
|
+
labelValue,
|
|
8
|
+
ariaDescribedByIds,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
import { Textarea } from '@mantine/core';
|
|
11
|
+
|
|
12
|
+
import { cleanupOptions } from '../utils';
|
|
13
|
+
|
|
14
|
+
/** The `TextareaWidget` is a widget for rendering input fields as textarea.
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `WidgetProps` for this component
|
|
17
|
+
*/
|
|
18
|
+
export default function TextareaWidget<
|
|
19
|
+
T = any,
|
|
20
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
21
|
+
F extends FormContextType = any,
|
|
22
|
+
>(props: WidgetProps<T, S, F>): ReactElement {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
name,
|
|
26
|
+
value,
|
|
27
|
+
placeholder,
|
|
28
|
+
required,
|
|
29
|
+
disabled,
|
|
30
|
+
readonly,
|
|
31
|
+
autofocus,
|
|
32
|
+
label,
|
|
33
|
+
hideLabel,
|
|
34
|
+
rawErrors,
|
|
35
|
+
options,
|
|
36
|
+
onChange,
|
|
37
|
+
onBlur,
|
|
38
|
+
onFocus,
|
|
39
|
+
} = props;
|
|
40
|
+
|
|
41
|
+
const themeProps = cleanupOptions(options);
|
|
42
|
+
const emptyValue = options?.emptyValue ?? '';
|
|
43
|
+
|
|
44
|
+
const handleChange = useCallback(
|
|
45
|
+
(e: ChangeEvent<HTMLTextAreaElement>) => {
|
|
46
|
+
onChange(e.target.value === '' ? emptyValue : e.target.value);
|
|
47
|
+
},
|
|
48
|
+
[onChange, emptyValue],
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const handleBlur = useCallback(
|
|
52
|
+
({ target }: FocusEvent<HTMLTextAreaElement>) => {
|
|
53
|
+
if (onBlur) {
|
|
54
|
+
onBlur(id, target && target.value);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[onBlur, id],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleFocus = useCallback(
|
|
61
|
+
({ target }: FocusEvent<HTMLTextAreaElement>) => {
|
|
62
|
+
if (onFocus) {
|
|
63
|
+
onFocus(id, target && target.value);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
[onFocus, id],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Textarea
|
|
71
|
+
id={id}
|
|
72
|
+
name={name}
|
|
73
|
+
value={value || ''}
|
|
74
|
+
placeholder={placeholder || undefined}
|
|
75
|
+
required={required}
|
|
76
|
+
disabled={disabled || readonly}
|
|
77
|
+
autoFocus={autofocus}
|
|
78
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
79
|
+
onChange={handleChange}
|
|
80
|
+
onBlur={handleBlur}
|
|
81
|
+
onFocus={handleFocus}
|
|
82
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
83
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
84
|
+
{...themeProps}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
|
+
|
|
5
|
+
import { AltDateTimeWidget, AltDateWidget, DateWidget, DateTimeWidget, TimeWidget } from './DateTime';
|
|
6
|
+
import CheckboxesWidget from './CheckboxesWidget';
|
|
7
|
+
import CheckboxWidget from './CheckboxWidget';
|
|
8
|
+
import ColorWidget from './ColorWidget';
|
|
9
|
+
import FileWidget from './FileWidget';
|
|
10
|
+
import PasswordWidget from './PasswordWidget';
|
|
11
|
+
import RadioWidget from './RadioWidget';
|
|
12
|
+
import RangeWidget from './RangeWidget';
|
|
13
|
+
import SelectWidget from './SelectWidget';
|
|
14
|
+
import TextareaWidget from './TextareaWidget';
|
|
15
|
+
|
|
16
|
+
// This plugin is needed to support the parsing of date and time values in the `DateWidget` and `DateTimeWidget`
|
|
17
|
+
dayjs.extend(customParseFormat);
|
|
18
|
+
|
|
19
|
+
export function generateWidgets<
|
|
20
|
+
T = any,
|
|
21
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
22
|
+
F extends FormContextType = any,
|
|
23
|
+
>(): RegistryWidgetsType<T, S, F> {
|
|
24
|
+
return {
|
|
25
|
+
AltDateTimeWidget,
|
|
26
|
+
AltDateWidget,
|
|
27
|
+
CheckboxesWidget,
|
|
28
|
+
CheckboxWidget,
|
|
29
|
+
ColorWidget,
|
|
30
|
+
FileWidget,
|
|
31
|
+
DateTimeWidget,
|
|
32
|
+
DateWidget,
|
|
33
|
+
PasswordWidget,
|
|
34
|
+
RadioWidget,
|
|
35
|
+
RangeWidget,
|
|
36
|
+
SelectWidget,
|
|
37
|
+
TextareaWidget,
|
|
38
|
+
TimeWidget,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default generateWidgets();
|