autoforma 1.0.1 → 1.0.4
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 +157 -157
- package/dist/{src/components → components}/AutoForm.d.ts +1 -2
- package/dist/index.cjs.js +18 -15
- package/dist/index.es.js +6261 -5405
- package/package.json +23 -58
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/render.d.ts +0 -1
- package/src/components/AutoForm.tsx +0 -201
- package/src/components/FieldRender.tsx +0 -217
- package/src/components/fields/ArrayField.tsx +0 -59
- package/src/components/fields/CheckField.tsx +0 -23
- package/src/components/fields/DateField.tsx +0 -26
- package/src/components/fields/DateTimeField.tsx +0 -26
- package/src/components/fields/NumberField.tsx +0 -20
- package/src/components/fields/ObjectField.tsx +0 -41
- package/src/components/fields/SelectField.tsx +0 -23
- package/src/components/fields/TextAreaField.tsx +0 -25
- package/src/components/fields/TextField.tsx +0 -20
- package/src/components/fields/TimeField.tsx +0 -32
- package/src/types/custom-render.ts +0 -22
- package/src/types/field.ts +0 -32
- package/src/types/form.ts +0 -8
- /package/dist/{src/components → components}/FieldRender.d.ts +0 -0
- /package/dist/{src/components → components}/fields/ArrayField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/CheckField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/DateField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/DateTimeField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/NumberField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/ObjectField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/SelectField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/TextAreaField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/TextField.d.ts +0 -0
- /package/dist/{src/components → components}/fields/TimeField.d.ts +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/stories → stories}/AutoForm.stories.d.ts +0 -0
- /package/dist/{src/stories → stories}/Fields.stories.d.ts +0 -0
- /package/dist/{src/theme.d.ts → theme.d.ts} +0 -0
- /package/dist/{src/types → types}/custom-render.d.ts +0 -0
- /package/dist/{src/types → types}/field.d.ts +0 -0
- /package/dist/{src/types → types}/form.d.ts +0 -0
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { BaseFieldProps, FieldSchema } from '@/types/field';
|
|
3
|
-
import FieldRender from '../FieldRender';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface ObjectFieldProps extends BaseFieldProps<Record<string, any>> {
|
|
7
|
-
fields: FieldSchema[];
|
|
8
|
-
formValues: Record<string, any>;
|
|
9
|
-
error?: Record<string, React.ReactNode>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const ObjectField: React.FC<ObjectFieldProps> = (props) => {
|
|
13
|
-
const {
|
|
14
|
-
fields,
|
|
15
|
-
name: parentName,
|
|
16
|
-
onChange: onParentChange,
|
|
17
|
-
value,
|
|
18
|
-
formValues,
|
|
19
|
-
error = {},
|
|
20
|
-
readOnly,
|
|
21
|
-
} = props;
|
|
22
|
-
|
|
23
|
-
const onChange = (name: string, value: any) => {
|
|
24
|
-
onParentChange(`${parentName}.${name}`, value);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const content = fields.map((field, index) => (
|
|
28
|
-
<FieldRender
|
|
29
|
-
key={index}
|
|
30
|
-
field={field}
|
|
31
|
-
formValues={formValues}
|
|
32
|
-
onChange={onChange}
|
|
33
|
-
value={value[field.name]}
|
|
34
|
-
error={error[field.name]}
|
|
35
|
-
readOnly={readOnly}
|
|
36
|
-
/>
|
|
37
|
-
));
|
|
38
|
-
return content;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default ObjectField;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Select } from '@mantine/core';
|
|
3
|
-
import { BaseFieldProps } from '@/types/field';
|
|
4
|
-
|
|
5
|
-
interface SelectFieldProps extends BaseFieldProps<string> {
|
|
6
|
-
data: { label: string; value: string }[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const SelectField: React.FC<SelectFieldProps> = (props) => {
|
|
10
|
-
const { data, name, onChange, value, readOnly } = props;
|
|
11
|
-
return (
|
|
12
|
-
<Select
|
|
13
|
-
name={name}
|
|
14
|
-
data={data}
|
|
15
|
-
value={value}
|
|
16
|
-
onChange={(value) => onChange(name, value)}
|
|
17
|
-
readOnly={readOnly}
|
|
18
|
-
clearable
|
|
19
|
-
/>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default SelectField;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Textarea } from '@mantine/core';
|
|
3
|
-
import { BaseFieldProps } from '@/types/field';
|
|
4
|
-
|
|
5
|
-
interface TextAreaFieldProps extends BaseFieldProps<string> {}
|
|
6
|
-
|
|
7
|
-
const TextAreaField: React.FC<TextAreaFieldProps> = (props) => {
|
|
8
|
-
const { name, onChange, value, readOnly } = props;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<Textarea
|
|
12
|
-
name={name}
|
|
13
|
-
onChange={(e) => onChange(name, e.target.value)}
|
|
14
|
-
value={value}
|
|
15
|
-
readOnly={readOnly}
|
|
16
|
-
styles={{
|
|
17
|
-
input: {
|
|
18
|
-
height: 200
|
|
19
|
-
}
|
|
20
|
-
}}
|
|
21
|
-
/>
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default TextAreaField;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { TextInput } from '@mantine/core';
|
|
3
|
-
import { BaseFieldProps } from '@/types/field';
|
|
4
|
-
|
|
5
|
-
interface TextFieldProps extends BaseFieldProps<string> {}
|
|
6
|
-
|
|
7
|
-
const TextField: React.FC<TextFieldProps> = (props) => {
|
|
8
|
-
const { name, onChange, value, readOnly } = props;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<TextInput
|
|
12
|
-
name={name}
|
|
13
|
-
onChange={(value) => onChange(name, value.target.value)}
|
|
14
|
-
value={value}
|
|
15
|
-
readOnly={readOnly}
|
|
16
|
-
/>
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default TextField;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
2
|
-
import { ActionIcon } from '@mantine/core';
|
|
3
|
-
import { TimeInput } from '@mantine/dates';
|
|
4
|
-
import { BaseFieldProps } from '@/types/field';
|
|
5
|
-
|
|
6
|
-
interface TimeFieldProps extends BaseFieldProps<string> {}
|
|
7
|
-
|
|
8
|
-
const TimeField: React.FC<TimeFieldProps> = (props) => {
|
|
9
|
-
const { name, onChange, value, readOnly } = props;
|
|
10
|
-
|
|
11
|
-
const ref = useRef<HTMLInputElement>(null);
|
|
12
|
-
|
|
13
|
-
const pickerControl = (
|
|
14
|
-
<ActionIcon variant="subtle" color="gray" onClick={() => ref.current?.showPicker()}>
|
|
15
|
-
🕛
|
|
16
|
-
</ActionIcon>
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<TimeInput
|
|
21
|
-
name={name}
|
|
22
|
-
onChange={(e) => onChange(name, e.target.value)}
|
|
23
|
-
value={value}
|
|
24
|
-
readOnly={readOnly}
|
|
25
|
-
ref={ref}
|
|
26
|
-
rightSection={pickerControl}
|
|
27
|
-
withSeconds
|
|
28
|
-
/>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export default TimeField;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// types/custom-render.ts
|
|
2
|
-
import { ArrayFieldOptions, FieldSchema } from './field';
|
|
3
|
-
|
|
4
|
-
export type FieldRenderCustomRender = (
|
|
5
|
-
field: FieldSchema,
|
|
6
|
-
value: any,
|
|
7
|
-
error: React.ReactNode | Record<string, React.ReactNode>,
|
|
8
|
-
onChange: (name: string, value: any) => void,
|
|
9
|
-
formValues: Record<string, any>,
|
|
10
|
-
options?: ArrayFieldOptions,
|
|
11
|
-
readOnly?: true
|
|
12
|
-
) => React.ReactNode;
|
|
13
|
-
|
|
14
|
-
export interface CustomFieldRender {
|
|
15
|
-
field: FieldSchema;
|
|
16
|
-
value: any;
|
|
17
|
-
error: React.ReactNode | Record<string, React.ReactNode>;
|
|
18
|
-
onChange: (name: string, value: any) => void;
|
|
19
|
-
formValues: Record<string, any>;
|
|
20
|
-
options?: ArrayFieldOptions;
|
|
21
|
-
readOnly?: true;
|
|
22
|
-
}
|
package/src/types/field.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export type FieldType = 'text' | 'number' | 'object' | 'array' | 'check' | 'select' | 'textarea' | 'date' | 'datetime' | 'time';
|
|
2
|
-
|
|
3
|
-
export interface FieldSchema {
|
|
4
|
-
name: string;
|
|
5
|
-
type: FieldType;
|
|
6
|
-
label: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
placeholder?: string;
|
|
9
|
-
extra?: Record<string, any>;
|
|
10
|
-
disabled?: (values: Record<string, any>) => boolean | boolean;
|
|
11
|
-
visible?: (values: Record<string, any>) => boolean | boolean;
|
|
12
|
-
initialValue?: any;
|
|
13
|
-
required?: true;
|
|
14
|
-
readOnly?: true;
|
|
15
|
-
// for object type only
|
|
16
|
-
fields?: FieldSchema[];
|
|
17
|
-
// for select type only
|
|
18
|
-
data?: { label: string; value: string }[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface BaseFieldProps<T> {
|
|
22
|
-
name: string;
|
|
23
|
-
value: T;
|
|
24
|
-
onChange: (name: string, value: T | null) => void;
|
|
25
|
-
readOnly?: true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type ArrayFieldOptions = {
|
|
29
|
-
addElement: (value: Record<string, any>) => void;
|
|
30
|
-
replaceElement: (index: number, val: Record<string, any>) => void;
|
|
31
|
-
removeElement: (index: number) => void;
|
|
32
|
-
};
|
package/src/types/form.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|