autoforma 1.1.4 β 1.1.6
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 +164 -159
- package/dist/components/AutoForm/AutoForm.types.d.ts +1 -1
- package/dist/index.cjs.js +25 -25
- package/dist/index.es.js +1122 -1106
- package/package.json +9 -16
package/README.md
CHANGED
|
@@ -1,211 +1,216 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AutoForma
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
It allows you to create powerful forms **entirely from JSON schema definitions**, removing repetitive boilerplate code and giving you full control over field behavior and layout.
|
|
5
|
-
|
|
6
|
-
With AutoForma, you can:
|
|
7
|
-
- π§© Define forms using schema objects β no manual wiring.
|
|
8
|
-
- πͺ Dynamically show, hide, or disable fields based on other values.
|
|
9
|
-
- π¨ Customize the UI with your own field renderers.
|
|
10
|
-
- π§ Extend with new field types or layouts effortlessly.
|
|
11
|
-
|
|
12
|
-
> π‘ AutoForma is perfect for dashboards, admin panels, and SaaS apps where flexibility and maintainability matter.
|
|
3
|
+
AutoForma is a schema-driven form engine for React applications, built to create dynamic, scalable, and maintainable forms with minimal boilerplate.
|
|
13
4
|
|
|
14
5
|
---
|
|
15
6
|
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
Install **AutoForma** along with its required Mantine and React peer dependencies:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install autoforma @mantine/core@^8.3.2 @mantine/hooks@^8.3.2 @mantine/form@^8.3.2 @mantine/dates@^8.3.2 @mantine/tiptap@^8.3.2 @tiptap/react@^3.6.6 react@^19.0.0 react-dom@^19.0.0
|
|
22
|
-
```
|
|
7
|
+
## What is AutoForma?
|
|
23
8
|
|
|
24
|
-
|
|
9
|
+
AutoForma allows you to build complete forms declaratively using a structured schema instead of manually wiring inputs, state, and validation logic.
|
|
25
10
|
|
|
26
|
-
|
|
11
|
+
It is designed for dynamic and data-driven applications such as admin dashboards, SaaS platforms, and complex systems where form structures evolve over time.
|
|
27
12
|
|
|
28
|
-
|
|
29
|
-
and import Mantineβs global styles and optional TipTap editor styles:
|
|
13
|
+
AutoForma currently uses Mantine as its UI layer, while keeping form logic, schema resolution, and rendering clearly separated.
|
|
30
14
|
|
|
31
|
-
|
|
32
|
-
import { MantineProvider } from "@mantine/core";
|
|
33
|
-
import "@mantine/core/styles.css";
|
|
34
|
-
import "@mantine/dates/styles.css";
|
|
35
|
-
import "@mantine/tiptap/styles.css";
|
|
15
|
+
---
|
|
36
16
|
|
|
37
|
-
|
|
38
|
-
<MantineProvider>
|
|
39
|
-
<App />
|
|
40
|
-
</MantineProvider>
|
|
41
|
-
);
|
|
42
|
-
```
|
|
17
|
+
## Features
|
|
43
18
|
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
- Schema-driven form rendering
|
|
20
|
+
- Mantine-based UI layer
|
|
21
|
+
- Dynamic schema updates at runtime
|
|
22
|
+
- Support for nested objects and arrays
|
|
23
|
+
- Extensible renderer resolution chain
|
|
24
|
+
- Custom field renderers and field types
|
|
25
|
+
- Multiple layout strategies (grid, vertical, horizontal)
|
|
26
|
+
- Read-only and view modes
|
|
27
|
+
- Automatic validation handling
|
|
28
|
+
- TypeScript-first design
|
|
29
|
+
- Built for dynamic, data-driven applications
|
|
46
30
|
|
|
47
31
|
---
|
|
48
32
|
|
|
49
|
-
|
|
33
|
+
## Installation
|
|
50
34
|
|
|
51
|
-
|
|
52
|
-
Just define your schema and pass it to the `AutoForm` component β it handles layout, validation, and submission automatically.
|
|
35
|
+
AutoForma is currently distributed via **npm only**.
|
|
53
36
|
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
import { userFormSchema } from "./schema";
|
|
57
|
-
|
|
58
|
-
const App = () => (
|
|
59
|
-
<AutoForm
|
|
60
|
-
schema={userFormSchema}
|
|
61
|
-
onSubmit={(values) => console.log("Submitted:", values)}
|
|
62
|
-
/>
|
|
63
|
-
);
|
|
37
|
+
```bash
|
|
38
|
+
npm install autoforma
|
|
64
39
|
```
|
|
65
40
|
|
|
66
|
-
|
|
41
|
+
### Peer Dependencies
|
|
67
42
|
|
|
68
|
-
|
|
43
|
+
```bash
|
|
44
|
+
npm install react react-dom @mantine/core @mantine/form @mantine/hooks @mantine/dates @mantine/tiptap
|
|
45
|
+
```
|
|
69
46
|
|
|
70
|
-
|
|
47
|
+
AutoForma is built and tested with **React 19** and **Mantine 8**.
|
|
71
48
|
|
|
72
|
-
|
|
73
|
-
You can **dynamically update field properties** (like visibility, enabled state, or placeholder)
|
|
74
|
-
and even **inject your own custom field types** using `customFieldTypes`.
|
|
49
|
+
### Styles Setup
|
|
75
50
|
|
|
76
|
-
|
|
51
|
+
```ts
|
|
52
|
+
import "@mantine/core/styles.css";
|
|
53
|
+
import "@mantine/dates/styles.css";
|
|
54
|
+
```
|
|
77
55
|
|
|
78
|
-
|
|
56
|
+
### Mantine Provider
|
|
79
57
|
|
|
80
|
-
|
|
58
|
+
```tsx
|
|
59
|
+
import { MantineProvider } from "@mantine/core";
|
|
60
|
+
|
|
61
|
+
<MantineProvider>
|
|
62
|
+
<App />
|
|
63
|
+
</MantineProvider>
|
|
64
|
+
```
|
|
81
65
|
|
|
82
|
-
|
|
83
|
-
|------|--------------|
|
|
84
|
-
| `text` | Standard text input |
|
|
85
|
-
| `number` | Numeric input |
|
|
86
|
-
| `select` | Dropdown list |
|
|
87
|
-
| `checkbox` | Boolean checkbox |
|
|
88
|
-
| `date` | Date picker |
|
|
89
|
-
| `datetime` | Combined date & time picker |
|
|
90
|
-
| `time` | Time-only picker |
|
|
91
|
-
| `object` | Nested object field (grouped sub-fields) |
|
|
92
|
-
| `array` | Repeating array of fields |
|
|
93
|
-
| `switch` | Toggle switch |
|
|
94
|
-
| `texteditor` | Rich text editor (TipTap powered) |
|
|
95
|
-
| `tags` | Multi-value tag input |
|
|
96
|
-
| `TCustom` | Any custom type you define via `customFieldTypes` |
|
|
66
|
+
---
|
|
97
67
|
|
|
98
|
-
|
|
68
|
+
## Quick Start
|
|
99
69
|
|
|
100
70
|
```tsx
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
71
|
+
import { useRef } from "react";
|
|
72
|
+
import { MantineProvider, Button } from "@mantine/core";
|
|
73
|
+
import AutoForm from "autoforma";
|
|
74
|
+
import { FieldSchema, AutoFormRef } from "autoforma";
|
|
75
|
+
|
|
76
|
+
interface UserForm {
|
|
77
|
+
firstName: string;
|
|
78
|
+
lastName: string;
|
|
79
|
+
fullName: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const schema: FieldSchema<UserForm>[] = [
|
|
83
|
+
{ type: "text", name: "firstName", label: "First Name" },
|
|
84
|
+
{ type: "text", name: "lastName", label: "Last Name" },
|
|
85
|
+
{ type: "text", name: "fullName", label: "Full Name", visible: false },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export function App() {
|
|
89
|
+
const formRef = useRef<AutoFormRef>(null);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<MantineProvider>
|
|
93
|
+
<Button onClick={() => formRef.current?.setFieldValue("firstName", "Saji")}>
|
|
94
|
+
Fill First Name
|
|
95
|
+
</Button>
|
|
96
|
+
|
|
97
|
+
<AutoForm
|
|
98
|
+
ref={formRef}
|
|
99
|
+
schema={schema}
|
|
100
|
+
onSubmit={(values) => console.log(values)}
|
|
101
|
+
updateFieldSchema={{
|
|
102
|
+
fullName: (_, field, values) =>
|
|
103
|
+
values.firstName && values.lastName
|
|
104
|
+
? { ...field, visible: true }
|
|
105
|
+
: field,
|
|
106
|
+
}}
|
|
107
|
+
onFieldChange={{
|
|
108
|
+
firstName: (_, value, form) =>
|
|
109
|
+
form.setFieldValue(
|
|
110
|
+
"fullName",
|
|
111
|
+
`${value} ${form.values.lastName ?? ""}`
|
|
112
|
+
),
|
|
113
|
+
lastName: (_, value, form) =>
|
|
114
|
+
form.setFieldValue(
|
|
115
|
+
"fullName",
|
|
116
|
+
`${form.values.firstName ?? ""} ${value}`
|
|
117
|
+
),
|
|
118
|
+
}}
|
|
108
119
|
/>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
</MantineProvider>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
112
123
|
```
|
|
113
124
|
|
|
114
125
|
---
|
|
115
126
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
AutoForma exposes several TypeScript interfaces and configuration objects that make it fully type-safe and flexible.
|
|
119
|
-
Below are the main types you can use to configure and extend the library.
|
|
127
|
+
## Field Types
|
|
120
128
|
|
|
121
|
-
|
|
129
|
+
AutoForma determines how each field is rendered using a string-based `type` property.
|
|
122
130
|
|
|
123
|
-
|
|
131
|
+
### Built-in Field Types
|
|
124
132
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
- `text`
|
|
134
|
+
- `number`
|
|
135
|
+
- `select`
|
|
136
|
+
- `checkbox`
|
|
137
|
+
- `switch`
|
|
138
|
+
- `date`
|
|
139
|
+
- `datetime`
|
|
140
|
+
- `time`
|
|
141
|
+
- `tags`
|
|
142
|
+
- `texteditor`
|
|
143
|
+
- `object`
|
|
144
|
+
- `array`
|
|
130
145
|
|
|
131
|
-
|
|
132
|
-
currentValues?: ValueProvider<TValues>;
|
|
146
|
+
---
|
|
133
147
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
## AutoForm Props
|
|
149
|
+
|
|
150
|
+
| Prop | Type | Required | Description |
|
|
151
|
+
|---|---|---|---|
|
|
152
|
+
| schema | FieldSchema[] | Yes | Defines the structure of the form |
|
|
153
|
+
| readOnly | boolean | No | Renders the form in read-only mode |
|
|
154
|
+
| disabled | boolean | No | Disables all form inputs |
|
|
155
|
+
| layout | vertical \| horizontal \| grid | No | Controls field layout |
|
|
156
|
+
| primaryAction | boolean | No | Marks submit as the primary action |
|
|
157
|
+
| submitLabel | string | No | Custom submit button label |
|
|
158
|
+
| loading | boolean | No | Enables loading state |
|
|
159
|
+
| values | () => FormValues \| Promise<FormValues> | No | Dynamically resolved values |
|
|
160
|
+
| initialValues | () => FormValues \| Promise<FormValues> | No | Initial form values |
|
|
161
|
+
| onFieldChange | OnFieldChangeMap | No | Field-level change handlers |
|
|
162
|
+
| updateFieldSchema | UpdateFieldSchema | No | Dynamic schema updates |
|
|
163
|
+
| validate | (values) => errors | No | Form-level validation |
|
|
164
|
+
| preSubmit | (values) => values | No | Pre-submit transformation |
|
|
165
|
+
| onSubmit | (values) => void | Yes | Submit handler |
|
|
166
|
+
| postSubmit | (values) => void | No | Post-submit side effects |
|
|
167
|
+
| onValuesChange | (values) => void | No | Global change listener |
|
|
168
|
+
| uiConfig | object | No | UI customization config |
|
|
137
169
|
|
|
138
|
-
|
|
139
|
-
readOnly?: boolean;
|
|
170
|
+
---
|
|
140
171
|
|
|
141
|
-
|
|
172
|
+
## AutoFormRef API
|
|
173
|
+
|
|
174
|
+
| Method | Type | Description |
|
|
175
|
+
|---|---|---|
|
|
176
|
+
| submit | () => void | Triggers form submission |
|
|
177
|
+
| reset | (values?) => void | Resets form state |
|
|
178
|
+
| validate | () => boolean | Runs validation |
|
|
179
|
+
| getValues | () => FormValues | Returns current values |
|
|
180
|
+
| setValues | (values) => void | Updates multiple values |
|
|
181
|
+
| getFieldValue | (path) => any | Returns field value |
|
|
182
|
+
| setFieldValue | (path, value) => void | Updates field value |
|
|
183
|
+
| isValid | () => boolean | Returns validity state |
|
|
184
|
+
| isDirty | () => boolean | Returns dirty state |
|
|
185
|
+
| isLoading | () => boolean | Returns loading state |
|
|
142
186
|
|
|
143
|
-
|
|
187
|
+
---
|
|
144
188
|
|
|
145
|
-
|
|
189
|
+
## Customization
|
|
146
190
|
|
|
147
|
-
|
|
191
|
+
AutoForma supports customization through custom field renderers and schema configuration.
|
|
148
192
|
|
|
149
|
-
|
|
150
|
-
|
|
193
|
+
```tsx
|
|
194
|
+
<AutoForm
|
|
195
|
+
schema={schema}
|
|
196
|
+
uiConfig={{
|
|
197
|
+
customTypeRenderers: {
|
|
198
|
+
text: CustomTextRenderer,
|
|
199
|
+
},
|
|
200
|
+
}}
|
|
201
|
+
/>
|
|
151
202
|
```
|
|
152
203
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
| Prop | Type | Description |
|
|
156
|
-
|------|------|--------------|
|
|
157
|
-
| `schema` | `FieldSchema[]` | The main schema defining all form fields. |
|
|
158
|
-
| `initialValues` | `ValueProvider<TValues>` | Function or object returning the **initial form values** (called once). |
|
|
159
|
-
| `currentValues` | `ValueProvider<TValues>` | Function or object providing **current values** (reactively updated). |
|
|
160
|
-
| `prepareValues` | `(values) => TValues \| Promise<TValues>` | Modify or sanitize values before submit. |
|
|
161
|
-
| `onSubmit` | `(values) => void \| Promise<void>` | Called when the form is submitted. |
|
|
162
|
-
| `afterSubmit` | `(values) => void \| Promise<void>` | Called after successful submission (for side effects). |
|
|
163
|
-
| `validate` | `FormValidateInput<TValues>` | Mantine validation config or validation schema. |
|
|
164
|
-
| `readOnly` | `boolean` | Makes the entire form read-only. |
|
|
165
|
-
| `onFieldChange` | `OnFieldChangeMap<TValues>` | Map of field-specific change handlers. |
|
|
166
|
-
| `layout` | `"vertical" \| "horizontal" \| "grid"` | Form layout type. |
|
|
167
|
-
| `updateFieldSchema` | `UpdateFieldSchemaMap<TValues>` | Dynamically modify schema based on values. |
|
|
168
|
-
| `submitButton` | `boolean \| ReactNode` | Whether to render or customize the submit button. |
|
|
169
|
-
| `loading` | `boolean` | Display a global loading state for the form. |
|
|
204
|
+
For advanced customization examples, visit the Storybook.
|
|
170
205
|
|
|
171
206
|
---
|
|
172
207
|
|
|
173
|
-
##
|
|
208
|
+
## Documentation
|
|
174
209
|
|
|
175
|
-
|
|
210
|
+
Storybook: https://sajinael98.github.io/AutoForma
|
|
176
211
|
|
|
177
|
-
|
|
178
|
-
export type CustomRenderersConfig<
|
|
179
|
-
TValues extends Record<string, any> = Record<string, any>
|
|
180
|
-
> = {
|
|
181
|
-
customFieldRenderers?: Record<
|
|
182
|
-
string,
|
|
183
|
-
(
|
|
184
|
-
field: FieldSchema<TValues>,
|
|
185
|
-
form: UseFormReturnType<TValues>
|
|
186
|
-
) => React.ReactNode
|
|
187
|
-
>;
|
|
188
|
-
customTypeRenderers?: Record<
|
|
189
|
-
string,
|
|
190
|
-
(
|
|
191
|
-
field: FieldSchema<TValues>,
|
|
192
|
-
form: UseFormReturnType<TValues>
|
|
193
|
-
) => React.ReactNode
|
|
194
|
-
>;
|
|
195
|
-
customFieldTypes?: Record<
|
|
196
|
-
string,
|
|
197
|
-
(
|
|
198
|
-
field: FieldSchema<TValues>,
|
|
199
|
-
form: UseFormReturnType<TValues>
|
|
200
|
-
) => React.ReactNode
|
|
201
|
-
>;
|
|
202
|
-
};
|
|
203
|
-
```
|
|
212
|
+
---
|
|
204
213
|
|
|
205
|
-
|
|
214
|
+
## License
|
|
206
215
|
|
|
207
|
-
|
|
208
|
-
|------|------|--------------|
|
|
209
|
-
| `customFieldRenderers` | `Record<string, (field, form) => ReactNode>` | Override rendering for specific **field names**. |
|
|
210
|
-
| `customTypeRenderers` | `Record<string, (field, form) => ReactNode>` | Override rendering for specific **field types** (like `select`, `text`, etc.). |
|
|
211
|
-
| `customFieldTypes` | `Record<string, (field, form) => ReactNode>` | Register completely new **custom field types**. |
|
|
216
|
+
MIT
|
|
@@ -27,6 +27,7 @@ export interface AutoFormProps<FormValues extends Record<string, any> = Record<s
|
|
|
27
27
|
preSubmit?: (values: FormValues) => FormValues | Promise<FormValues>;
|
|
28
28
|
onSubmit: (values: FormValues) => void | Promise<void>;
|
|
29
29
|
postSubmit?: (values: FormValues) => void | Promise<void>;
|
|
30
|
+
onValuesChange?: (values: FormValues) => void;
|
|
30
31
|
uiConfig?: {
|
|
31
32
|
customTypeRenderers?: Record<string, React.ComponentType<FieldRendererProps<FormValues>>>;
|
|
32
33
|
customFieldNameRenderers?: Record<string, React.ComponentType<FieldRendererProps<FormValues>>>;
|
|
@@ -44,6 +45,5 @@ export interface AutoFormRef {
|
|
|
44
45
|
isValid: () => boolean;
|
|
45
46
|
isDirty: () => boolean;
|
|
46
47
|
isLoading: () => boolean;
|
|
47
|
-
watch: <Field extends string>(path: Field, subscriber: (value: any, previousValue: any) => void) => void;
|
|
48
48
|
}
|
|
49
49
|
export {};
|