@homefile/components-v2 2.27.5 → 2.27.7

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