@rjsf/mantine 6.4.2 → 6.5.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.cjs +59 -45
- package/dist/index.cjs.map +2 -2
- package/dist/mantine.esm.js +69 -49
- package/dist/mantine.esm.js.map +3 -3
- package/dist/mantine.umd.js +59 -45
- package/lib/Form/index.js +1 -1
- package/lib/Theme/index.js +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/index.js +4 -4
- package/lib/templates/BaseInputTemplate.js +3 -2
- package/lib/templates/BaseInputTemplate.js.map +1 -1
- package/lib/templates/ButtonTemplates/AddButton.js +2 -2
- package/lib/templates/ButtonTemplates/IconButton.js +1 -1
- package/lib/templates/ButtonTemplates/index.js +3 -3
- package/lib/templates/ErrorList.js +1 -1
- package/lib/templates/OptionalDataControlsTemplate.js +2 -2
- package/lib/templates/WrapIfAdditionalTemplate.js +1 -1
- package/lib/templates/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/templates/index.js +16 -16
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/widgets/CheckboxesWidget.js +10 -9
- package/lib/widgets/CheckboxesWidget.js.map +1 -1
- package/lib/widgets/ColorWidget.js +1 -1
- package/lib/widgets/DateTime/DateTimeWidget.js +1 -1
- package/lib/widgets/DateTime/DateWidget.js +1 -1
- package/lib/widgets/DateTime/index.d.ts +5 -5
- package/lib/widgets/DateTime/index.js +5 -5
- package/lib/widgets/FileWidget.js +1 -1
- package/lib/widgets/PasswordWidget.js +1 -1
- package/lib/widgets/RadioWidget.js +10 -9
- package/lib/widgets/RadioWidget.js.map +1 -1
- package/lib/widgets/RangeWidget.js +1 -1
- package/lib/widgets/SelectWidget.js +30 -13
- package/lib/widgets/SelectWidget.js.map +1 -1
- package/lib/widgets/TextareaWidget.js +1 -1
- package/lib/widgets/index.js +10 -10
- package/package.json +8 -8
- package/src/templates/BaseInputTemplate.tsx +5 -1
- package/src/templates/WrapIfAdditionalTemplate.tsx +1 -0
- package/src/widgets/CheckboxesWidget.tsx +11 -8
- package/src/widgets/RadioWidget.tsx +11 -8
- package/src/widgets/SelectWidget.tsx +40 -32
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { FocusEvent, useCallback, useMemo } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ariaDescribedByIds,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
enumOptionSelectedValue,
|
|
5
|
+
enumOptionValueDecoder,
|
|
6
|
+
enumOptionValueEncoder,
|
|
7
|
+
getOptionValueFormat,
|
|
6
8
|
labelValue,
|
|
7
9
|
FormContextType,
|
|
8
10
|
RJSFSchema,
|
|
@@ -41,70 +43,76 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
41
43
|
} = props;
|
|
42
44
|
|
|
43
45
|
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
46
|
+
const optionValueFormat = getOptionValueFormat(options);
|
|
44
47
|
const themeProps = cleanupOptions(options);
|
|
45
48
|
|
|
46
49
|
const handleChange = useCallback(
|
|
47
50
|
(nextValue: any) => {
|
|
48
51
|
if (!disabled && !readonly && onChange) {
|
|
49
|
-
onChange(
|
|
52
|
+
onChange(enumOptionValueDecoder<S>(nextValue, enumOptions, optionValueFormat, emptyValue));
|
|
50
53
|
}
|
|
51
54
|
},
|
|
52
|
-
[onChange, disabled, readonly, enumOptions, emptyValue],
|
|
55
|
+
[onChange, disabled, readonly, enumOptions, emptyValue, optionValueFormat],
|
|
53
56
|
);
|
|
54
57
|
|
|
55
58
|
const handleBlur = useCallback(
|
|
56
59
|
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
57
60
|
if (onBlur) {
|
|
58
|
-
onBlur(id,
|
|
61
|
+
onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
|
|
59
62
|
}
|
|
60
63
|
},
|
|
61
|
-
[onBlur, id, enumOptions, emptyValue],
|
|
64
|
+
[onBlur, id, enumOptions, emptyValue, optionValueFormat],
|
|
62
65
|
);
|
|
63
66
|
|
|
64
67
|
const handleFocus = useCallback(
|
|
65
68
|
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
66
69
|
if (onFocus) {
|
|
67
|
-
onFocus(id,
|
|
70
|
+
onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
|
|
68
71
|
}
|
|
69
72
|
},
|
|
70
|
-
[onFocus, id, enumOptions, emptyValue],
|
|
73
|
+
[onFocus, id, enumOptions, emptyValue, optionValueFormat],
|
|
71
74
|
);
|
|
72
75
|
|
|
73
|
-
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
|
|
74
|
-
|
|
75
76
|
const selectOptions = useMemo(() => {
|
|
76
77
|
if (Array.isArray(enumOptions)) {
|
|
77
78
|
return enumOptions.map((option, index) => ({
|
|
78
79
|
key: String(index),
|
|
79
|
-
value:
|
|
80
|
+
value: enumOptionValueEncoder(option.value, index, optionValueFormat),
|
|
80
81
|
label: option.label,
|
|
81
82
|
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1,
|
|
82
83
|
}));
|
|
83
84
|
}
|
|
84
85
|
return [];
|
|
85
|
-
}, [enumDisabled, enumOptions]);
|
|
86
|
+
}, [enumDisabled, enumOptions, optionValueFormat]);
|
|
86
87
|
|
|
87
|
-
const
|
|
88
|
+
const sharedProps = {
|
|
89
|
+
id,
|
|
90
|
+
name: htmlName || id,
|
|
91
|
+
label: labelValue(label || undefined, hideLabel, false),
|
|
92
|
+
data: selectOptions,
|
|
93
|
+
onChange: !readonly ? handleChange : undefined,
|
|
94
|
+
onBlur: !readonly ? handleBlur : undefined,
|
|
95
|
+
onFocus: !readonly ? handleFocus : undefined,
|
|
96
|
+
autoFocus: autofocus,
|
|
97
|
+
placeholder,
|
|
98
|
+
disabled: disabled || readonly,
|
|
99
|
+
required,
|
|
100
|
+
error: rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined,
|
|
101
|
+
searchable: true,
|
|
102
|
+
'aria-describedby': ariaDescribedByIds(id),
|
|
103
|
+
comboboxProps: { withinPortal: false },
|
|
104
|
+
...themeProps,
|
|
105
|
+
};
|
|
88
106
|
|
|
89
|
-
return (
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
onFocus={!readonly ? handleFocus : undefined}
|
|
99
|
-
autoFocus={autofocus}
|
|
100
|
-
placeholder={placeholder}
|
|
101
|
-
disabled={disabled || readonly}
|
|
102
|
-
required={required}
|
|
103
|
-
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
104
|
-
searchable
|
|
105
|
-
{...themeProps}
|
|
106
|
-
aria-describedby={ariaDescribedByIds(id)}
|
|
107
|
-
comboboxProps={{ withinPortal: false }}
|
|
107
|
+
return multiple ? (
|
|
108
|
+
<MultiSelect
|
|
109
|
+
{...sharedProps}
|
|
110
|
+
value={enumOptionSelectedValue<S>(value, enumOptions, true, optionValueFormat, []) as string[]}
|
|
111
|
+
/>
|
|
112
|
+
) : (
|
|
113
|
+
<Select
|
|
114
|
+
{...sharedProps}
|
|
115
|
+
value={enumOptionSelectedValue<S>(value, enumOptions, false, optionValueFormat, null) as string | null}
|
|
108
116
|
/>
|
|
109
117
|
);
|
|
110
118
|
}
|