@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,99 @@
|
|
|
1
|
+
import { FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ADDITIONAL_PROPERTY_FLAG,
|
|
4
|
+
UI_OPTIONS_KEY,
|
|
5
|
+
buttonId,
|
|
6
|
+
FormContextType,
|
|
7
|
+
RJSFSchema,
|
|
8
|
+
StrictRJSFSchema,
|
|
9
|
+
TranslatableString,
|
|
10
|
+
WrapIfAdditionalTemplateProps,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { Flex, Grid, TextInput } from '@mantine/core';
|
|
13
|
+
|
|
14
|
+
/** The `WrapIfAdditional` component is used by the `FieldTemplate` to rename, or remove properties that are
|
|
15
|
+
* part of an `additionalProperties` part of a schema.
|
|
16
|
+
*
|
|
17
|
+
* @param props - The `WrapIfAdditionalProps` for this component
|
|
18
|
+
*/
|
|
19
|
+
export default function WrapIfAdditionalTemplate<
|
|
20
|
+
T = any,
|
|
21
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
22
|
+
F extends FormContextType = any,
|
|
23
|
+
>(props: WrapIfAdditionalTemplateProps<T, S, F>) {
|
|
24
|
+
const {
|
|
25
|
+
id,
|
|
26
|
+
classNames,
|
|
27
|
+
style,
|
|
28
|
+
label,
|
|
29
|
+
required,
|
|
30
|
+
readonly,
|
|
31
|
+
disabled,
|
|
32
|
+
schema,
|
|
33
|
+
uiSchema,
|
|
34
|
+
onKeyChange,
|
|
35
|
+
onDropPropertyClick,
|
|
36
|
+
registry,
|
|
37
|
+
children,
|
|
38
|
+
} = props;
|
|
39
|
+
const { templates, translateString } = registry;
|
|
40
|
+
// Button templates are not overridden in the uiSchema
|
|
41
|
+
const { RemoveButton } = templates.ButtonTemplates;
|
|
42
|
+
const keyLabel = translateString(TranslatableString.KeyLabel, [label]);
|
|
43
|
+
const additional = ADDITIONAL_PROPERTY_FLAG in schema;
|
|
44
|
+
|
|
45
|
+
const handleBlur = useCallback(
|
|
46
|
+
({ target }: FocusEvent<HTMLInputElement>) => onKeyChange(target && target.value),
|
|
47
|
+
[onKeyChange],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (!additional) {
|
|
51
|
+
return (
|
|
52
|
+
<div className={classNames} style={style}>
|
|
53
|
+
{children}
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The `block` prop is not part of the `IconButtonProps` defined in the template, so put it into the uiSchema instead
|
|
59
|
+
const uiOptions = uiSchema ? uiSchema[UI_OPTIONS_KEY] : {};
|
|
60
|
+
const buttonUiOptions = {
|
|
61
|
+
...uiSchema,
|
|
62
|
+
[UI_OPTIONS_KEY]: { ...uiOptions, block: true },
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className={classNames} style={style}>
|
|
67
|
+
<Flex gap='xs' align='end' justify='center'>
|
|
68
|
+
<Grid w='100%' align='center'>
|
|
69
|
+
<Grid.Col span={6} className='form-additional'>
|
|
70
|
+
<div className='form-group'>
|
|
71
|
+
<TextInput
|
|
72
|
+
className='form-group'
|
|
73
|
+
label={keyLabel}
|
|
74
|
+
defaultValue={label}
|
|
75
|
+
required={required}
|
|
76
|
+
disabled={disabled || readonly}
|
|
77
|
+
id={`${id}-key`}
|
|
78
|
+
name={`${id}-key`}
|
|
79
|
+
onBlur={!readonly ? handleBlur : undefined}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
</Grid.Col>
|
|
83
|
+
<Grid.Col span={6} className='form-additional'>
|
|
84
|
+
{children}
|
|
85
|
+
</Grid.Col>
|
|
86
|
+
</Grid>
|
|
87
|
+
<RemoveButton
|
|
88
|
+
id={buttonId<T>(id, 'remove')}
|
|
89
|
+
iconType='sm'
|
|
90
|
+
className='rjsf-array-item-remove'
|
|
91
|
+
disabled={disabled || readonly}
|
|
92
|
+
onClick={onDropPropertyClick(label)}
|
|
93
|
+
uiSchema={buttonUiOptions}
|
|
94
|
+
registry={registry}
|
|
95
|
+
/>
|
|
96
|
+
</Flex>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
|
|
3
|
+
interface IconProps extends ComponentPropsWithoutRef<'svg'> {
|
|
4
|
+
size?: number | string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function Plus({ size, style, ...others }: IconProps) {
|
|
8
|
+
return (
|
|
9
|
+
<svg
|
|
10
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
11
|
+
width='24'
|
|
12
|
+
height='24'
|
|
13
|
+
viewBox='0 0 24 24'
|
|
14
|
+
fill='none'
|
|
15
|
+
stroke='currentColor'
|
|
16
|
+
strokeWidth='2'
|
|
17
|
+
strokeLinecap='round'
|
|
18
|
+
strokeLinejoin='round'
|
|
19
|
+
className='icon icon-tabler icons-tabler-outline icon-tabler-plus'
|
|
20
|
+
style={{ width: size, height: size, ...style }}
|
|
21
|
+
{...others}
|
|
22
|
+
>
|
|
23
|
+
<path stroke='none' d='M0 0h24v24H0z' fill='none' />
|
|
24
|
+
<path d='M12 5l0 14' />
|
|
25
|
+
<path d='M5 12l14 0' />
|
|
26
|
+
</svg>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function Copy({ size, style, ...others }: IconProps) {
|
|
31
|
+
return (
|
|
32
|
+
<svg
|
|
33
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
34
|
+
width='24'
|
|
35
|
+
height='24'
|
|
36
|
+
viewBox='0 0 24 24'
|
|
37
|
+
fill='none'
|
|
38
|
+
stroke='currentColor'
|
|
39
|
+
strokeWidth='2'
|
|
40
|
+
strokeLinecap='round'
|
|
41
|
+
strokeLinejoin='round'
|
|
42
|
+
className='icon icon-tabler icons-tabler-outline icon-tabler-copy'
|
|
43
|
+
style={{ width: size, height: size, ...style }}
|
|
44
|
+
{...others}
|
|
45
|
+
>
|
|
46
|
+
<path stroke='none' d='M0 0h24v24H0z' fill='none' />
|
|
47
|
+
<path d='M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z' />
|
|
48
|
+
<path d='M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1' />
|
|
49
|
+
</svg>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function ChevronDown({ size, style, ...others }: IconProps) {
|
|
54
|
+
return (
|
|
55
|
+
<svg
|
|
56
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
57
|
+
width='24'
|
|
58
|
+
height='24'
|
|
59
|
+
viewBox='0 0 24 24'
|
|
60
|
+
fill='none'
|
|
61
|
+
stroke='currentColor'
|
|
62
|
+
strokeWidth='2'
|
|
63
|
+
strokeLinecap='round'
|
|
64
|
+
strokeLinejoin='round'
|
|
65
|
+
className='icon icon-tabler icons-tabler-outline icon-tabler-chevron-down'
|
|
66
|
+
style={{ width: size, height: size, ...style }}
|
|
67
|
+
{...others}
|
|
68
|
+
>
|
|
69
|
+
<path stroke='none' d='M0 0h24v24H0z' fill='none' />
|
|
70
|
+
<path d='M6 9l6 6l6 -6' />
|
|
71
|
+
</svg>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function ChevronUp({ size, style, ...others }: IconProps) {
|
|
76
|
+
return (
|
|
77
|
+
<svg
|
|
78
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
79
|
+
width='24'
|
|
80
|
+
height='24'
|
|
81
|
+
viewBox='0 0 24 24'
|
|
82
|
+
fill='none'
|
|
83
|
+
stroke='currentColor'
|
|
84
|
+
strokeWidth='2'
|
|
85
|
+
strokeLinecap='round'
|
|
86
|
+
strokeLinejoin='round'
|
|
87
|
+
className='icon icon-tabler icons-tabler-outline icon-tabler-chevron-up'
|
|
88
|
+
style={{ width: size, height: size, ...style }}
|
|
89
|
+
{...others}
|
|
90
|
+
>
|
|
91
|
+
<path stroke='none' d='M0 0h24v24H0z' fill='none' />
|
|
92
|
+
<path d='M6 15l6 -6l6 6' />
|
|
93
|
+
</svg>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function X({ size, style, ...others }: IconProps) {
|
|
98
|
+
return (
|
|
99
|
+
<svg
|
|
100
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
101
|
+
width='24'
|
|
102
|
+
height='24'
|
|
103
|
+
viewBox='0 0 24 24'
|
|
104
|
+
fill='none'
|
|
105
|
+
stroke='currentColor'
|
|
106
|
+
strokeWidth='2'
|
|
107
|
+
strokeLinecap='round'
|
|
108
|
+
strokeLinejoin='round'
|
|
109
|
+
className='icon icon-tabler icons-tabler-outline icon-tabler-x'
|
|
110
|
+
style={{ width: size, height: size, ...style }}
|
|
111
|
+
{...others}
|
|
112
|
+
>
|
|
113
|
+
<path stroke='none' d='M0 0h24v24H0z' fill='none' />
|
|
114
|
+
<path d='M18 6l-12 12' />
|
|
115
|
+
<path d='M6 6l12 12' />
|
|
116
|
+
</svg>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function ExclamationCircle({ size, style, ...others }: IconProps) {
|
|
121
|
+
return (
|
|
122
|
+
<svg
|
|
123
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
124
|
+
width='24'
|
|
125
|
+
height='24'
|
|
126
|
+
viewBox='0 0 24 24'
|
|
127
|
+
fill='none'
|
|
128
|
+
stroke='currentColor'
|
|
129
|
+
strokeWidth='2'
|
|
130
|
+
strokeLinecap='round'
|
|
131
|
+
strokeLinejoin='round'
|
|
132
|
+
className='icon icon-tabler icons-tabler-outline icon-tabler-exclamation-circle'
|
|
133
|
+
style={{ width: size, height: size, ...style }}
|
|
134
|
+
{...others}
|
|
135
|
+
>
|
|
136
|
+
<path d='M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0' />
|
|
137
|
+
<path d='M12 9v4' />
|
|
138
|
+
<path d='M12 16v.01' />
|
|
139
|
+
</svg>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import ArrayFieldItemTemplate from './ArrayFieldItemTemplate';
|
|
4
|
+
import ArrayFieldTemplate from './ArrayFieldTemplate';
|
|
5
|
+
import ArrayFieldTitleTemplate from './ArrayFieldTitleTemplate';
|
|
6
|
+
import BaseInputTemplate from './BaseInputTemplate';
|
|
7
|
+
import DescriptionField from './DescriptionField';
|
|
8
|
+
import ErrorList from './ErrorList';
|
|
9
|
+
import ButtonTemplates from './ButtonTemplates';
|
|
10
|
+
import FieldErrorTemplate from './FieldErrorTemplate';
|
|
11
|
+
import FieldTemplate from './FieldTemplate';
|
|
12
|
+
import FieldHelpTemplate from './FieldHelpTemplate';
|
|
13
|
+
import GridTemplate from './GridTemplate';
|
|
14
|
+
import ObjectFieldTemplate from './ObjectFieldTemplate';
|
|
15
|
+
import TitleField from './TitleField';
|
|
16
|
+
import WrapIfAdditionalTemplate from './WrapIfAdditionalTemplate';
|
|
17
|
+
import MultiSchemaFieldTemplate from './MultiSchemaFieldTemplate';
|
|
18
|
+
|
|
19
|
+
export function generateTemplates<
|
|
20
|
+
T = any,
|
|
21
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
22
|
+
F extends FormContextType = any,
|
|
23
|
+
>(): Partial<TemplatesType<T, S, F>> {
|
|
24
|
+
return {
|
|
25
|
+
ArrayFieldItemTemplate,
|
|
26
|
+
ArrayFieldTemplate,
|
|
27
|
+
ArrayFieldTitleTemplate,
|
|
28
|
+
BaseInputTemplate,
|
|
29
|
+
ButtonTemplates: ButtonTemplates<T, S, F>(),
|
|
30
|
+
DescriptionFieldTemplate: DescriptionField,
|
|
31
|
+
ErrorListTemplate: ErrorList,
|
|
32
|
+
FieldErrorTemplate,
|
|
33
|
+
FieldTemplate,
|
|
34
|
+
FieldHelpTemplate,
|
|
35
|
+
GridTemplate,
|
|
36
|
+
ObjectFieldTemplate,
|
|
37
|
+
TitleFieldTemplate: TitleField,
|
|
38
|
+
WrapIfAdditionalTemplate,
|
|
39
|
+
MultiSchemaFieldTemplate,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default generateTemplates();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"./"
|
|
5
|
+
],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"rootDir": "./",
|
|
8
|
+
"outDir": "../lib",
|
|
9
|
+
"baseUrl": "../",
|
|
10
|
+
"jsx": "react-jsx"
|
|
11
|
+
},
|
|
12
|
+
"references": [
|
|
13
|
+
{
|
|
14
|
+
"path": "../../core"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../../utils"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../../validator-ajv8"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { UIOptionsType } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
const uiOptionsKeys: Array<keyof UIOptionsType> = [
|
|
4
|
+
'emptyValue',
|
|
5
|
+
'classNames',
|
|
6
|
+
'title',
|
|
7
|
+
'help',
|
|
8
|
+
'autocomplete',
|
|
9
|
+
'disabled',
|
|
10
|
+
'enumDisabled',
|
|
11
|
+
'hideError',
|
|
12
|
+
'readonly',
|
|
13
|
+
'order',
|
|
14
|
+
'filePreview',
|
|
15
|
+
'inline',
|
|
16
|
+
'inputType',
|
|
17
|
+
'submitButtonOptions',
|
|
18
|
+
'widget',
|
|
19
|
+
'enumNames',
|
|
20
|
+
'addable',
|
|
21
|
+
'copyable',
|
|
22
|
+
'orderable',
|
|
23
|
+
'removable',
|
|
24
|
+
'duplicateKeySuffixSeparator',
|
|
25
|
+
'enumOptions',
|
|
26
|
+
'enableMarkdownInDescription',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export function cleanupOptions<T extends object>(options: T): Omit<T, keyof UIOptionsType> {
|
|
30
|
+
const result = {} as T;
|
|
31
|
+
for (const key in options) {
|
|
32
|
+
if (!uiOptionsKeys.includes(key as keyof UIOptionsType)) {
|
|
33
|
+
result[key] = options[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result as Omit<T, keyof UIOptionsType>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ReactElement, ChangeEvent, FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
descriptionId,
|
|
4
|
+
getTemplate,
|
|
5
|
+
StrictRJSFSchema,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
FormContextType,
|
|
8
|
+
WidgetProps,
|
|
9
|
+
labelValue,
|
|
10
|
+
ariaDescribedByIds,
|
|
11
|
+
} from '@rjsf/utils';
|
|
12
|
+
import { Checkbox } from '@mantine/core';
|
|
13
|
+
|
|
14
|
+
import { cleanupOptions } from '../utils';
|
|
15
|
+
|
|
16
|
+
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
|
|
17
|
+
* It is typically used to represent a boolean.
|
|
18
|
+
*
|
|
19
|
+
* @param props - The `WidgetProps` for this component
|
|
20
|
+
*/
|
|
21
|
+
export default function CheckboxWidget<
|
|
22
|
+
T = any,
|
|
23
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
24
|
+
F extends FormContextType = any,
|
|
25
|
+
>(props: WidgetProps<T, S, F>): ReactElement {
|
|
26
|
+
const {
|
|
27
|
+
id,
|
|
28
|
+
name,
|
|
29
|
+
value = false,
|
|
30
|
+
required,
|
|
31
|
+
disabled,
|
|
32
|
+
readonly,
|
|
33
|
+
autofocus,
|
|
34
|
+
label,
|
|
35
|
+
hideLabel,
|
|
36
|
+
schema,
|
|
37
|
+
rawErrors,
|
|
38
|
+
options,
|
|
39
|
+
onChange,
|
|
40
|
+
onBlur,
|
|
41
|
+
onFocus,
|
|
42
|
+
registry,
|
|
43
|
+
uiSchema,
|
|
44
|
+
} = props;
|
|
45
|
+
|
|
46
|
+
const themeProps = cleanupOptions(options);
|
|
47
|
+
|
|
48
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
49
|
+
'DescriptionFieldTemplate',
|
|
50
|
+
registry,
|
|
51
|
+
options,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const handleCheckboxChange = useCallback(
|
|
55
|
+
(e: ChangeEvent<HTMLInputElement>) => {
|
|
56
|
+
if (!disabled && !readonly && onChange) {
|
|
57
|
+
onChange(e.currentTarget.checked);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[onChange, disabled, readonly],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const handleBlur = useCallback(
|
|
64
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
65
|
+
if (onBlur) {
|
|
66
|
+
onBlur(id, target.checked);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[onBlur, id],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const handleFocus = useCallback(
|
|
73
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
74
|
+
if (onFocus) {
|
|
75
|
+
onFocus(id, target.checked);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[onFocus, id],
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const description = options.description || schema.description;
|
|
82
|
+
return (
|
|
83
|
+
<>
|
|
84
|
+
{!hideLabel && !!description && (
|
|
85
|
+
<DescriptionFieldTemplate
|
|
86
|
+
id={descriptionId<T>(id)}
|
|
87
|
+
description={description}
|
|
88
|
+
schema={schema}
|
|
89
|
+
uiSchema={uiSchema}
|
|
90
|
+
registry={registry}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
<Checkbox
|
|
94
|
+
id={id}
|
|
95
|
+
name={name}
|
|
96
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
97
|
+
disabled={disabled || readonly}
|
|
98
|
+
required={required}
|
|
99
|
+
autoFocus={autofocus}
|
|
100
|
+
checked={typeof value === 'undefined' ? false : value === 'true' || value}
|
|
101
|
+
onChange={handleCheckboxChange}
|
|
102
|
+
onBlur={handleBlur}
|
|
103
|
+
onFocus={handleFocus}
|
|
104
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
105
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
106
|
+
{...themeProps}
|
|
107
|
+
/>
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ariaDescribedByIds,
|
|
4
|
+
enumOptionsValueForIndex,
|
|
5
|
+
enumOptionsIndexForValue,
|
|
6
|
+
optionId,
|
|
7
|
+
titleId,
|
|
8
|
+
FormContextType,
|
|
9
|
+
WidgetProps,
|
|
10
|
+
RJSFSchema,
|
|
11
|
+
StrictRJSFSchema,
|
|
12
|
+
} from '@rjsf/utils';
|
|
13
|
+
import { Checkbox, Flex, Input } from '@mantine/core';
|
|
14
|
+
|
|
15
|
+
import { cleanupOptions } from '../utils';
|
|
16
|
+
|
|
17
|
+
/** The `CheckboxesWidget` is a widget for rendering checkbox groups.
|
|
18
|
+
* It is typically used to represent an array of enums.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The `WidgetProps` for this component
|
|
21
|
+
*/
|
|
22
|
+
export default function CheckboxesWidget<
|
|
23
|
+
T = any,
|
|
24
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
25
|
+
F extends FormContextType = any,
|
|
26
|
+
>(props: WidgetProps<T, S, F>) {
|
|
27
|
+
const {
|
|
28
|
+
id,
|
|
29
|
+
value,
|
|
30
|
+
required,
|
|
31
|
+
disabled,
|
|
32
|
+
readonly,
|
|
33
|
+
autofocus,
|
|
34
|
+
label,
|
|
35
|
+
hideLabel,
|
|
36
|
+
rawErrors,
|
|
37
|
+
options,
|
|
38
|
+
onChange,
|
|
39
|
+
onBlur,
|
|
40
|
+
onFocus,
|
|
41
|
+
} = props;
|
|
42
|
+
|
|
43
|
+
const { enumOptions, enumDisabled, inline, emptyValue } = options;
|
|
44
|
+
const themeProps = cleanupOptions(options);
|
|
45
|
+
|
|
46
|
+
const handleChange = useCallback(
|
|
47
|
+
(nextValue: any) => {
|
|
48
|
+
if (!disabled && !readonly && onChange) {
|
|
49
|
+
onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[onChange, disabled, readonly, enumOptions, emptyValue],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const handleBlur = useCallback(
|
|
56
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
57
|
+
if (onBlur) {
|
|
58
|
+
onBlur(id, enumOptionsValueForIndex<S>(target.value, enumOptions, emptyValue));
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[onBlur, id, enumOptions, emptyValue],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const handleFocus = useCallback(
|
|
65
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
66
|
+
if (onFocus) {
|
|
67
|
+
onFocus(id, enumOptionsValueForIndex<S>(target.value, enumOptions, emptyValue));
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[onFocus, id, enumOptions, emptyValue],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, true) as string[];
|
|
74
|
+
|
|
75
|
+
return Array.isArray(enumOptions) && enumOptions.length > 0 ? (
|
|
76
|
+
<>
|
|
77
|
+
{!hideLabel && !!label && (
|
|
78
|
+
<Input.Label id={titleId<T>(id)} required={required}>
|
|
79
|
+
{label}
|
|
80
|
+
</Input.Label>
|
|
81
|
+
)}
|
|
82
|
+
<Checkbox.Group
|
|
83
|
+
id={id}
|
|
84
|
+
value={selectedIndexes}
|
|
85
|
+
onChange={handleChange}
|
|
86
|
+
required={required}
|
|
87
|
+
readOnly={disabled || readonly}
|
|
88
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
89
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
90
|
+
{...themeProps}
|
|
91
|
+
>
|
|
92
|
+
{Array.isArray(enumOptions) ? (
|
|
93
|
+
<Flex mt='xs' direction={inline ? 'row' : 'column'} gap='xs' wrap='wrap'>
|
|
94
|
+
{enumOptions.map((option, i) => (
|
|
95
|
+
<Checkbox
|
|
96
|
+
key={i}
|
|
97
|
+
id={optionId(id, i)}
|
|
98
|
+
name={id}
|
|
99
|
+
value={String(i)}
|
|
100
|
+
label={option.label}
|
|
101
|
+
disabled={Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1}
|
|
102
|
+
autoFocus={i === 0 && autofocus}
|
|
103
|
+
onBlur={handleBlur}
|
|
104
|
+
onFocus={handleFocus}
|
|
105
|
+
/>
|
|
106
|
+
))}
|
|
107
|
+
</Flex>
|
|
108
|
+
) : null}
|
|
109
|
+
</Checkbox.Group>
|
|
110
|
+
</>
|
|
111
|
+
) : null;
|
|
112
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FocusEvent, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
FormContextType,
|
|
4
|
+
RJSFSchema,
|
|
5
|
+
StrictRJSFSchema,
|
|
6
|
+
WidgetProps,
|
|
7
|
+
labelValue,
|
|
8
|
+
ariaDescribedByIds,
|
|
9
|
+
} from '@rjsf/utils';
|
|
10
|
+
import { ColorInput } from '@mantine/core';
|
|
11
|
+
|
|
12
|
+
import { cleanupOptions } from '../utils';
|
|
13
|
+
|
|
14
|
+
/** The `ColorWidget` component uses the `ColorInput` from Mantine, allowing users to pick a color.
|
|
15
|
+
*
|
|
16
|
+
* @param props - The `WidgetProps` for this component
|
|
17
|
+
*/
|
|
18
|
+
export default function ColorWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
19
|
+
props: WidgetProps<T, S, F>,
|
|
20
|
+
) {
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
name,
|
|
24
|
+
value,
|
|
25
|
+
placeholder,
|
|
26
|
+
required,
|
|
27
|
+
disabled,
|
|
28
|
+
readonly,
|
|
29
|
+
autofocus,
|
|
30
|
+
label,
|
|
31
|
+
hideLabel,
|
|
32
|
+
rawErrors,
|
|
33
|
+
options,
|
|
34
|
+
onChange,
|
|
35
|
+
onBlur,
|
|
36
|
+
onFocus,
|
|
37
|
+
} = props;
|
|
38
|
+
|
|
39
|
+
const themeProps = cleanupOptions(options);
|
|
40
|
+
|
|
41
|
+
const handleChange = useCallback(
|
|
42
|
+
(nextValue: string) => {
|
|
43
|
+
onChange(nextValue);
|
|
44
|
+
},
|
|
45
|
+
[onChange],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const handleBlur = useCallback(
|
|
49
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
50
|
+
if (onBlur) {
|
|
51
|
+
onBlur(id, target && target.value);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[onBlur, id],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const handleFocus = useCallback(
|
|
58
|
+
({ target }: FocusEvent<HTMLInputElement>) => {
|
|
59
|
+
if (onFocus) {
|
|
60
|
+
onFocus(id, target && target.value);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
[onFocus, id],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<ColorInput
|
|
68
|
+
id={id}
|
|
69
|
+
name={name}
|
|
70
|
+
value={value || ''}
|
|
71
|
+
placeholder={placeholder || undefined}
|
|
72
|
+
required={required}
|
|
73
|
+
disabled={disabled || readonly}
|
|
74
|
+
autoFocus={autofocus}
|
|
75
|
+
label={labelValue(label || undefined, hideLabel, false)}
|
|
76
|
+
onChange={handleChange}
|
|
77
|
+
onBlur={handleBlur}
|
|
78
|
+
onFocus={handleFocus}
|
|
79
|
+
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
|
|
80
|
+
{...themeProps}
|
|
81
|
+
aria-describedby={ariaDescribedByIds<T>(id)}
|
|
82
|
+
popoverProps={{ withinPortal: false }}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils';
|
|
2
|
+
|
|
3
|
+
import _AltDateWidget from './AltDateWidget';
|
|
4
|
+
|
|
5
|
+
/** The `AltDateTimeWidget` is an alternative widget for rendering datetime properties.
|
|
6
|
+
* It uses the AltDateWidget for rendering, with the `time` prop set to true by default.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The `WidgetProps` for this component
|
|
9
|
+
*/
|
|
10
|
+
export default function AltDateTimeWidget<
|
|
11
|
+
T = any,
|
|
12
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
13
|
+
F extends FormContextType = any,
|
|
14
|
+
>(props: WidgetProps<T, S, F>) {
|
|
15
|
+
const { AltDateWidget } = props.registry.widgets;
|
|
16
|
+
return <AltDateWidget showTime {...props} />;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
AltDateTimeWidget.defaultProps = {
|
|
20
|
+
..._AltDateWidget?.defaultProps,
|
|
21
|
+
showTime: true,
|
|
22
|
+
};
|