@rjsf/chakra-ui 5.24.10 → 6.0.0-beta.1
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/chakra-ui.esm.js +664 -700
- package/dist/chakra-ui.esm.js.map +4 -4
- package/dist/chakra-ui.umd.js +488 -579
- package/dist/index.js +670 -708
- package/dist/index.js.map +4 -4
- package/lib/AddButton/AddButton.js +3 -3
- package/lib/AddButton/AddButton.js.map +1 -1
- package/lib/AltDateWidget/AltDateWidget.js.map +1 -1
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +2 -2
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +5 -8
- package/lib/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -1
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js +2 -2
- package/lib/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -1
- package/lib/BaseInputTemplate/BaseInputTemplate.js +4 -5
- package/lib/BaseInputTemplate/BaseInputTemplate.js.map +1 -1
- package/lib/ChakraFrameProvider.js +3 -4
- package/lib/ChakraFrameProvider.js.map +1 -1
- package/lib/CheckboxWidget/CheckboxWidget.js +5 -5
- package/lib/CheckboxWidget/CheckboxWidget.js.map +1 -1
- package/lib/CheckboxesWidget/CheckboxesWidget.js +10 -13
- package/lib/CheckboxesWidget/CheckboxesWidget.js.map +1 -1
- package/lib/DescriptionField/DescriptionField.js.map +1 -1
- package/lib/ErrorList/ErrorList.js +4 -3
- package/lib/ErrorList/ErrorList.js.map +1 -1
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js +3 -3
- package/lib/FieldErrorTemplate/FieldErrorTemplate.js.map +1 -1
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js +2 -2
- package/lib/FieldHelpTemplate/FieldHelpTemplate.js.map +1 -1
- package/lib/FieldTemplate/FieldTemplate.js +2 -2
- package/lib/FieldTemplate/FieldTemplate.js.map +1 -1
- package/lib/GridTemplate/GridTemplate.d.ts +7 -0
- package/lib/GridTemplate/GridTemplate.js +15 -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/ChakraIconButton.js +1 -1
- package/lib/IconButton/ChakraIconButton.js.map +1 -1
- package/lib/IconButton/IconButton.js +1 -1
- package/lib/IconButton/IconButton.js.map +1 -1
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js +2 -2
- package/lib/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -1
- package/lib/RadioWidget/RadioWidget.d.ts +1 -1
- package/lib/RadioWidget/RadioWidget.js +11 -11
- package/lib/RadioWidget/RadioWidget.js.map +1 -1
- package/lib/RangeWidget/RangeWidget.d.ts +1 -1
- package/lib/RangeWidget/RangeWidget.js +6 -8
- package/lib/RangeWidget/RangeWidget.js.map +1 -1
- package/lib/SelectNativeWidget/NativeSelectWidget.d.ts +12 -0
- package/lib/SelectNativeWidget/NativeSelectWidget.js +60 -0
- package/lib/SelectNativeWidget/NativeSelectWidget.js.map +1 -0
- package/lib/SelectNativeWidget/index.d.ts +2 -0
- package/lib/SelectNativeWidget/index.js +3 -0
- package/lib/SelectNativeWidget/index.js.map +1 -0
- package/lib/SelectWidget/SelectWidget.js +30 -23
- package/lib/SelectWidget/SelectWidget.js.map +1 -1
- package/lib/SubmitButton/SubmitButton.js.map +1 -1
- package/lib/Templates/Templates.js +2 -0
- package/lib/Templates/Templates.js.map +1 -1
- package/lib/TextareaWidget/TextareaWidget.d.ts +1 -1
- package/lib/TextareaWidget/TextareaWidget.js +5 -6
- package/lib/TextareaWidget/TextareaWidget.js.map +1 -1
- package/lib/TitleField/TitleField.js +2 -2
- package/lib/TitleField/TitleField.js.map +1 -1
- package/lib/UpDownWidget/UpDownWidget.js +6 -7
- package/lib/UpDownWidget/UpDownWidget.js.map +1 -1
- package/lib/Widgets/Widgets.js +2 -0
- package/lib/Widgets/Widgets.js.map +1 -1
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +4 -3
- package/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/components/ui/alert.d.ts +24 -0
- package/lib/components/ui/alert.js +9 -0
- package/lib/components/ui/alert.js.map +1 -0
- package/lib/components/ui/checkbox.d.ts +17 -0
- package/lib/components/ui/checkbox.js +17 -0
- package/lib/components/ui/checkbox.js.map +1 -0
- package/lib/components/ui/close-button.d.ts +10 -0
- package/lib/components/ui/close-button.js +16 -0
- package/lib/components/ui/close-button.js.map +1 -0
- package/lib/components/ui/field.d.ts +20 -0
- package/lib/components/ui/field.js +19 -0
- package/lib/components/ui/field.js.map +1 -0
- package/lib/components/ui/number-input.d.ts +10 -0
- package/lib/components/ui/number-input.js +20 -0
- package/lib/components/ui/number-input.js.map +1 -0
- package/lib/components/ui/radio.d.ts +16 -0
- package/lib/components/ui/radio.js +17 -0
- package/lib/components/ui/radio.js.map +1 -0
- package/lib/components/ui/select.d.ts +73 -0
- package/lib/components/ui/select.js +99 -0
- package/lib/components/ui/select.js.map +1 -0
- package/lib/components/ui/slider.d.ts +18 -0
- package/lib/components/ui/slider.js +55 -0
- package/lib/components/ui/slider.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils.d.ts +3 -6
- package/lib/utils.js +6 -7
- package/lib/utils.js.map +1 -1
- package/package.json +52 -47
- package/src/AddButton/AddButton.tsx +3 -2
- package/src/AltDateTimeWidget/AltDateTimeWidget.tsx +1 -1
- package/src/AltDateWidget/AltDateWidget.tsx +3 -3
- package/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +18 -60
- package/src/ArrayFieldTemplate/ArrayFieldTemplate.tsx +9 -7
- package/src/BaseInputTemplate/BaseInputTemplate.tsx +11 -18
- package/src/ChakraFrameProvider.tsx +3 -4
- package/src/CheckboxWidget/CheckboxWidget.tsx +13 -12
- package/src/CheckboxesWidget/CheckboxesWidget.tsx +14 -29
- package/src/DescriptionField/DescriptionField.tsx +1 -1
- package/src/ErrorList/ErrorList.tsx +16 -7
- package/src/FieldErrorTemplate/FieldErrorTemplate.tsx +5 -5
- package/src/FieldHelpTemplate/FieldHelpTemplate.tsx +3 -3
- package/src/FieldTemplate/FieldTemplate.tsx +8 -8
- package/src/Form/Form.tsx +1 -1
- package/src/GridTemplate/GridTemplate.tsx +15 -0
- package/src/GridTemplate/index.ts +2 -0
- package/src/IconButton/ChakraIconButton.tsx +7 -3
- package/src/IconButton/IconButton.tsx +5 -5
- package/src/ObjectFieldTemplate/ObjectFieldTemplate.tsx +6 -4
- package/src/RadioWidget/RadioWidget.tsx +15 -14
- package/src/RangeWidget/RangeWidget.tsx +13 -20
- package/src/SelectNativeWidget/NativeSelectWidget.tsx +134 -0
- package/src/SelectNativeWidget/index.ts +2 -0
- package/src/SelectWidget/SelectWidget.tsx +74 -46
- package/src/SubmitButton/SubmitButton.tsx +1 -1
- package/src/Templates/Templates.ts +3 -1
- package/src/TextareaWidget/TextareaWidget.tsx +11 -14
- package/src/Theme/Theme.tsx +1 -1
- package/src/TitleField/TitleField.tsx +2 -2
- package/src/UpDownWidget/UpDownWidget.tsx +21 -34
- package/src/Widgets/Widgets.ts +3 -1
- package/src/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +9 -7
- package/src/components/ui/alert.tsx +47 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/close-button.tsx +21 -0
- package/src/components/ui/field.tsx +37 -0
- package/src/components/ui/number-input.tsx +31 -0
- package/src/components/ui/radio.tsx +28 -0
- package/src/components/ui/select.tsx +171 -0
- package/src/components/ui/slider.tsx +100 -0
- package/src/tsconfig.json +3 -4
- package/src/utils.ts +8 -12
- package/LICENSE.md +0 -201
- package/lib/CssReset.d.ts +0 -23
- package/lib/CssReset.js +0 -266
- package/lib/CssReset.js.map +0 -1
- package/src/CssReset.tsx +0 -270
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FocusEvent, useMemo } from 'react';
|
|
2
|
-
|
|
1
|
+
import { FocusEvent, useMemo, useRef } from 'react';
|
|
2
|
+
|
|
3
3
|
import {
|
|
4
4
|
ariaDescribedByIds,
|
|
5
5
|
EnumOptionsType,
|
|
@@ -11,11 +11,14 @@ import {
|
|
|
11
11
|
StrictRJSFSchema,
|
|
12
12
|
WidgetProps,
|
|
13
13
|
} from '@rjsf/utils';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { OptionsOrGroups } from 'chakra-react-select';
|
|
15
|
+
import { createListCollection, SelectValueChangeDetails, Select as ChakraSelect } from '@chakra-ui/react';
|
|
16
|
+
|
|
17
|
+
import { Field } from '../components/ui/field';
|
|
18
|
+
import { SelectRoot, SelectTrigger, SelectValueText } from '../components/ui/select';
|
|
16
19
|
|
|
17
20
|
export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
18
|
-
props: WidgetProps<T, S, F
|
|
21
|
+
props: WidgetProps<T, S, F>,
|
|
19
22
|
) {
|
|
20
23
|
const {
|
|
21
24
|
id,
|
|
@@ -33,26 +36,24 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
33
36
|
onBlur,
|
|
34
37
|
onFocus,
|
|
35
38
|
rawErrors = [],
|
|
36
|
-
uiSchema,
|
|
37
39
|
schema,
|
|
38
40
|
} = props;
|
|
39
41
|
const { enumOptions, enumDisabled, emptyValue } = options;
|
|
40
|
-
const chakraProps = getChakra({ uiSchema });
|
|
41
42
|
|
|
42
|
-
const _onMultiChange = (
|
|
43
|
+
const _onMultiChange = ({ value }: SelectValueChangeDetails) => {
|
|
43
44
|
return onChange(
|
|
44
45
|
enumOptionsValueForIndex<S>(
|
|
45
|
-
|
|
46
|
-
return
|
|
46
|
+
value.map((item) => {
|
|
47
|
+
return item;
|
|
47
48
|
}),
|
|
48
49
|
enumOptions,
|
|
49
|
-
emptyValue
|
|
50
|
-
)
|
|
50
|
+
emptyValue,
|
|
51
|
+
),
|
|
51
52
|
);
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
const _onChange = (
|
|
55
|
-
return onChange(enumOptionsValueForIndex<S>(
|
|
55
|
+
const _onChange = ({ value }: SelectValueChangeDetails) => {
|
|
56
|
+
return onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
|
|
@@ -75,7 +76,7 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
75
76
|
return {
|
|
76
77
|
label,
|
|
77
78
|
value: String(index),
|
|
78
|
-
|
|
79
|
+
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(value) !== -1,
|
|
79
80
|
};
|
|
80
81
|
});
|
|
81
82
|
if (showPlaceholderOption) {
|
|
@@ -87,47 +88,74 @@ export default function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
87
88
|
|
|
88
89
|
const isMultiple = typeof multiple !== 'undefined' && multiple !== false && Boolean(enumOptions);
|
|
89
90
|
const selectedIndex = enumOptionsIndexForValue<S>(value, enumOptions, isMultiple);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
: {
|
|
98
|
-
label: valueLabelMap[selectedIndex as string] || '',
|
|
99
|
-
selectedIndex,
|
|
91
|
+
|
|
92
|
+
const getMultiValue = () =>
|
|
93
|
+
((selectedIndex as string[]) || []).map((i: string) => {
|
|
94
|
+
return {
|
|
95
|
+
label: valueLabelMap[i],
|
|
96
|
+
value: i.toString(),
|
|
100
97
|
};
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const getSingleValue = () =>
|
|
101
|
+
typeof selectedIndex !== 'undefined'
|
|
102
|
+
? [
|
|
103
|
+
{
|
|
104
|
+
label: valueLabelMap[selectedIndex as string] || '',
|
|
105
|
+
value: selectedIndex.toString(),
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
: [];
|
|
109
|
+
|
|
110
|
+
const formValue = (isMultiple ? getMultiValue() : getSingleValue()).map((item) => item.value);
|
|
111
|
+
|
|
112
|
+
const selectOptions = createListCollection({
|
|
113
|
+
items: displayEnumOptions.filter((item) => item.value),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const containerRef = useRef(null);
|
|
101
117
|
|
|
102
118
|
return (
|
|
103
|
-
<
|
|
119
|
+
<Field
|
|
120
|
+
ref={containerRef}
|
|
104
121
|
mb={1}
|
|
105
|
-
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
disabled={disabled || readonly}
|
|
123
|
+
required={required}
|
|
124
|
+
readOnly={readonly}
|
|
125
|
+
invalid={rawErrors && rawErrors.length > 0}
|
|
126
|
+
label={labelValue(label, hideLabel || !label)}
|
|
127
|
+
position='relative'
|
|
110
128
|
>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
</FormLabel>,
|
|
115
|
-
hideLabel || !label
|
|
116
|
-
)}
|
|
117
|
-
<Select
|
|
118
|
-
inputId={id}
|
|
129
|
+
<SelectRoot
|
|
130
|
+
collection={selectOptions}
|
|
131
|
+
id={id}
|
|
119
132
|
name={id}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
placeholder={placeholder}
|
|
123
|
-
closeMenuOnSelect={!isMultiple}
|
|
133
|
+
multiple={isMultiple}
|
|
134
|
+
closeOnSelect={!isMultiple}
|
|
124
135
|
onBlur={_onBlur}
|
|
125
|
-
|
|
136
|
+
onValueChange={isMultiple ? _onMultiChange : _onChange}
|
|
126
137
|
onFocus={_onFocus}
|
|
127
138
|
autoFocus={autofocus}
|
|
128
139
|
value={formValue}
|
|
129
140
|
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
positioning={{ placement: 'bottom' }}
|
|
142
|
+
>
|
|
143
|
+
<ChakraSelect.Control>
|
|
144
|
+
<SelectTrigger>
|
|
145
|
+
<SelectValueText placeholder={placeholder} />
|
|
146
|
+
</SelectTrigger>
|
|
147
|
+
</ChakraSelect.Control>
|
|
148
|
+
<ChakraSelect.Positioner minWidth='100% !important' zIndex='2 !important' top='calc(100% + 5px) !important'>
|
|
149
|
+
<ChakraSelect.Content>
|
|
150
|
+
{selectOptions.items.map((item) => (
|
|
151
|
+
<ChakraSelect.Item item={item} key={item.value}>
|
|
152
|
+
{item.label}
|
|
153
|
+
<ChakraSelect.ItemIndicator />
|
|
154
|
+
</ChakraSelect.Item>
|
|
155
|
+
))}
|
|
156
|
+
</ChakraSelect.Content>
|
|
157
|
+
</ChakraSelect.Positioner>
|
|
158
|
+
</SelectRoot>
|
|
159
|
+
</Field>
|
|
132
160
|
);
|
|
133
161
|
}
|
|
@@ -4,7 +4,7 @@ import { FormContextType, getSubmitButtonOptions, RJSFSchema, StrictRJSFSchema,
|
|
|
4
4
|
export default function SubmitButton<
|
|
5
5
|
T = any,
|
|
6
6
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
7
|
-
F extends FormContextType = any
|
|
7
|
+
F extends FormContextType = any,
|
|
8
8
|
>({ uiSchema }: SubmitButtonProps<T, S, F>) {
|
|
9
9
|
const { submitText, norender, props: submitButtonProps } = getSubmitButtonOptions(uiSchema);
|
|
10
10
|
if (norender) {
|
|
@@ -8,6 +8,7 @@ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconB
|
|
|
8
8
|
import FieldErrorTemplate from '../FieldErrorTemplate';
|
|
9
9
|
import FieldHelpTemplate from '../FieldHelpTemplate';
|
|
10
10
|
import FieldTemplate from '../FieldTemplate';
|
|
11
|
+
import GridTemplate from '../GridTemplate';
|
|
11
12
|
import ObjectFieldTemplate from '../ObjectFieldTemplate';
|
|
12
13
|
import SubmitButton from '../SubmitButton';
|
|
13
14
|
import TitleField from '../TitleField';
|
|
@@ -17,7 +18,7 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@r
|
|
|
17
18
|
export function generateTemplates<
|
|
18
19
|
T = any,
|
|
19
20
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
20
|
-
F extends FormContextType = any
|
|
21
|
+
F extends FormContextType = any,
|
|
21
22
|
>(): Partial<TemplatesType<T, S, F>> {
|
|
22
23
|
return {
|
|
23
24
|
ArrayFieldItemTemplate,
|
|
@@ -36,6 +37,7 @@ export function generateTemplates<
|
|
|
36
37
|
FieldErrorTemplate,
|
|
37
38
|
FieldHelpTemplate,
|
|
38
39
|
FieldTemplate,
|
|
40
|
+
GridTemplate,
|
|
39
41
|
ObjectFieldTemplate,
|
|
40
42
|
TitleFieldTemplate: TitleField,
|
|
41
43
|
WrapIfAdditionalTemplate,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChangeEvent, FocusEvent } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Textarea } from '@chakra-ui/react';
|
|
3
3
|
import {
|
|
4
4
|
ariaDescribedByIds,
|
|
5
5
|
labelValue,
|
|
@@ -8,12 +8,13 @@ import {
|
|
|
8
8
|
StrictRJSFSchema,
|
|
9
9
|
WidgetProps,
|
|
10
10
|
} from '@rjsf/utils';
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
import { Field } from '../components/ui/field';
|
|
12
13
|
|
|
13
14
|
export default function TextareaWidget<
|
|
14
15
|
T = any,
|
|
15
16
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
16
|
-
F extends FormContextType = any
|
|
17
|
+
F extends FormContextType = any,
|
|
17
18
|
>({
|
|
18
19
|
id,
|
|
19
20
|
placeholder,
|
|
@@ -27,27 +28,23 @@ export default function TextareaWidget<
|
|
|
27
28
|
onFocus,
|
|
28
29
|
onChange,
|
|
29
30
|
options,
|
|
30
|
-
uiSchema,
|
|
31
31
|
required,
|
|
32
32
|
rawErrors,
|
|
33
33
|
}: WidgetProps<T, S, F>) {
|
|
34
|
-
const chakraProps = getChakra({ uiSchema });
|
|
35
|
-
|
|
36
34
|
const _onChange = ({ target: { value } }: ChangeEvent<HTMLTextAreaElement>) =>
|
|
37
35
|
onChange(value === '' ? options.emptyValue : value);
|
|
38
36
|
const _onBlur = ({ target }: FocusEvent<HTMLTextAreaElement>) => onBlur(id, target && target.value);
|
|
39
37
|
const _onFocus = ({ target }: FocusEvent<HTMLTextAreaElement>) => onFocus(id, target && target.value);
|
|
40
38
|
|
|
41
39
|
return (
|
|
42
|
-
<
|
|
40
|
+
<Field
|
|
43
41
|
mb={1}
|
|
44
|
-
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
disabled={disabled || readonly}
|
|
43
|
+
required={required}
|
|
44
|
+
readOnly={readonly}
|
|
45
|
+
invalid={rawErrors && rawErrors.length > 0}
|
|
46
|
+
label={labelValue(label, hideLabel || !label)}
|
|
49
47
|
>
|
|
50
|
-
{labelValue(<FormLabel htmlFor={id}>{label}</FormLabel>, hideLabel || !label)}
|
|
51
48
|
<Textarea
|
|
52
49
|
id={id}
|
|
53
50
|
name={id}
|
|
@@ -60,6 +57,6 @@ export default function TextareaWidget<
|
|
|
60
57
|
rows={options.rows}
|
|
61
58
|
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
62
59
|
/>
|
|
63
|
-
</
|
|
60
|
+
</Field>
|
|
64
61
|
);
|
|
65
62
|
}
|
package/src/Theme/Theme.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
|
7
7
|
export function generateTheme<
|
|
8
8
|
T = any,
|
|
9
9
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
-
F extends FormContextType = any
|
|
10
|
+
F extends FormContextType = any,
|
|
11
11
|
>(): ThemeProps<T, S, F> {
|
|
12
12
|
return {
|
|
13
13
|
templates: generateTemplates<T, S, F>(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormContextType, RJSFSchema, StrictRJSFSchema, TitleFieldProps } from '@rjsf/utils';
|
|
2
|
-
import { Box,
|
|
2
|
+
import { Box, Separator, Heading } from '@chakra-ui/react';
|
|
3
3
|
|
|
4
4
|
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
5
5
|
id,
|
|
@@ -8,7 +8,7 @@ export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
8
8
|
return (
|
|
9
9
|
<Box id={id} mt={1} mb={4}>
|
|
10
10
|
<Heading as='h5'>{title}</Heading>
|
|
11
|
-
<
|
|
11
|
+
<Separator />
|
|
12
12
|
</Box>
|
|
13
13
|
);
|
|
14
14
|
}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { FocusEvent } from 'react';
|
|
2
|
-
|
|
3
|
-
NumberInput,
|
|
4
|
-
NumberDecrementStepper,
|
|
5
|
-
NumberIncrementStepper,
|
|
6
|
-
NumberInputField,
|
|
7
|
-
NumberInputStepper,
|
|
8
|
-
FormControl,
|
|
9
|
-
FormLabel,
|
|
10
|
-
} from '@chakra-ui/react';
|
|
2
|
+
|
|
11
3
|
import {
|
|
12
4
|
ariaDescribedByIds,
|
|
13
5
|
labelValue,
|
|
@@ -16,43 +8,38 @@ import {
|
|
|
16
8
|
StrictRJSFSchema,
|
|
17
9
|
WidgetProps,
|
|
18
10
|
} from '@rjsf/utils';
|
|
19
|
-
import {
|
|
11
|
+
import { NumberInputValueChangeDetails } from '@chakra-ui/react';
|
|
12
|
+
|
|
13
|
+
import { Field } from '../components/ui/field';
|
|
14
|
+
import { NumberInputRoot } from '../components/ui/number-input';
|
|
20
15
|
|
|
21
16
|
export default function UpDownWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
22
|
-
props: WidgetProps<T, S, F
|
|
17
|
+
props: WidgetProps<T, S, F>,
|
|
23
18
|
) {
|
|
24
|
-
const { id,
|
|
25
|
-
props;
|
|
26
|
-
|
|
27
|
-
const chakraProps = getChakra({ uiSchema });
|
|
19
|
+
const { id, readonly, disabled, label, hideLabel, value, onChange, onBlur, onFocus, rawErrors, required } = props;
|
|
28
20
|
|
|
29
|
-
const _onChange = (value:
|
|
21
|
+
const _onChange = ({ value }: NumberInputValueChangeDetails) => onChange(value);
|
|
30
22
|
const _onBlur = ({ target }: FocusEvent<HTMLInputElement | any>) => onBlur(id, target && target.value);
|
|
31
23
|
const _onFocus = ({ target }: FocusEvent<HTMLInputElement | any>) => onFocus(id, target && target.value);
|
|
32
24
|
|
|
33
25
|
return (
|
|
34
|
-
<
|
|
26
|
+
<Field
|
|
35
27
|
mb={1}
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
disabled={disabled || readonly}
|
|
29
|
+
required={required}
|
|
30
|
+
readOnly={readonly}
|
|
31
|
+
invalid={rawErrors && rawErrors.length > 0}
|
|
32
|
+
label={labelValue(label, hideLabel || !label)}
|
|
41
33
|
>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
onChange={_onChange}
|
|
34
|
+
<NumberInputRoot
|
|
35
|
+
value={value}
|
|
36
|
+
onValueChange={_onChange}
|
|
46
37
|
onBlur={_onBlur}
|
|
47
38
|
onFocus={_onFocus}
|
|
48
39
|
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<NumberDecrementStepper />
|
|
54
|
-
</NumberInputStepper>
|
|
55
|
-
</NumberInput>
|
|
56
|
-
</FormControl>
|
|
40
|
+
id={id}
|
|
41
|
+
name={id}
|
|
42
|
+
/>
|
|
43
|
+
</Field>
|
|
57
44
|
);
|
|
58
45
|
}
|
package/src/Widgets/Widgets.ts
CHANGED
|
@@ -5,6 +5,7 @@ import CheckboxesWidget from '../CheckboxesWidget/CheckboxesWidget';
|
|
|
5
5
|
import RadioWidget from '../RadioWidget/RadioWidget';
|
|
6
6
|
import RangeWidget from '../RangeWidget/RangeWidget';
|
|
7
7
|
import SelectWidget from '../SelectWidget/SelectWidget';
|
|
8
|
+
import NativeSelectWidget from '../SelectNativeWidget/NativeSelectWidget';
|
|
8
9
|
import TextareaWidget from '../TextareaWidget/TextareaWidget';
|
|
9
10
|
import UpDownWidget from '../UpDownWidget/UpDownWidget';
|
|
10
11
|
import { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
@@ -12,7 +13,7 @@ import { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema } fr
|
|
|
12
13
|
export function generateWidgets<
|
|
13
14
|
T = any,
|
|
14
15
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
15
|
-
F extends FormContextType = any
|
|
16
|
+
F extends FormContextType = any,
|
|
16
17
|
>(): RegistryWidgetsType<T, S, F> {
|
|
17
18
|
return {
|
|
18
19
|
AltDateTimeWidget,
|
|
@@ -22,6 +23,7 @@ export function generateWidgets<
|
|
|
22
23
|
RadioWidget,
|
|
23
24
|
RangeWidget,
|
|
24
25
|
SelectWidget,
|
|
26
|
+
NativeSelectWidget,
|
|
25
27
|
TextareaWidget,
|
|
26
28
|
UpDownWidget,
|
|
27
29
|
};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { FocusEvent } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ADDITIONAL_PROPERTY_FLAG,
|
|
4
|
+
buttonId,
|
|
4
5
|
FormContextType,
|
|
5
6
|
RJSFSchema,
|
|
6
7
|
StrictRJSFSchema,
|
|
7
8
|
TranslatableString,
|
|
8
9
|
WrapIfAdditionalTemplateProps,
|
|
9
10
|
} from '@rjsf/utils';
|
|
10
|
-
import {
|
|
11
|
+
import { Grid, GridItem, Input } from '@chakra-ui/react';
|
|
12
|
+
|
|
13
|
+
import { Field } from '../components/ui/field';
|
|
11
14
|
|
|
12
15
|
export default function WrapIfAdditionalTemplate<
|
|
13
16
|
T = any,
|
|
14
17
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
15
|
-
F extends FormContextType = any
|
|
18
|
+
F extends FormContextType = any,
|
|
16
19
|
>(props: WrapIfAdditionalTemplateProps<T, S, F>) {
|
|
17
20
|
const {
|
|
18
21
|
children,
|
|
@@ -47,10 +50,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
47
50
|
return (
|
|
48
51
|
<Grid key={`${id}-key`} className={classNames} style={style} alignItems='center' gap={2}>
|
|
49
52
|
<GridItem>
|
|
50
|
-
<
|
|
51
|
-
<FormLabel htmlFor={`${id}-key`} id={`${id}-key-label`}>
|
|
52
|
-
{keyLabel}
|
|
53
|
-
</FormLabel>
|
|
53
|
+
<Field required={required} label={keyLabel}>
|
|
54
54
|
<Input
|
|
55
55
|
defaultValue={label}
|
|
56
56
|
disabled={disabled || readonly}
|
|
@@ -60,11 +60,13 @@ export default function WrapIfAdditionalTemplate<
|
|
|
60
60
|
type='text'
|
|
61
61
|
mb={1}
|
|
62
62
|
/>
|
|
63
|
-
</
|
|
63
|
+
</Field>
|
|
64
64
|
</GridItem>
|
|
65
65
|
<GridItem>{children}</GridItem>
|
|
66
66
|
<GridItem>
|
|
67
67
|
<RemoveButton
|
|
68
|
+
id={buttonId<T>(id, 'remove')}
|
|
69
|
+
className='rjsf-object-property-remove'
|
|
68
70
|
disabled={disabled || readonly}
|
|
69
71
|
onClick={onDropPropertyClick(label)}
|
|
70
72
|
uiSchema={uiSchema}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { forwardRef, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { Alert as ChakraAlert } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
import { CloseButton } from './close-button';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Alert component that displays a message with an optional icon and close button.
|
|
8
|
+
*
|
|
9
|
+
* @param {AlertProps} props - The properties for the alert component.
|
|
10
|
+
* @param {ReactNode} [props.startElement] - The element to display at the start of the alert.
|
|
11
|
+
* @param {ReactNode} [props.endElement] - The element to display at the end of the alert.
|
|
12
|
+
* @param {ReactNode} [props.title] - The title of the alert.
|
|
13
|
+
* @param {ReactElement} [props.icon] - The icon to display in the alert.
|
|
14
|
+
* @param {boolean} [props.closable] - Whether to show the close button.
|
|
15
|
+
* @param {function} [props.onClose] - The function to call when the close button is clicked.
|
|
16
|
+
*
|
|
17
|
+
* @returns {JSX.Element} The rendered alert component.
|
|
18
|
+
*/
|
|
19
|
+
export interface AlertProps extends Omit<ChakraAlert.RootProps, 'title'> {
|
|
20
|
+
startElement?: ReactNode;
|
|
21
|
+
endElement?: ReactNode;
|
|
22
|
+
title?: ReactNode;
|
|
23
|
+
icon?: ReactElement;
|
|
24
|
+
closable?: boolean;
|
|
25
|
+
onClose?: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(props, ref) {
|
|
29
|
+
const { title, children, icon, closable, onClose, startElement, endElement, ...rest } = props;
|
|
30
|
+
return (
|
|
31
|
+
<ChakraAlert.Root ref={ref} {...rest}>
|
|
32
|
+
{startElement || <ChakraAlert.Indicator>{icon}</ChakraAlert.Indicator>}
|
|
33
|
+
{children ? (
|
|
34
|
+
<ChakraAlert.Content>
|
|
35
|
+
<ChakraAlert.Title>{title}</ChakraAlert.Title>
|
|
36
|
+
<ChakraAlert.Description>{children}</ChakraAlert.Description>
|
|
37
|
+
</ChakraAlert.Content>
|
|
38
|
+
) : (
|
|
39
|
+
<ChakraAlert.Title flex='1'>{title}</ChakraAlert.Title>
|
|
40
|
+
)}
|
|
41
|
+
{endElement}
|
|
42
|
+
{closable && (
|
|
43
|
+
<CloseButton size='sm' pos='relative' top='-2' insetEnd='-2' alignSelf='flex-start' onClick={onClose} />
|
|
44
|
+
)}
|
|
45
|
+
</ChakraAlert.Root>
|
|
46
|
+
);
|
|
47
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { forwardRef, InputHTMLAttributes, ReactNode, Ref } from 'react';
|
|
2
|
+
import { Checkbox as ChakraCheckbox } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
export interface CheckboxProps extends ChakraCheckbox.RootProps {
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
7
|
+
rootRef?: Ref<HTMLLabelElement>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Checkbox component that allows users to select or deselect an option.
|
|
12
|
+
*
|
|
13
|
+
* @param {CheckboxProps} props - The properties for the checkbox component.
|
|
14
|
+
* @param {ReactNode} [props.icon] - The icon to display in the checkbox.
|
|
15
|
+
* @param {InputHTMLAttributes<HTMLInputElement>} [props.inputProps] - Additional props for the input element.
|
|
16
|
+
* @param {Ref<HTMLLabelElement>} [props.rootRef] - Ref for the root element of the checkbox.
|
|
17
|
+
* @returns {JSX.Element} The rendered checkbox component.
|
|
18
|
+
*/
|
|
19
|
+
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(props, ref) {
|
|
20
|
+
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
21
|
+
return (
|
|
22
|
+
<ChakraCheckbox.Root ref={rootRef} {...rest}>
|
|
23
|
+
<ChakraCheckbox.HiddenInput ref={ref} {...inputProps} />
|
|
24
|
+
<ChakraCheckbox.Control>{icon || <ChakraCheckbox.Indicator />}</ChakraCheckbox.Control>
|
|
25
|
+
{children != null && <ChakraCheckbox.Label>{children}</ChakraCheckbox.Label>}
|
|
26
|
+
</ChakraCheckbox.Root>
|
|
27
|
+
);
|
|
28
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import type { ButtonProps } from '@chakra-ui/react';
|
|
3
|
+
import { IconButton as ChakraIconButton } from '@chakra-ui/react';
|
|
4
|
+
import { LuX } from 'react-icons/lu';
|
|
5
|
+
|
|
6
|
+
export type CloseButtonProps = ButtonProps;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* CloseButton component that renders a button with a close icon.
|
|
10
|
+
*
|
|
11
|
+
* @param {CloseButtonProps} props - The properties for the close button component.
|
|
12
|
+
* @param {ReactNode} [props.children] - The content to display inside the button.
|
|
13
|
+
* @returns {JSX.Element} The rendered close button component.
|
|
14
|
+
*/
|
|
15
|
+
export const CloseButton = forwardRef<HTMLButtonElement, CloseButtonProps>(function CloseButton(props, ref) {
|
|
16
|
+
return (
|
|
17
|
+
<ChakraIconButton variant='ghost' aria-label='Close' ref={ref} {...props}>
|
|
18
|
+
{props.children ?? <LuX />}
|
|
19
|
+
</ChakraIconButton>
|
|
20
|
+
);
|
|
21
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { forwardRef, ReactNode } from 'react';
|
|
2
|
+
import { Field as ChakraField } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
export interface FieldProps extends Omit<ChakraField.RootProps, 'label'> {
|
|
5
|
+
label?: ReactNode;
|
|
6
|
+
helperText?: ReactNode;
|
|
7
|
+
errorText?: ReactNode;
|
|
8
|
+
optionalText?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Field component that serves as a wrapper for form fields, providing
|
|
13
|
+
* additional functionality such as labels, helper text, and error messages.
|
|
14
|
+
*
|
|
15
|
+
* @param {FieldProps} props - The properties for the field component.
|
|
16
|
+
* @param {ReactNode} [props.label] - The label for the field.
|
|
17
|
+
* @param {ReactNode} [props.helperText] - Helper text to display below the field.
|
|
18
|
+
* @param {ReactNode} [props.errorText] - Error message to display below the field.
|
|
19
|
+
* @param {ReactNode} [props.optionalText] - Text to indicate that the field is optional.
|
|
20
|
+
* @returns {JSX.Element} The rendered field component.
|
|
21
|
+
*/
|
|
22
|
+
export const Field = forwardRef<HTMLDivElement, FieldProps>(function Field(props, ref) {
|
|
23
|
+
const { label, children, helperText, errorText, optionalText, ...rest } = props;
|
|
24
|
+
return (
|
|
25
|
+
<ChakraField.Root ref={ref} {...rest}>
|
|
26
|
+
{label && (
|
|
27
|
+
<ChakraField.Label>
|
|
28
|
+
{label}
|
|
29
|
+
<ChakraField.RequiredIndicator fallback={optionalText} />
|
|
30
|
+
</ChakraField.Label>
|
|
31
|
+
)}
|
|
32
|
+
{children}
|
|
33
|
+
{helperText && <ChakraField.HelperText>{helperText}</ChakraField.HelperText>}
|
|
34
|
+
{errorText && <ChakraField.ErrorText>{errorText}</ChakraField.ErrorText>}
|
|
35
|
+
</ChakraField.Root>
|
|
36
|
+
);
|
|
37
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
2
|
+
import { NumberInput as ChakraNumberInput } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
export type NumberInputProps = ChakraNumberInput.RootProps;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* NumberInput component that allows users to input numeric values.
|
|
8
|
+
*
|
|
9
|
+
* @param {NumberInputProps} props - The properties for the number input component.
|
|
10
|
+
* @param {ReactNode} [props.children] - The content to display inside the number input.
|
|
11
|
+
* @returns {JSX.Element} The rendered number input component.
|
|
12
|
+
*/
|
|
13
|
+
export const NumberInputRoot = forwardRef<HTMLDivElement, NumberInputProps>(function NumberInput(props, ref) {
|
|
14
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (inputRef.current) {
|
|
18
|
+
inputRef.current.value = props.value || '';
|
|
19
|
+
}
|
|
20
|
+
}, [props.value]);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<ChakraNumberInput.Root ref={ref} variant='outline' {...props}>
|
|
24
|
+
<ChakraNumberInput.Control>
|
|
25
|
+
<ChakraNumberInput.IncrementTrigger />
|
|
26
|
+
<ChakraNumberInput.DecrementTrigger />
|
|
27
|
+
</ChakraNumberInput.Control>
|
|
28
|
+
<ChakraNumberInput.Input ref={inputRef} />
|
|
29
|
+
</ChakraNumberInput.Root>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { forwardRef, InputHTMLAttributes, Ref } from 'react';
|
|
2
|
+
import { RadioGroup as ChakraRadioGroup } from '@chakra-ui/react';
|
|
3
|
+
|
|
4
|
+
export interface RadioProps extends ChakraRadioGroup.ItemProps {
|
|
5
|
+
rootRef?: Ref<HTMLDivElement>;
|
|
6
|
+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Radio component that allows users to select a single option from a set.
|
|
11
|
+
*
|
|
12
|
+
* @param {RadioProps} props - The properties for the radio component.
|
|
13
|
+
* @param {InputHTMLAttributes<HTMLInputElement>} [props.inputProps] - Additional props for the input element.
|
|
14
|
+
* @param {Ref<HTMLDivElement>} [props.rootRef] - Ref for the root element of the radio.
|
|
15
|
+
* @returns {JSX.Element} The rendered radio component.
|
|
16
|
+
*/
|
|
17
|
+
export const Radio = forwardRef<HTMLInputElement, RadioProps>(function Radio(props, ref) {
|
|
18
|
+
const { children, inputProps, rootRef, ...rest } = props;
|
|
19
|
+
return (
|
|
20
|
+
<ChakraRadioGroup.Item ref={rootRef} {...rest}>
|
|
21
|
+
<ChakraRadioGroup.ItemHiddenInput ref={ref} {...inputProps} />
|
|
22
|
+
<ChakraRadioGroup.ItemIndicator />
|
|
23
|
+
{children && <ChakraRadioGroup.ItemText>{children}</ChakraRadioGroup.ItemText>}
|
|
24
|
+
</ChakraRadioGroup.Item>
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const RadioGroup = ChakraRadioGroup.Root;
|