@acp-autoform/mantine 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +360 -0
- package/dist/index.mjs +324 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Mantine integration for AutoForm
|
|
2
|
+
|
|
3
|
+
This package provides a Mantine integration for AutoForm.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @acp-autoform/mantine
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For more information on how to use this package, see the [AutoForm documentation](https://autoform.vantezzen.io/docs/react/getting-started).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _acp_autoform_react from '@acp-autoform/react';
|
|
3
|
+
import { FieldValues, ExtendableAutoFormProps } from '@acp-autoform/react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { MantineProvider } from '@mantine/core';
|
|
6
|
+
|
|
7
|
+
interface AutoFormProps<T extends FieldValues> extends ExtendableAutoFormProps<T> {
|
|
8
|
+
theme?: Parameters<typeof MantineProvider>[0]["theme"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const MantineAutoFormFieldComponents: {
|
|
12
|
+
readonly string: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
13
|
+
readonly number: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
14
|
+
readonly boolean: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
15
|
+
readonly date: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
16
|
+
readonly select: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
17
|
+
};
|
|
18
|
+
type FieldTypes = keyof typeof MantineAutoFormFieldComponents;
|
|
19
|
+
declare function AutoForm<T extends Record<string, any>>({ theme, uiComponents, formComponents, ...props }: AutoFormProps<T>): react_jsx_runtime.JSX.Element;
|
|
20
|
+
|
|
21
|
+
export { AutoForm, type AutoFormProps, type FieldTypes, MantineAutoFormFieldComponents };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _acp_autoform_react from '@acp-autoform/react';
|
|
3
|
+
import { FieldValues, ExtendableAutoFormProps } from '@acp-autoform/react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { MantineProvider } from '@mantine/core';
|
|
6
|
+
|
|
7
|
+
interface AutoFormProps<T extends FieldValues> extends ExtendableAutoFormProps<T> {
|
|
8
|
+
theme?: Parameters<typeof MantineProvider>[0]["theme"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const MantineAutoFormFieldComponents: {
|
|
12
|
+
readonly string: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
13
|
+
readonly number: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
14
|
+
readonly boolean: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
15
|
+
readonly date: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
16
|
+
readonly select: React.FC<_acp_autoform_react.AutoFormFieldProps>;
|
|
17
|
+
};
|
|
18
|
+
type FieldTypes = keyof typeof MantineAutoFormFieldComponents;
|
|
19
|
+
declare function AutoForm<T extends Record<string, any>>({ theme, uiComponents, formComponents, ...props }: AutoFormProps<T>): react_jsx_runtime.JSX.Element;
|
|
20
|
+
|
|
21
|
+
export { AutoForm, type AutoFormProps, type FieldTypes, MantineAutoFormFieldComponents };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AutoForm: () => AutoForm,
|
|
34
|
+
MantineAutoFormFieldComponents: () => MantineAutoFormFieldComponents
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/AutoForm.tsx
|
|
39
|
+
var import_react2 = require("@acp-autoform/react");
|
|
40
|
+
var import_core11 = require("@mantine/core");
|
|
41
|
+
|
|
42
|
+
// src/components/Form.tsx
|
|
43
|
+
var import_react = __toESM(require("react"));
|
|
44
|
+
var import_styles = require("@mantine/dates/styles.css");
|
|
45
|
+
var import_core = require("@mantine/core");
|
|
46
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
var Form = import_react.default.forwardRef(({ children, ...props }, ref) => {
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
49
|
+
import_core.Box,
|
|
50
|
+
{
|
|
51
|
+
component: "form",
|
|
52
|
+
style: {
|
|
53
|
+
display: "flex",
|
|
54
|
+
flexDirection: "column",
|
|
55
|
+
gap: 15
|
|
56
|
+
},
|
|
57
|
+
ref,
|
|
58
|
+
...props,
|
|
59
|
+
children
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// src/components/FieldWrapper.tsx
|
|
65
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
66
|
+
var FieldWrapper = ({ children }) => {
|
|
67
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/components/ErrorMessage.tsx
|
|
71
|
+
var import_core2 = require("@mantine/core");
|
|
72
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
73
|
+
var ErrorMessage = ({ error }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core2.Text, { c: "red", size: "sm", children: error });
|
|
74
|
+
|
|
75
|
+
// src/components/SubmitButton.tsx
|
|
76
|
+
var import_core3 = require("@mantine/core");
|
|
77
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
78
|
+
var SubmitButton = ({
|
|
79
|
+
children
|
|
80
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core3.Button, { type: "submit", mt: "md", children });
|
|
81
|
+
|
|
82
|
+
// src/components/StringField.tsx
|
|
83
|
+
var import_core4 = require("@mantine/core");
|
|
84
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
85
|
+
var StringField = ({
|
|
86
|
+
id,
|
|
87
|
+
label,
|
|
88
|
+
field,
|
|
89
|
+
error,
|
|
90
|
+
useField,
|
|
91
|
+
inputProps
|
|
92
|
+
}) => {
|
|
93
|
+
const formField = useField();
|
|
94
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
95
|
+
import_core4.TextInput,
|
|
96
|
+
{
|
|
97
|
+
id,
|
|
98
|
+
label,
|
|
99
|
+
error,
|
|
100
|
+
...formField,
|
|
101
|
+
...inputProps,
|
|
102
|
+
value: formField.value ?? "",
|
|
103
|
+
withAsterisk: field.required,
|
|
104
|
+
description: field.fieldConfig?.description
|
|
105
|
+
},
|
|
106
|
+
id
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/components/NumberField.tsx
|
|
111
|
+
var import_core5 = require("@mantine/core");
|
|
112
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
113
|
+
var NumberField = ({
|
|
114
|
+
id,
|
|
115
|
+
label,
|
|
116
|
+
field,
|
|
117
|
+
error,
|
|
118
|
+
useField,
|
|
119
|
+
inputProps
|
|
120
|
+
}) => {
|
|
121
|
+
const formField = useField();
|
|
122
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
123
|
+
import_core5.TextInput,
|
|
124
|
+
{
|
|
125
|
+
type: "number",
|
|
126
|
+
label,
|
|
127
|
+
error,
|
|
128
|
+
...formField,
|
|
129
|
+
...inputProps,
|
|
130
|
+
value: formField.value ?? "",
|
|
131
|
+
withAsterisk: field.required,
|
|
132
|
+
description: field.fieldConfig?.description
|
|
133
|
+
},
|
|
134
|
+
id
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/components/BooleanField.tsx
|
|
139
|
+
var import_core6 = require("@mantine/core");
|
|
140
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
141
|
+
var BooleanField = ({
|
|
142
|
+
id,
|
|
143
|
+
label,
|
|
144
|
+
field,
|
|
145
|
+
error,
|
|
146
|
+
useField,
|
|
147
|
+
inputProps
|
|
148
|
+
}) => {
|
|
149
|
+
const formField = useField();
|
|
150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
151
|
+
import_core6.Checkbox,
|
|
152
|
+
{
|
|
153
|
+
...formField,
|
|
154
|
+
...inputProps,
|
|
155
|
+
error,
|
|
156
|
+
checked: formField.value ?? false,
|
|
157
|
+
description: field.fieldConfig?.description,
|
|
158
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { style: { lineHeight: "16px", cursor: "pointer" }, children: [
|
|
159
|
+
label,
|
|
160
|
+
field.required && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: { color: "red", opacity: 0.8 }, children: " * " })
|
|
161
|
+
] })
|
|
162
|
+
},
|
|
163
|
+
id
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/components/DateField.tsx
|
|
168
|
+
var import_dates = require("@mantine/dates");
|
|
169
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
170
|
+
var DateField = ({
|
|
171
|
+
id,
|
|
172
|
+
label,
|
|
173
|
+
field,
|
|
174
|
+
error,
|
|
175
|
+
useField,
|
|
176
|
+
inputProps
|
|
177
|
+
}) => {
|
|
178
|
+
const formField = useField();
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
180
|
+
import_dates.DateInput,
|
|
181
|
+
{
|
|
182
|
+
...inputProps,
|
|
183
|
+
...formField,
|
|
184
|
+
label,
|
|
185
|
+
error,
|
|
186
|
+
withAsterisk: field.required,
|
|
187
|
+
description: field.fieldConfig?.description,
|
|
188
|
+
value: formField.value ? new Date(formField.value) : void 0,
|
|
189
|
+
onChange: (value) => formField.onChange(value?.toLocaleDateString("en-CA"))
|
|
190
|
+
},
|
|
191
|
+
id
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/components/SelectField.tsx
|
|
196
|
+
var import_core7 = require("@mantine/core");
|
|
197
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
198
|
+
var SelectField = ({
|
|
199
|
+
id,
|
|
200
|
+
label,
|
|
201
|
+
field,
|
|
202
|
+
error,
|
|
203
|
+
useField,
|
|
204
|
+
inputProps
|
|
205
|
+
}) => {
|
|
206
|
+
const formField = useField();
|
|
207
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
208
|
+
import_core7.Select,
|
|
209
|
+
{
|
|
210
|
+
...inputProps,
|
|
211
|
+
...formField,
|
|
212
|
+
label,
|
|
213
|
+
error,
|
|
214
|
+
withAsterisk: field.required,
|
|
215
|
+
description: field.fieldConfig?.description,
|
|
216
|
+
data: (field.options || []).map(([_key, label2]) => ({
|
|
217
|
+
value: label2,
|
|
218
|
+
label: label2
|
|
219
|
+
}))
|
|
220
|
+
},
|
|
221
|
+
id
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/components/ObjectWrapper.tsx
|
|
226
|
+
var import_core8 = require("@mantine/core");
|
|
227
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
228
|
+
var ObjectWrapper = ({
|
|
229
|
+
label,
|
|
230
|
+
field,
|
|
231
|
+
children
|
|
232
|
+
}) => {
|
|
233
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_core8.Box, { mt: "md", children: [
|
|
234
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_core8.Title, { order: 5, style: { marginTop: "25px" }, children: label }),
|
|
235
|
+
field.fieldConfig?.description && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_core8.Text, { size: "xs", c: "dimmed", mb: 3, children: field.fieldConfig?.description }),
|
|
236
|
+
children
|
|
237
|
+
] });
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/components/ArrayWrapper.tsx
|
|
241
|
+
var import_icons_react = require("@tabler/icons-react");
|
|
242
|
+
var import_core9 = require("@mantine/core");
|
|
243
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
244
|
+
var ArrayWrapper = ({
|
|
245
|
+
label,
|
|
246
|
+
field,
|
|
247
|
+
error,
|
|
248
|
+
children,
|
|
249
|
+
onAddItem,
|
|
250
|
+
inputProps
|
|
251
|
+
}) => {
|
|
252
|
+
const { key, ref, ...props } = inputProps;
|
|
253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core9.Box, { mt: "md", children: [
|
|
254
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
255
|
+
import_core9.Text,
|
|
256
|
+
{
|
|
257
|
+
fw: 500,
|
|
258
|
+
size: "md",
|
|
259
|
+
ref,
|
|
260
|
+
tabIndex: -1,
|
|
261
|
+
role: "heading",
|
|
262
|
+
"aria-describedby": `${key}-error ${key}-description`,
|
|
263
|
+
children: [
|
|
264
|
+
label,
|
|
265
|
+
field.required && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { style: { color: "red", opacity: 0.8 }, children: " * " })
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
),
|
|
269
|
+
field.fieldConfig?.description && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core9.Text, { size: "xs", c: "dimmed", id: key + "-description", children: field.fieldConfig?.description }),
|
|
270
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core9.Text, { size: "xs", c: "red.6", id: key + "-error", children: error }),
|
|
271
|
+
children,
|
|
272
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
273
|
+
import_core9.Button,
|
|
274
|
+
{
|
|
275
|
+
...props,
|
|
276
|
+
mt: "5px",
|
|
277
|
+
onClick: onAddItem,
|
|
278
|
+
"aria-label": `add ${label}`,
|
|
279
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons_react.IconPlus, { size: 19 })
|
|
280
|
+
}
|
|
281
|
+
)
|
|
282
|
+
] });
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/components/ArrayElementWrapper.tsx
|
|
286
|
+
var import_core10 = require("@mantine/core");
|
|
287
|
+
var import_icons_react2 = require("@tabler/icons-react");
|
|
288
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
289
|
+
var ArrayElementWrapper = ({
|
|
290
|
+
children,
|
|
291
|
+
onRemove
|
|
292
|
+
}) => {
|
|
293
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
294
|
+
import_core10.Box,
|
|
295
|
+
{
|
|
296
|
+
mt: "md",
|
|
297
|
+
p: "md",
|
|
298
|
+
style: {
|
|
299
|
+
border: "1px solid #eee",
|
|
300
|
+
borderRadius: 4,
|
|
301
|
+
position: "relative"
|
|
302
|
+
},
|
|
303
|
+
children: [
|
|
304
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
305
|
+
import_core10.ActionIcon,
|
|
306
|
+
{
|
|
307
|
+
onClick: onRemove,
|
|
308
|
+
color: "red",
|
|
309
|
+
variant: "subtle",
|
|
310
|
+
"data-testid": "remove-item-button",
|
|
311
|
+
size: 30,
|
|
312
|
+
mb: 5,
|
|
313
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons_react2.IconTrash, { size: 19 })
|
|
314
|
+
}
|
|
315
|
+
),
|
|
316
|
+
children
|
|
317
|
+
]
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/AutoForm.tsx
|
|
323
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
324
|
+
var MantineUIComponents = {
|
|
325
|
+
Form,
|
|
326
|
+
FieldWrapper,
|
|
327
|
+
ErrorMessage,
|
|
328
|
+
SubmitButton,
|
|
329
|
+
ObjectWrapper,
|
|
330
|
+
ArrayWrapper,
|
|
331
|
+
ArrayElementWrapper
|
|
332
|
+
};
|
|
333
|
+
var MantineAutoFormFieldComponents = {
|
|
334
|
+
string: StringField,
|
|
335
|
+
number: NumberField,
|
|
336
|
+
boolean: BooleanField,
|
|
337
|
+
date: DateField,
|
|
338
|
+
select: SelectField
|
|
339
|
+
};
|
|
340
|
+
function AutoForm({
|
|
341
|
+
theme,
|
|
342
|
+
uiComponents,
|
|
343
|
+
formComponents,
|
|
344
|
+
...props
|
|
345
|
+
}) {
|
|
346
|
+
const ThemedForm = () => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
347
|
+
import_react2.AutoForm,
|
|
348
|
+
{
|
|
349
|
+
...props,
|
|
350
|
+
uiComponents: { ...MantineUIComponents, ...uiComponents },
|
|
351
|
+
formComponents: { ...MantineAutoFormFieldComponents, ...formComponents }
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
return theme ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core11.MantineProvider, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ThemedForm, {}) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ThemedForm, {});
|
|
355
|
+
}
|
|
356
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
357
|
+
0 && (module.exports = {
|
|
358
|
+
AutoForm,
|
|
359
|
+
MantineAutoFormFieldComponents
|
|
360
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// src/AutoForm.tsx
|
|
2
|
+
import {
|
|
3
|
+
AutoForm as BaseAutoForm
|
|
4
|
+
} from "@acp-autoform/react";
|
|
5
|
+
import { MantineProvider } from "@mantine/core";
|
|
6
|
+
|
|
7
|
+
// src/components/Form.tsx
|
|
8
|
+
import React from "react";
|
|
9
|
+
import "@mantine/dates/styles.css";
|
|
10
|
+
import { Box } from "@mantine/core";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
var Form = React.forwardRef(({ children, ...props }, ref) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
Box,
|
|
15
|
+
{
|
|
16
|
+
component: "form",
|
|
17
|
+
style: {
|
|
18
|
+
display: "flex",
|
|
19
|
+
flexDirection: "column",
|
|
20
|
+
gap: 15
|
|
21
|
+
},
|
|
22
|
+
ref,
|
|
23
|
+
...props,
|
|
24
|
+
children
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// src/components/FieldWrapper.tsx
|
|
30
|
+
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
31
|
+
var FieldWrapper = ({ children }) => {
|
|
32
|
+
return /* @__PURE__ */ jsx2(Fragment, { children });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/components/ErrorMessage.tsx
|
|
36
|
+
import { Text } from "@mantine/core";
|
|
37
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
38
|
+
var ErrorMessage = ({ error }) => /* @__PURE__ */ jsx3(Text, { c: "red", size: "sm", children: error });
|
|
39
|
+
|
|
40
|
+
// src/components/SubmitButton.tsx
|
|
41
|
+
import { Button } from "@mantine/core";
|
|
42
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
43
|
+
var SubmitButton = ({
|
|
44
|
+
children
|
|
45
|
+
}) => /* @__PURE__ */ jsx4(Button, { type: "submit", mt: "md", children });
|
|
46
|
+
|
|
47
|
+
// src/components/StringField.tsx
|
|
48
|
+
import { TextInput } from "@mantine/core";
|
|
49
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
50
|
+
var StringField = ({
|
|
51
|
+
id,
|
|
52
|
+
label,
|
|
53
|
+
field,
|
|
54
|
+
error,
|
|
55
|
+
useField,
|
|
56
|
+
inputProps
|
|
57
|
+
}) => {
|
|
58
|
+
const formField = useField();
|
|
59
|
+
return /* @__PURE__ */ jsx5(
|
|
60
|
+
TextInput,
|
|
61
|
+
{
|
|
62
|
+
id,
|
|
63
|
+
label,
|
|
64
|
+
error,
|
|
65
|
+
...formField,
|
|
66
|
+
...inputProps,
|
|
67
|
+
value: formField.value ?? "",
|
|
68
|
+
withAsterisk: field.required,
|
|
69
|
+
description: field.fieldConfig?.description
|
|
70
|
+
},
|
|
71
|
+
id
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/components/NumberField.tsx
|
|
76
|
+
import { TextInput as TextInput2 } from "@mantine/core";
|
|
77
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
78
|
+
var NumberField = ({
|
|
79
|
+
id,
|
|
80
|
+
label,
|
|
81
|
+
field,
|
|
82
|
+
error,
|
|
83
|
+
useField,
|
|
84
|
+
inputProps
|
|
85
|
+
}) => {
|
|
86
|
+
const formField = useField();
|
|
87
|
+
return /* @__PURE__ */ jsx6(
|
|
88
|
+
TextInput2,
|
|
89
|
+
{
|
|
90
|
+
type: "number",
|
|
91
|
+
label,
|
|
92
|
+
error,
|
|
93
|
+
...formField,
|
|
94
|
+
...inputProps,
|
|
95
|
+
value: formField.value ?? "",
|
|
96
|
+
withAsterisk: field.required,
|
|
97
|
+
description: field.fieldConfig?.description
|
|
98
|
+
},
|
|
99
|
+
id
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/components/BooleanField.tsx
|
|
104
|
+
import { Checkbox } from "@mantine/core";
|
|
105
|
+
import { jsx as jsx7, jsxs } from "react/jsx-runtime";
|
|
106
|
+
var BooleanField = ({
|
|
107
|
+
id,
|
|
108
|
+
label,
|
|
109
|
+
field,
|
|
110
|
+
error,
|
|
111
|
+
useField,
|
|
112
|
+
inputProps
|
|
113
|
+
}) => {
|
|
114
|
+
const formField = useField();
|
|
115
|
+
return /* @__PURE__ */ jsx7(
|
|
116
|
+
Checkbox,
|
|
117
|
+
{
|
|
118
|
+
...formField,
|
|
119
|
+
...inputProps,
|
|
120
|
+
error,
|
|
121
|
+
checked: formField.value ?? false,
|
|
122
|
+
description: field.fieldConfig?.description,
|
|
123
|
+
label: /* @__PURE__ */ jsxs("span", { style: { lineHeight: "16px", cursor: "pointer" }, children: [
|
|
124
|
+
label,
|
|
125
|
+
field.required && /* @__PURE__ */ jsx7("span", { style: { color: "red", opacity: 0.8 }, children: " * " })
|
|
126
|
+
] })
|
|
127
|
+
},
|
|
128
|
+
id
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/components/DateField.tsx
|
|
133
|
+
import { DateInput } from "@mantine/dates";
|
|
134
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
135
|
+
var DateField = ({
|
|
136
|
+
id,
|
|
137
|
+
label,
|
|
138
|
+
field,
|
|
139
|
+
error,
|
|
140
|
+
useField,
|
|
141
|
+
inputProps
|
|
142
|
+
}) => {
|
|
143
|
+
const formField = useField();
|
|
144
|
+
return /* @__PURE__ */ jsx8(
|
|
145
|
+
DateInput,
|
|
146
|
+
{
|
|
147
|
+
...inputProps,
|
|
148
|
+
...formField,
|
|
149
|
+
label,
|
|
150
|
+
error,
|
|
151
|
+
withAsterisk: field.required,
|
|
152
|
+
description: field.fieldConfig?.description,
|
|
153
|
+
value: formField.value ? new Date(formField.value) : void 0,
|
|
154
|
+
onChange: (value) => formField.onChange(value?.toLocaleDateString("en-CA"))
|
|
155
|
+
},
|
|
156
|
+
id
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/components/SelectField.tsx
|
|
161
|
+
import { Select } from "@mantine/core";
|
|
162
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
163
|
+
var SelectField = ({
|
|
164
|
+
id,
|
|
165
|
+
label,
|
|
166
|
+
field,
|
|
167
|
+
error,
|
|
168
|
+
useField,
|
|
169
|
+
inputProps
|
|
170
|
+
}) => {
|
|
171
|
+
const formField = useField();
|
|
172
|
+
return /* @__PURE__ */ jsx9(
|
|
173
|
+
Select,
|
|
174
|
+
{
|
|
175
|
+
...inputProps,
|
|
176
|
+
...formField,
|
|
177
|
+
label,
|
|
178
|
+
error,
|
|
179
|
+
withAsterisk: field.required,
|
|
180
|
+
description: field.fieldConfig?.description,
|
|
181
|
+
data: (field.options || []).map(([_key, label2]) => ({
|
|
182
|
+
value: label2,
|
|
183
|
+
label: label2
|
|
184
|
+
}))
|
|
185
|
+
},
|
|
186
|
+
id
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/components/ObjectWrapper.tsx
|
|
191
|
+
import { Box as Box2, Title, Text as Text2 } from "@mantine/core";
|
|
192
|
+
import { jsx as jsx10, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
193
|
+
var ObjectWrapper = ({
|
|
194
|
+
label,
|
|
195
|
+
field,
|
|
196
|
+
children
|
|
197
|
+
}) => {
|
|
198
|
+
return /* @__PURE__ */ jsxs2(Box2, { mt: "md", children: [
|
|
199
|
+
/* @__PURE__ */ jsx10(Title, { order: 5, style: { marginTop: "25px" }, children: label }),
|
|
200
|
+
field.fieldConfig?.description && /* @__PURE__ */ jsx10(Text2, { size: "xs", c: "dimmed", mb: 3, children: field.fieldConfig?.description }),
|
|
201
|
+
children
|
|
202
|
+
] });
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// src/components/ArrayWrapper.tsx
|
|
206
|
+
import { IconPlus } from "@tabler/icons-react";
|
|
207
|
+
import { Box as Box3, Text as Text3, Button as Button2 } from "@mantine/core";
|
|
208
|
+
import { jsx as jsx11, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
209
|
+
var ArrayWrapper = ({
|
|
210
|
+
label,
|
|
211
|
+
field,
|
|
212
|
+
error,
|
|
213
|
+
children,
|
|
214
|
+
onAddItem,
|
|
215
|
+
inputProps
|
|
216
|
+
}) => {
|
|
217
|
+
const { key, ref, ...props } = inputProps;
|
|
218
|
+
return /* @__PURE__ */ jsxs3(Box3, { mt: "md", children: [
|
|
219
|
+
/* @__PURE__ */ jsxs3(
|
|
220
|
+
Text3,
|
|
221
|
+
{
|
|
222
|
+
fw: 500,
|
|
223
|
+
size: "md",
|
|
224
|
+
ref,
|
|
225
|
+
tabIndex: -1,
|
|
226
|
+
role: "heading",
|
|
227
|
+
"aria-describedby": `${key}-error ${key}-description`,
|
|
228
|
+
children: [
|
|
229
|
+
label,
|
|
230
|
+
field.required && /* @__PURE__ */ jsx11("span", { style: { color: "red", opacity: 0.8 }, children: " * " })
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
),
|
|
234
|
+
field.fieldConfig?.description && /* @__PURE__ */ jsx11(Text3, { size: "xs", c: "dimmed", id: key + "-description", children: field.fieldConfig?.description }),
|
|
235
|
+
error && /* @__PURE__ */ jsx11(Text3, { size: "xs", c: "red.6", id: key + "-error", children: error }),
|
|
236
|
+
children,
|
|
237
|
+
/* @__PURE__ */ jsx11(
|
|
238
|
+
Button2,
|
|
239
|
+
{
|
|
240
|
+
...props,
|
|
241
|
+
mt: "5px",
|
|
242
|
+
onClick: onAddItem,
|
|
243
|
+
"aria-label": `add ${label}`,
|
|
244
|
+
children: /* @__PURE__ */ jsx11(IconPlus, { size: 19 })
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
] });
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// src/components/ArrayElementWrapper.tsx
|
|
251
|
+
import { Box as Box4, ActionIcon } from "@mantine/core";
|
|
252
|
+
import { IconTrash } from "@tabler/icons-react";
|
|
253
|
+
import { jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
254
|
+
var ArrayElementWrapper = ({
|
|
255
|
+
children,
|
|
256
|
+
onRemove
|
|
257
|
+
}) => {
|
|
258
|
+
return /* @__PURE__ */ jsxs4(
|
|
259
|
+
Box4,
|
|
260
|
+
{
|
|
261
|
+
mt: "md",
|
|
262
|
+
p: "md",
|
|
263
|
+
style: {
|
|
264
|
+
border: "1px solid #eee",
|
|
265
|
+
borderRadius: 4,
|
|
266
|
+
position: "relative"
|
|
267
|
+
},
|
|
268
|
+
children: [
|
|
269
|
+
/* @__PURE__ */ jsx12(
|
|
270
|
+
ActionIcon,
|
|
271
|
+
{
|
|
272
|
+
onClick: onRemove,
|
|
273
|
+
color: "red",
|
|
274
|
+
variant: "subtle",
|
|
275
|
+
"data-testid": "remove-item-button",
|
|
276
|
+
size: 30,
|
|
277
|
+
mb: 5,
|
|
278
|
+
children: /* @__PURE__ */ jsx12(IconTrash, { size: 19 })
|
|
279
|
+
}
|
|
280
|
+
),
|
|
281
|
+
children
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// src/AutoForm.tsx
|
|
288
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
289
|
+
var MantineUIComponents = {
|
|
290
|
+
Form,
|
|
291
|
+
FieldWrapper,
|
|
292
|
+
ErrorMessage,
|
|
293
|
+
SubmitButton,
|
|
294
|
+
ObjectWrapper,
|
|
295
|
+
ArrayWrapper,
|
|
296
|
+
ArrayElementWrapper
|
|
297
|
+
};
|
|
298
|
+
var MantineAutoFormFieldComponents = {
|
|
299
|
+
string: StringField,
|
|
300
|
+
number: NumberField,
|
|
301
|
+
boolean: BooleanField,
|
|
302
|
+
date: DateField,
|
|
303
|
+
select: SelectField
|
|
304
|
+
};
|
|
305
|
+
function AutoForm({
|
|
306
|
+
theme,
|
|
307
|
+
uiComponents,
|
|
308
|
+
formComponents,
|
|
309
|
+
...props
|
|
310
|
+
}) {
|
|
311
|
+
const ThemedForm = () => /* @__PURE__ */ jsx13(
|
|
312
|
+
BaseAutoForm,
|
|
313
|
+
{
|
|
314
|
+
...props,
|
|
315
|
+
uiComponents: { ...MantineUIComponents, ...uiComponents },
|
|
316
|
+
formComponents: { ...MantineAutoFormFieldComponents, ...formComponents }
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
return theme ? /* @__PURE__ */ jsx13(MantineProvider, { theme, children: /* @__PURE__ */ jsx13(ThemedForm, {}) }) : /* @__PURE__ */ jsx13(ThemedForm, {});
|
|
320
|
+
}
|
|
321
|
+
export {
|
|
322
|
+
AutoForm,
|
|
323
|
+
MantineAutoFormFieldComponents
|
|
324
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@acp-autoform/mantine",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint . --max-warnings 0",
|
|
9
|
+
"build": "tsup src/index.tsx --format cjs,esm --dts ",
|
|
10
|
+
"dev": "tsup src/index.tsx --format cjs,esm --dts --watch"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/adityacodepublic/autoform.git"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@acp-autoform/core": "*",
|
|
18
|
+
"@acp-autoform/eslint-config": "*",
|
|
19
|
+
"@acp-autoform/typescript-config": "*",
|
|
20
|
+
"@mantine/core": "^7.16.0",
|
|
21
|
+
"@mantine/dates": "^7.16.0",
|
|
22
|
+
"@types/eslint": "^8.56.5",
|
|
23
|
+
"@types/node": "^20.11.24",
|
|
24
|
+
"@types/react": "^19.1.8",
|
|
25
|
+
"@types/react-dom": "^19.1.6",
|
|
26
|
+
"eslint": "^8.57.0",
|
|
27
|
+
"react": "^19.1.0",
|
|
28
|
+
"tsup": "^8.3.0",
|
|
29
|
+
"typescript": "^5.3.3"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@acp-autoform/react": "*",
|
|
33
|
+
"@tabler/icons-react": "^3.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@mantine/core": "^7",
|
|
37
|
+
"@mantine/dates": "^7",
|
|
38
|
+
"react": "^16.8.0 || ^17 || ^18 || ^19"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|