@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,134 @@
|
|
|
1
|
+
import { ChangeEvent, FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
BaseInputTemplateProps,
|
|
5
|
+
examplesId,
|
|
6
|
+
getInputProps,
|
|
7
|
+
labelValue,
|
|
8
|
+
FormContextType,
|
|
9
|
+
RJSFSchema,
|
|
10
|
+
StrictRJSFSchema,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { TextInput, NumberInput } from '@mantine/core';
|
|
13
|
+
|
|
14
|
+
import { cleanupOptions } from '../utils';
|
|
15
|
+
|
|
16
|
+
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
|
|
17
|
+
* It is used as the template for rendering many of the <input> based widgets that differ by `type` and callbacks only.
|
|
18
|
+
* It can be customized/overridden for other themes or individual implementations as needed.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The `WidgetProps` for this template
|
|
21
|
+
*/
|
|
22
|
+
export default function BaseInputTemplate<
|
|
23
|
+
T = any,
|
|
24
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
25
|
+
F extends FormContextType = any,
|
|
26
|
+
>(props: BaseInputTemplateProps<T, S, F>) {
|
|
27
|
+
const {
|
|
28
|
+
id,
|
|
29
|
+
type,
|
|
30
|
+
schema,
|
|
31
|
+
value,
|
|
32
|
+
placeholder,
|
|
33
|
+
required,
|
|
34
|
+
disabled,
|
|
35
|
+
readonly,
|
|
36
|
+
autofocus,
|
|
37
|
+
label,
|
|
38
|
+
hideLabel,
|
|
39
|
+
onChange,
|
|
40
|
+
onChangeOverride,
|
|
41
|
+
onBlur,
|
|
42
|
+
onFocus,
|
|
43
|
+
options,
|
|
44
|
+
rawErrors,
|
|
45
|
+
children,
|
|
46
|
+
} = props;
|
|
47
|
+
|
|
48
|
+
const inputProps = getInputProps<T, S, F>(schema, type, options, false);
|
|
49
|
+
const themeProps = cleanupOptions(options);
|
|
50
|
+
|
|
51
|
+
const handleNumberChange = useCallback((value: number | string) => onChange(value), [onChange]);
|
|
52
|
+
|
|
53
|
+
const handleChange = useCallback(
|
|
54
|
+
(e: ChangeEvent<HTMLInputElement>) => {
|
|
55
|
+
const handler = onChangeOverride ? onChangeOverride : onChange;
|
|
56
|
+
const value = e.target.value === '' ? (options.emptyValue ?? '') : e.target.value;
|
|
57
|
+
handler(value);
|
|
58
|
+
},
|
|
59
|
+
[onChange, onChangeOverride, options],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const handleBlur = useCallback(
|
|
63
|
+
(e: FocusEvent<HTMLInputElement>) => {
|
|
64
|
+
onBlur(id, e.target && e.target.value);
|
|
65
|
+
},
|
|
66
|
+
[onBlur, id],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const handleFocus = useCallback(
|
|
70
|
+
(e: FocusEvent<HTMLInputElement>) => {
|
|
71
|
+
onFocus(id, e.target && e.target.value);
|
|
72
|
+
},
|
|
73
|
+
[onFocus, id],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const input =
|
|
77
|
+
inputProps.type === 'number' || inputProps.type === 'integer' ? (
|
|
78
|
+
<NumberInput
|
|
79
|
+
id={id}
|
|
80
|
+
name={id}
|
|
81
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
82
|
+
required={required}
|
|
83
|
+
autoFocus={autofocus}
|
|
84
|
+
disabled={disabled || readonly}
|
|
85
|
+
onBlur={!readonly ? handleBlur : undefined}
|
|
86
|
+
onChange={!readonly ? handleNumberChange : undefined}
|
|
87
|
+
onFocus={!readonly ? handleFocus : undefined}
|
|
88
|
+
placeholder={placeholder}
|
|
89
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
90
|
+
list={schema.examples ? examplesId<T>(id) : undefined}
|
|
91
|
+
{...inputProps}
|
|
92
|
+
{...themeProps}
|
|
93
|
+
step={typeof inputProps.step === 'number' ? inputProps.step : 1}
|
|
94
|
+
type='text'
|
|
95
|
+
value={value}
|
|
96
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
97
|
+
/>
|
|
98
|
+
) : (
|
|
99
|
+
<TextInput
|
|
100
|
+
id={id}
|
|
101
|
+
name={id}
|
|
102
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
103
|
+
required={required}
|
|
104
|
+
autoFocus={autofocus}
|
|
105
|
+
disabled={disabled || readonly}
|
|
106
|
+
onBlur={!readonly ? handleBlur : undefined}
|
|
107
|
+
onChange={!readonly ? handleChange : undefined}
|
|
108
|
+
onFocus={!readonly ? handleFocus : undefined}
|
|
109
|
+
placeholder={placeholder}
|
|
110
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
111
|
+
list={schema.examples ? examplesId<T>(id) : undefined}
|
|
112
|
+
{...inputProps}
|
|
113
|
+
{...themeProps}
|
|
114
|
+
value={value}
|
|
115
|
+
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<>
|
|
121
|
+
{input}
|
|
122
|
+
{children}
|
|
123
|
+
{Array.isArray(schema.examples) && (
|
|
124
|
+
<datalist id={examplesId<T>(id)}>
|
|
125
|
+
{(schema.examples as string[])
|
|
126
|
+
.concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
|
|
127
|
+
.map((example) => {
|
|
128
|
+
return <option key={example} value={example} />;
|
|
129
|
+
})}
|
|
130
|
+
</datalist>
|
|
131
|
+
)}
|
|
132
|
+
</>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import IconButton from './IconButton';
|
|
4
|
+
import { Plus } from '../icons';
|
|
5
|
+
|
|
6
|
+
/** The `AddButton` renders a button that represent the `Add` action on a form
|
|
7
|
+
*/
|
|
8
|
+
export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
9
|
+
props: IconButtonProps<T, S, F>,
|
|
10
|
+
) {
|
|
11
|
+
const {
|
|
12
|
+
registry: { translateString },
|
|
13
|
+
} = props;
|
|
14
|
+
return (
|
|
15
|
+
<IconButton title={translateString(TranslatableString.AddItemButton)} variant='subtle' {...props} icon={<Plus />} />
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { MouseEventHandler } from 'react';
|
|
2
|
+
import { ActionIcon, ActionIconProps } from '@mantine/core';
|
|
3
|
+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
4
|
+
|
|
5
|
+
import { Copy, ChevronDown, ChevronUp, X } from '../icons';
|
|
6
|
+
|
|
7
|
+
export type MantineIconButtonProps<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any,
|
|
11
|
+
> = IconButtonProps<T, S, F> & Omit<ActionIconProps, 'onClick'>;
|
|
12
|
+
|
|
13
|
+
export default function IconButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
14
|
+
props: MantineIconButtonProps<T, S, F>,
|
|
15
|
+
) {
|
|
16
|
+
const { icon, iconType = 'sm', color, onClick, uiSchema, registry, ...otherProps } = props;
|
|
17
|
+
return (
|
|
18
|
+
<ActionIcon
|
|
19
|
+
size={iconType as ActionIconProps['size']}
|
|
20
|
+
color={color as ActionIconProps['color']}
|
|
21
|
+
onClick={onClick as MouseEventHandler<HTMLAnchorElement> & MouseEventHandler<HTMLButtonElement>}
|
|
22
|
+
{...otherProps}
|
|
23
|
+
>
|
|
24
|
+
{icon}
|
|
25
|
+
</ActionIcon>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function CopyButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
30
|
+
props: MantineIconButtonProps<T, S, F>,
|
|
31
|
+
) {
|
|
32
|
+
const {
|
|
33
|
+
registry: { translateString },
|
|
34
|
+
} = props;
|
|
35
|
+
return (
|
|
36
|
+
<IconButton title={translateString(TranslatableString.CopyButton)} variant='subtle' {...props} icon={<Copy />} />
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function MoveDownButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
41
|
+
props: MantineIconButtonProps<T, S, F>,
|
|
42
|
+
) {
|
|
43
|
+
const {
|
|
44
|
+
registry: { translateString },
|
|
45
|
+
} = props;
|
|
46
|
+
return (
|
|
47
|
+
<IconButton
|
|
48
|
+
title={translateString(TranslatableString.MoveDownButton)}
|
|
49
|
+
variant='subtle'
|
|
50
|
+
{...props}
|
|
51
|
+
icon={<ChevronDown />}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function MoveUpButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
57
|
+
props: MantineIconButtonProps<T, S, F>,
|
|
58
|
+
) {
|
|
59
|
+
const {
|
|
60
|
+
registry: { translateString },
|
|
61
|
+
} = props;
|
|
62
|
+
return (
|
|
63
|
+
<IconButton
|
|
64
|
+
title={translateString(TranslatableString.MoveUpButton)}
|
|
65
|
+
variant='subtle'
|
|
66
|
+
{...props}
|
|
67
|
+
icon={<ChevronUp />}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
73
|
+
props: MantineIconButtonProps<T, S, F>,
|
|
74
|
+
) {
|
|
75
|
+
const {
|
|
76
|
+
registry: { translateString },
|
|
77
|
+
} = props;
|
|
78
|
+
return (
|
|
79
|
+
<IconButton
|
|
80
|
+
title={translateString(TranslatableString.RemoveButton)}
|
|
81
|
+
variant='subtle'
|
|
82
|
+
color='red'
|
|
83
|
+
{...props}
|
|
84
|
+
icon={<X />}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Button } from '@mantine/core';
|
|
2
|
+
import { getSubmitButtonOptions, FormContextType, RJSFSchema, StrictRJSFSchema, SubmitButtonProps } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
/** The `SubmitButton` renders a button that represent the `Submit` action on a form
|
|
5
|
+
*/
|
|
6
|
+
export default function SubmitButton<
|
|
7
|
+
T = any,
|
|
8
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
9
|
+
F extends FormContextType = any,
|
|
10
|
+
>({ uiSchema }: SubmitButtonProps<T, S, F>) {
|
|
11
|
+
const { submitText, norender, props: submitButtonProps = {} } = getSubmitButtonOptions(uiSchema);
|
|
12
|
+
if (norender) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return (
|
|
16
|
+
<Button type='submit' variant='filled' {...submitButtonProps}>
|
|
17
|
+
{submitText}
|
|
18
|
+
</Button>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@rjsf/utils';
|
|
2
|
+
import SubmitButton from './SubmitButton';
|
|
3
|
+
import AddButton from './AddButton';
|
|
4
|
+
import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from './IconButton';
|
|
5
|
+
|
|
6
|
+
function buttonTemplates<
|
|
7
|
+
T = any,
|
|
8
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
9
|
+
F extends FormContextType = any,
|
|
10
|
+
>(): TemplatesType<T, S, F>['ButtonTemplates'] {
|
|
11
|
+
return {
|
|
12
|
+
SubmitButton,
|
|
13
|
+
AddButton,
|
|
14
|
+
CopyButton,
|
|
15
|
+
MoveDownButton,
|
|
16
|
+
MoveUpButton,
|
|
17
|
+
RemoveButton,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default buttonTemplates;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DescriptionFieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { RichDescription } from '@rjsf/core';
|
|
3
|
+
import { Text } from '@mantine/core';
|
|
4
|
+
|
|
5
|
+
/** The `DescriptionField` is the template to use to render the description of a field
|
|
6
|
+
*
|
|
7
|
+
* @param props - The `DescriptionFieldProps` for this component
|
|
8
|
+
*/
|
|
9
|
+
export default function DescriptionField<
|
|
10
|
+
T = any,
|
|
11
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
12
|
+
F extends FormContextType = any,
|
|
13
|
+
>(props: DescriptionFieldProps<T, S, F>) {
|
|
14
|
+
const { id, description, registry, uiSchema } = props;
|
|
15
|
+
if (description) {
|
|
16
|
+
return (
|
|
17
|
+
<Text id={id} mt={3} mb='sm'>
|
|
18
|
+
<RichDescription description={description} registry={registry} uiSchema={uiSchema} />
|
|
19
|
+
</Text>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ErrorListProps, FormContextType, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
|
|
2
|
+
import { Alert, Title, List } from '@mantine/core';
|
|
3
|
+
|
|
4
|
+
import { ExclamationCircle } from './icons';
|
|
5
|
+
|
|
6
|
+
/** The `ErrorList` component is the template that renders the all the errors associated with the fields in the `Form`
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `ErrorListProps` for this component
|
|
9
|
+
*/
|
|
10
|
+
export default function ErrorList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
11
|
+
errors,
|
|
12
|
+
registry,
|
|
13
|
+
}: ErrorListProps<T, S, F>) {
|
|
14
|
+
const { translateString } = registry;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Alert
|
|
18
|
+
color='red'
|
|
19
|
+
variant='transparent'
|
|
20
|
+
title={
|
|
21
|
+
<Title order={5} fw='normal'>
|
|
22
|
+
{translateString(TranslatableString.ErrorsLabel)}
|
|
23
|
+
</Title>
|
|
24
|
+
}
|
|
25
|
+
icon={<ExclamationCircle />}
|
|
26
|
+
>
|
|
27
|
+
<List>
|
|
28
|
+
{errors.map((error, index) => (
|
|
29
|
+
<List.Item key={`error-${index}`} c='red'>
|
|
30
|
+
{error.stack}
|
|
31
|
+
</List.Item>
|
|
32
|
+
))}
|
|
33
|
+
</List>
|
|
34
|
+
</Alert>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { Box, List } from '@mantine/core';
|
|
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) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
// In mantine, errors are handled directly in each component, so there is no need to render a separate error template.
|
|
17
|
+
const id = errorId<T>(idSchema);
|
|
18
|
+
return (
|
|
19
|
+
<Box id={id} c='red' display='none'>
|
|
20
|
+
<List>
|
|
21
|
+
{errors.map((error, index) => (
|
|
22
|
+
<List.Item key={`field-error-${index}`}>{error}</List.Item>
|
|
23
|
+
))}
|
|
24
|
+
</List>
|
|
25
|
+
</Box>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { helpId, FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { Text } from '@mantine/core';
|
|
3
|
+
|
|
4
|
+
/** The `FieldHelpTemplate` component renders any help desired for a field
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `FieldHelpProps` to be rendered
|
|
7
|
+
*/
|
|
8
|
+
export default function FieldHelpTemplate<
|
|
9
|
+
T = any,
|
|
10
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
11
|
+
F extends FormContextType = any,
|
|
12
|
+
>(props: FieldHelpProps<T, S, F>) {
|
|
13
|
+
const { idSchema, help } = props;
|
|
14
|
+
|
|
15
|
+
const id = helpId<T>(idSchema);
|
|
16
|
+
|
|
17
|
+
return !help ? null : (
|
|
18
|
+
<Text id={id} size='sm' my='xs' c='dimmed'>
|
|
19
|
+
{help}
|
|
20
|
+
</Text>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Box } from '@mantine/core';
|
|
2
|
+
import {
|
|
3
|
+
FieldTemplateProps,
|
|
4
|
+
FormContextType,
|
|
5
|
+
RJSFSchema,
|
|
6
|
+
StrictRJSFSchema,
|
|
7
|
+
getTemplate,
|
|
8
|
+
getUiOptions,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
|
|
11
|
+
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
|
|
12
|
+
* content, (label, description, children, errors and help) inside a `WrapIfAdditional` component.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The `FieldTemplateProps` for this component
|
|
15
|
+
*/
|
|
16
|
+
export default function FieldTemplate<
|
|
17
|
+
T = any,
|
|
18
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
|
+
F extends FormContextType = any,
|
|
20
|
+
>(props: FieldTemplateProps<T, S, F>) {
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
classNames,
|
|
24
|
+
style,
|
|
25
|
+
label,
|
|
26
|
+
errors,
|
|
27
|
+
help,
|
|
28
|
+
displayLabel,
|
|
29
|
+
description,
|
|
30
|
+
rawDescription,
|
|
31
|
+
hidden,
|
|
32
|
+
schema,
|
|
33
|
+
uiSchema,
|
|
34
|
+
registry,
|
|
35
|
+
children,
|
|
36
|
+
...otherProps
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
40
|
+
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
|
|
41
|
+
'WrapIfAdditionalTemplate',
|
|
42
|
+
registry,
|
|
43
|
+
uiOptions,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (hidden) {
|
|
47
|
+
return <Box display='none'>{children}</Box>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<WrapIfAdditionalTemplate
|
|
52
|
+
id={id}
|
|
53
|
+
classNames={classNames}
|
|
54
|
+
style={style}
|
|
55
|
+
label={label}
|
|
56
|
+
schema={schema}
|
|
57
|
+
uiSchema={uiSchema}
|
|
58
|
+
registry={registry}
|
|
59
|
+
{...otherProps}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
{errors}
|
|
63
|
+
{help}
|
|
64
|
+
</WrapIfAdditionalTemplate>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Container, Grid } from '@mantine/core';
|
|
2
|
+
import { GridTemplateProps } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
/** Renders a `GridTemplate` for mantine, which is expecting the column sizing information coming in via the
|
|
5
|
+
* extra props provided by the caller, which are spread directly on the `Grid`/`Grid.Col`.
|
|
6
|
+
*
|
|
7
|
+
* @param props - The GridTemplateProps, including the extra props containing the Mantine grid positioning details
|
|
8
|
+
*/
|
|
9
|
+
export default function GridTemplate(props: GridTemplateProps) {
|
|
10
|
+
const { children, column, fluid = true, ...rest } = props;
|
|
11
|
+
|
|
12
|
+
if (column) {
|
|
13
|
+
return <Grid.Col {...rest}>{children}</Grid.Col>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Grid with fluid container
|
|
17
|
+
if (fluid) {
|
|
18
|
+
return (
|
|
19
|
+
<Container p='4' mx={0} w='100%'>
|
|
20
|
+
<Grid {...rest}>{children}</Grid>
|
|
21
|
+
</Container>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
// Grid without container
|
|
25
|
+
return (
|
|
26
|
+
<Grid grow {...rest}>
|
|
27
|
+
{children}
|
|
28
|
+
</Grid>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Stack } from '@mantine/core';
|
|
2
|
+
import { FormContextType, MultiSchemaFieldTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
3
|
+
|
|
4
|
+
export default function MultiSchemaFieldTemplate<
|
|
5
|
+
T = any,
|
|
6
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
7
|
+
F extends FormContextType = any,
|
|
8
|
+
>({ selector, optionSchemaField }: MultiSchemaFieldTemplateProps<T, S, F>) {
|
|
9
|
+
return (
|
|
10
|
+
<Stack style={{ marginBottom: '1rem' }}>
|
|
11
|
+
{selector}
|
|
12
|
+
{optionSchemaField}
|
|
13
|
+
</Stack>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Box, Container, Group, MantineSpacing, SimpleGrid } from '@mantine/core';
|
|
2
|
+
import {
|
|
3
|
+
buttonId,
|
|
4
|
+
canExpand,
|
|
5
|
+
descriptionId,
|
|
6
|
+
FormContextType,
|
|
7
|
+
getTemplate,
|
|
8
|
+
getUiOptions,
|
|
9
|
+
ObjectFieldTemplatePropertyType,
|
|
10
|
+
ObjectFieldTemplateProps,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
titleId,
|
|
14
|
+
} from '@rjsf/utils';
|
|
15
|
+
|
|
16
|
+
/** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
|
|
17
|
+
* title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
|
|
18
|
+
* the properties.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The `ObjectFieldTemplateProps` for this component
|
|
21
|
+
*/
|
|
22
|
+
export default function ObjectFieldTemplate<
|
|
23
|
+
T = any,
|
|
24
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
25
|
+
F extends FormContextType = any,
|
|
26
|
+
>(props: ObjectFieldTemplateProps<T, S, F>) {
|
|
27
|
+
const {
|
|
28
|
+
title,
|
|
29
|
+
description,
|
|
30
|
+
disabled,
|
|
31
|
+
properties,
|
|
32
|
+
onAddClick,
|
|
33
|
+
readonly,
|
|
34
|
+
required,
|
|
35
|
+
schema,
|
|
36
|
+
uiSchema,
|
|
37
|
+
idSchema,
|
|
38
|
+
formData,
|
|
39
|
+
registry,
|
|
40
|
+
} = props;
|
|
41
|
+
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
42
|
+
const TitleFieldTemplate = getTemplate<'TitleFieldTemplate', T, S, F>('TitleFieldTemplate', registry, uiOptions);
|
|
43
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
44
|
+
'DescriptionFieldTemplate',
|
|
45
|
+
registry,
|
|
46
|
+
uiOptions,
|
|
47
|
+
);
|
|
48
|
+
// Button templates are not overridden in the uiSchema
|
|
49
|
+
const {
|
|
50
|
+
ButtonTemplates: { AddButton },
|
|
51
|
+
} = registry.templates;
|
|
52
|
+
const gridCols = (typeof uiOptions?.gridCols === 'number' && uiOptions?.gridCols) || undefined;
|
|
53
|
+
const gridSpacing = uiOptions?.gridSpacing;
|
|
54
|
+
const gridVerticalSpacing = uiOptions?.gridVerticalSpacing;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Container id={idSchema.$id} p={0}>
|
|
58
|
+
{title && (
|
|
59
|
+
<TitleFieldTemplate
|
|
60
|
+
id={titleId<T>(idSchema)}
|
|
61
|
+
title={title}
|
|
62
|
+
required={required}
|
|
63
|
+
schema={schema}
|
|
64
|
+
uiSchema={uiSchema}
|
|
65
|
+
registry={registry}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
68
|
+
{description && (
|
|
69
|
+
<DescriptionFieldTemplate
|
|
70
|
+
id={descriptionId<T>(idSchema)}
|
|
71
|
+
description={description}
|
|
72
|
+
schema={schema}
|
|
73
|
+
uiSchema={uiSchema}
|
|
74
|
+
registry={registry}
|
|
75
|
+
/>
|
|
76
|
+
)}
|
|
77
|
+
<SimpleGrid
|
|
78
|
+
cols={gridCols}
|
|
79
|
+
spacing={gridSpacing as MantineSpacing | undefined}
|
|
80
|
+
verticalSpacing={gridVerticalSpacing as MantineSpacing | undefined}
|
|
81
|
+
mb='sm'
|
|
82
|
+
>
|
|
83
|
+
{properties
|
|
84
|
+
.filter((e) => !e.hidden)
|
|
85
|
+
.map((element: ObjectFieldTemplatePropertyType) => (
|
|
86
|
+
<Box key={element.name}>{element.content}</Box>
|
|
87
|
+
))}
|
|
88
|
+
</SimpleGrid>
|
|
89
|
+
|
|
90
|
+
{canExpand(schema, uiSchema, formData) && (
|
|
91
|
+
<Group mt='xs' justify='flex-end'>
|
|
92
|
+
<AddButton
|
|
93
|
+
id={buttonId<T>(idSchema, 'add')}
|
|
94
|
+
disabled={disabled || readonly}
|
|
95
|
+
onClick={onAddClick(schema)}
|
|
96
|
+
className='rjsf-object-property-expand'
|
|
97
|
+
uiSchema={uiSchema}
|
|
98
|
+
registry={registry}
|
|
99
|
+
/>
|
|
100
|
+
</Group>
|
|
101
|
+
)}
|
|
102
|
+
</Container>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormContextType, TitleFieldProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { Title } from '@mantine/core';
|
|
3
|
+
|
|
4
|
+
/** The `TitleField` is the template to use to render the title of a field
|
|
5
|
+
*
|
|
6
|
+
* @param props - The `TitleFieldProps` for this component
|
|
7
|
+
*/
|
|
8
|
+
export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
9
|
+
props: TitleFieldProps<T, S, F>,
|
|
10
|
+
) {
|
|
11
|
+
const { id, title } = props;
|
|
12
|
+
return title ? (
|
|
13
|
+
<Title id={id} order={3} fw='normal'>
|
|
14
|
+
{title}
|
|
15
|
+
</Title>
|
|
16
|
+
) : null;
|
|
17
|
+
}
|