@homefile/components-v2 2.27.5 → 2.27.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.
|
@@ -2,28 +2,30 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Stack } from '@chakra-ui/react';
|
|
3
3
|
import { TextField, SelectField, SwitchField, NumberField, FieldDivider, } from '../..';
|
|
4
4
|
import { fieldIcons } from '../../../helpers';
|
|
5
|
+
import { FormProvider, useForm } from 'react-hook-form';
|
|
5
6
|
export const SimpleDynamicForm = ({ dividerStyle, fields, showIcon = false, height = 'full', boxShadow = 'md', }) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
const form = useForm();
|
|
8
|
+
return (_jsx(Stack, { bg: "neutral.white", spacing: "0", h: height, boxShadow: boxShadow, children: _jsx(FormProvider, Object.assign({}, form, { children: fields === null || fields === void 0 ? void 0 : fields.map((field) => {
|
|
9
|
+
const { description, icon, id, name, options, type, value } = field;
|
|
10
|
+
const baseProps = {
|
|
11
|
+
description,
|
|
12
|
+
id,
|
|
13
|
+
value,
|
|
14
|
+
icon: icon ? fieldIcons[icon] : undefined,
|
|
15
|
+
placeholder: name !== null && name !== void 0 ? name : description,
|
|
16
|
+
};
|
|
17
|
+
switch (type) {
|
|
18
|
+
case 'number':
|
|
19
|
+
return (_jsx(FieldDivider, { style: dividerStyle, children: _jsx(NumberField, Object.assign({}, baseProps)) }, id));
|
|
20
|
+
case 'text':
|
|
21
|
+
case 'string':
|
|
22
|
+
return (_jsx(FieldDivider, { style: dividerStyle, children: _jsx(TextField, Object.assign({}, baseProps, { showIcon: showIcon })) }, id));
|
|
23
|
+
case 'select':
|
|
24
|
+
return (_jsx(FieldDivider, { style: dividerStyle, children: _jsx(SelectField, Object.assign({}, baseProps, { options: options })) }, id));
|
|
25
|
+
case 'switch':
|
|
26
|
+
return (_jsx(FieldDivider, { style: dividerStyle, children: _jsx(SwitchField, Object.assign({}, baseProps)) }, id));
|
|
27
|
+
default:
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}) })) }));
|
|
29
31
|
};
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
FieldDivider,
|
|
9
9
|
} from '@/components'
|
|
10
10
|
import { fieldIcons } from '@/helpers'
|
|
11
|
+
import { FormProvider, useForm } from 'react-hook-form'
|
|
11
12
|
|
|
12
13
|
export const SimpleDynamicForm = ({
|
|
13
14
|
dividerStyle,
|
|
@@ -16,48 +17,51 @@ export const SimpleDynamicForm = ({
|
|
|
16
17
|
height = 'full',
|
|
17
18
|
boxShadow = 'md',
|
|
18
19
|
}: SimpleDynamicFormI) => {
|
|
20
|
+
const form = useForm()
|
|
19
21
|
return (
|
|
20
22
|
<Stack bg="neutral.white" spacing="0" h={height} boxShadow={boxShadow}>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
<FormProvider {...form}>
|
|
24
|
+
{fields?.map((field) => {
|
|
25
|
+
const { description, icon, id, name, options, type, value } = field
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
27
|
+
const baseProps = {
|
|
28
|
+
description,
|
|
29
|
+
id,
|
|
30
|
+
value,
|
|
31
|
+
icon: icon ? (fieldIcons[icon] as IconTypes) : undefined,
|
|
32
|
+
placeholder: name ?? description,
|
|
33
|
+
}
|
|
34
|
+
switch (type) {
|
|
35
|
+
case 'number':
|
|
36
|
+
return (
|
|
37
|
+
<FieldDivider key={id} style={dividerStyle}>
|
|
38
|
+
<NumberField {...baseProps} />
|
|
39
|
+
</FieldDivider>
|
|
40
|
+
)
|
|
41
|
+
case 'text':
|
|
42
|
+
case 'string':
|
|
43
|
+
return (
|
|
44
|
+
<FieldDivider key={id} style={dividerStyle}>
|
|
45
|
+
<TextField {...baseProps} showIcon={showIcon} />
|
|
46
|
+
</FieldDivider>
|
|
47
|
+
)
|
|
48
|
+
case 'select':
|
|
49
|
+
return (
|
|
50
|
+
<FieldDivider key={id} style={dividerStyle}>
|
|
51
|
+
<SelectField {...baseProps} options={options} />
|
|
52
|
+
</FieldDivider>
|
|
53
|
+
)
|
|
54
|
+
case 'switch':
|
|
55
|
+
return (
|
|
56
|
+
<FieldDivider key={id} style={dividerStyle}>
|
|
57
|
+
<SwitchField {...baseProps} />
|
|
58
|
+
</FieldDivider>
|
|
59
|
+
)
|
|
60
|
+
default:
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
})}
|
|
64
|
+
</FormProvider>
|
|
61
65
|
</Stack>
|
|
62
66
|
)
|
|
63
67
|
}
|