dynamic-modal 1.1.8 → 1.1.10

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.
Files changed (63) hide show
  1. package/README.md +0 -1
  2. package/dist/components/input-upload/input-upload.js +3 -3
  3. package/dist/components/make-button/make-button.js +19 -10
  4. package/dist/components/make-description/make-description.js +2 -2
  5. package/dist/components/make-input/make-input.js +57 -29
  6. package/dist/components/make-select/make-select.js +66 -29
  7. package/dist/components/make-textarea/make-textarea.js +57 -29
  8. package/dist/components/make-toggle/make-toggle.js +57 -29
  9. package/dist/components/make-upload/make-upload.js +72 -18
  10. package/dist/components/portal/portal.js +20 -10
  11. package/dist/context/component/component-state.d.ts +3 -3
  12. package/dist/context/component/component-state.js +20 -11
  13. package/dist/hooks/use-enable-if.d.ts +9 -0
  14. package/dist/hooks/use-enable-if.js +45 -0
  15. package/dist/hooks/use-live-data.d.ts +14 -0
  16. package/dist/hooks/use-live-data.js +42 -0
  17. package/dist/hooks/use-render-if.d.ts +12 -0
  18. package/dist/hooks/use-render-if.js +51 -0
  19. package/dist/interfaces/component-state.d.ts +8 -8
  20. package/dist/interfaces/modal.d.ts +4 -2
  21. package/dist/modal.js +70 -58
  22. package/dist/util/general/general.util.d.ts +3 -0
  23. package/dist/util/general/general.util.js +28 -0
  24. package/eslint.config.mjs +72 -14
  25. package/examples/live-data.ts +0 -1
  26. package/package.json +11 -9
  27. package/src/components/input-upload/input-upload.tsx +40 -28
  28. package/src/components/make-button/make-button.tsx +11 -13
  29. package/src/components/make-description/make-description.tsx +14 -8
  30. package/src/components/make-input/make-input.tsx +94 -47
  31. package/src/components/make-select/make-select.tsx +118 -48
  32. package/src/components/make-textarea/make-textarea.tsx +94 -47
  33. package/src/components/make-toggle/make-toggle.tsx +94 -47
  34. package/src/components/make-upload/make-upload.tsx +88 -36
  35. package/src/components/portal/portal.tsx +27 -25
  36. package/src/context/component/component-state.tsx +16 -9
  37. package/src/hooks/modal-handler.ts +17 -14
  38. package/src/hooks/use-enable-if.ts +64 -0
  39. package/src/hooks/use-live-data.ts +45 -0
  40. package/src/hooks/use-render-if.ts +59 -0
  41. package/src/interfaces/component-state.ts +38 -23
  42. package/src/interfaces/field.ts +33 -27
  43. package/src/interfaces/input-upload.ts +17 -15
  44. package/src/interfaces/make-button.ts +14 -13
  45. package/src/interfaces/make-description.ts +9 -8
  46. package/src/interfaces/make-field-group.ts +9 -8
  47. package/src/interfaces/make-input.ts +9 -8
  48. package/src/interfaces/make-select.ts +9 -9
  49. package/src/interfaces/make-textarea.ts +5 -5
  50. package/src/interfaces/make-toggle.ts +3 -3
  51. package/src/interfaces/make-upload.ts +8 -8
  52. package/src/interfaces/modal.ts +57 -39
  53. package/src/interfaces/option.ts +3 -3
  54. package/src/interfaces/portal.ts +5 -5
  55. package/src/modal.tsx +243 -147
  56. package/src/util/general/general.util.ts +27 -0
  57. package/tsconfig.json +1 -1
  58. package/dist/hooks/field-render.d.ts +0 -20
  59. package/dist/hooks/field-render.js +0 -94
  60. package/dist/tools/general.d.ts +0 -1
  61. package/dist/tools/general.js +0 -11
  62. package/src/hooks/field-render.ts +0 -120
  63. package/src/tools/general.ts +0 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynamic-modal",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "The dynamic-modal is a solution of creation different modals into project using a json configuration file",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,17 +26,19 @@
26
26
  },
27
27
  "homepage": "https://gitlab.com/f.salazar/dynamic-modal#readme",
28
28
  "devDependencies": {
29
- "@eslint/js": "^9.22.0",
29
+ "@eslint/js": "^9.29.0",
30
+ "@typescript-eslint/eslint-plugin": "^8.34.1",
31
+ "@typescript-eslint/parser": "^8.34.1",
32
+ "eslint": "^9.29.0",
33
+ "eslint-config-next": "15.2.2",
34
+ "eslint-config-prettier": "^10.1.5",
35
+ "eslint-plugin-prettier": "^5.5.0",
36
+ "typescript-eslint": "^8.34.1",
30
37
  "@types/react": "^19.0.10",
31
38
  "@types/react-dom": "^19.0.4",
32
- "@typescript-eslint/eslint-plugin": "^8.26.1",
33
- "@typescript-eslint/parser": "^8.26.1",
34
- "eslint": "^9.22.0",
35
- "eslint-plugin-react": "^7.37.4",
36
- "eslint-plugin-react-hooks": "^5.2.0",
37
39
  "globals": "^16.0.0",
38
- "typescript": "^5.8.2",
39
- "typescript-eslint": "^8.26.1"
40
+ "prettier": "^3.5.3",
41
+ "typescript": "^5.8.3"
40
42
  },
41
43
  "dependencies": {
42
44
  "react": "^19.0.0",
@@ -1,48 +1,59 @@
1
- 'use client'
1
+ 'use client';
2
2
 
3
- import React, { ChangeEvent, FC } from 'react'
4
- import { IFileResult, IInputUpload } from '../../interfaces/input-upload'
3
+ import React, { ChangeEvent, FC } from 'react';
5
4
 
6
- const InputUpload: FC<IInputUpload> = ({ onChange, readAsArrayBuffer, ...props }: IInputUpload) => {
7
-
5
+ import { IFileResult, IInputUpload } from '../../interfaces/input-upload';
6
+
7
+ const InputUpload: FC<IInputUpload> = ({
8
+ onChange,
9
+ readAsArrayBuffer,
10
+ ...props
11
+ }: IInputUpload) => {
8
12
  const onChangeHandler = (event: ChangeEvent<HTMLInputElement>) => {
9
13
  if (props.read && event.target.files) {
10
14
  readFileBlob(event.target.files[0], false)
11
15
  .then((result) => onChange(result))
12
16
  .catch((err) => {
13
- console.error('file read error', err)
14
- onChange({name:'', size: 0, data: ''})
15
- })
17
+ console.error('file read error', err);
18
+ onChange({ name: '', size: 0, data: '' });
19
+ });
16
20
  } else {
17
- onChange(event.target.files)
21
+ onChange(event.target.files);
18
22
  }
19
- }
23
+ };
20
24
 
21
25
  const readFileBlob = (blob: File, image: boolean): Promise<IFileResult> => {
22
26
  return new Promise((resolve, reject) => {
23
- const fileReader = new FileReader()
24
- if(image) fileReader.readAsDataURL(blob)
25
- else if (readAsArrayBuffer) fileReader.readAsArrayBuffer(blob)
26
- else fileReader.readAsText(blob)
27
+ const fileReader = new FileReader();
28
+ if (image) fileReader.readAsDataURL(blob);
29
+ else if (readAsArrayBuffer) fileReader.readAsArrayBuffer(blob);
30
+ else fileReader.readAsText(blob);
27
31
 
28
32
  fileReader.onload = () => {
29
33
  const fileResult: IFileResult = {
30
34
  name: blob.name,
31
35
  size: blob.size,
32
- data: fileReader.result as string
33
- }
36
+ data: fileReader.result as string,
37
+ };
34
38
 
35
- resolve(fileResult)
36
- }
39
+ resolve(fileResult);
40
+ };
37
41
  fileReader.onerror = (error) => {
38
- reject(error)
39
- }
40
- })
41
- }
42
+ reject(error);
43
+ };
44
+ });
45
+ };
42
46
 
43
47
  return (
44
- <div className='flex flex-col w-full gap-1 text-center'>
45
- {props.label && <label className="block mb-2 text-sm font-medium text-gray-900 dark:text-white" htmlFor={`file-input-${props.id}`}>{props.label}</label>}
48
+ <div className="flex flex-col w-full gap-1 text-center">
49
+ {props.label && (
50
+ <label
51
+ className="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
52
+ htmlFor={`file-input-${props.id}`}
53
+ >
54
+ {props.label}
55
+ </label>
56
+ )}
46
57
  <input
47
58
  className="file:transition-all file:delay-150 block w-full text-sm text-slate-500
48
59
  file:mr-4 file:py-2 file:px-4 file:rounded-md
@@ -57,11 +68,12 @@ const InputUpload: FC<IInputUpload> = ({ onChange, readAsArrayBuffer, ...props }
57
68
  />
58
69
  <p
59
70
  className="mt-1 text-sm text-gray-500 dark:text-gray-300 text-start"
60
- id={`file-input-${props.id}-help`}>
71
+ id={`file-input-${props.id}-help`}
72
+ >
61
73
  {props.helpText?.toUpperCase()}
62
74
  </p>
63
75
  </div>
64
- )
65
- }
76
+ );
77
+ };
66
78
 
67
- export default InputUpload
79
+ export default InputUpload;
@@ -1,18 +1,16 @@
1
- 'use client'
1
+ 'use client';
2
2
 
3
- import React, { FC, useContext, useMemo } from 'react'
4
- import { IMakeButtonProps } from '../../interfaces/make-button'
5
- import { ComponentStateContext } from '../../context/component/component-state'
6
- import { generateId } from '../../tools/general'
3
+ import React, { FC, useContext, useId } from 'react';
4
+
5
+ import { IMakeButtonProps } from '../../interfaces/make-button';
6
+ import { ComponentStateContext } from '../../context/component/component-state';
7
7
 
8
8
  const MakeButton: FC<IMakeButtonProps> = ({ element }) => {
9
- const { Button } = useContext(ComponentStateContext)
9
+ const { Button } = useContext(ComponentStateContext);
10
+
11
+ const elementId = useId();
10
12
 
11
- const elementId = useMemo(() => element.id ?? generateId(), [])
12
-
13
- return (
14
- <Button {...element} id={elementId} />
15
- )
16
- }
13
+ return <Button {...element} id={elementId} />;
14
+ };
17
15
 
18
- export default MakeButton
16
+ export default MakeButton;
@@ -1,15 +1,21 @@
1
- 'use client'
1
+ 'use client';
2
2
 
3
- import React, { FC } from 'react'
4
- import { IMakeDescriptionProps } from '../../interfaces/make-description'
3
+ import React, { FC } from 'react';
5
4
 
6
- const MakeDescription: FC<IMakeDescriptionProps> = ({ element: { text, Icon, containerStyle, textStyle } }) => {
5
+ import { IMakeDescriptionProps } from '../../interfaces/make-description';
6
+
7
+ const MakeDescription: FC<IMakeDescriptionProps> = ({
8
+ element: { text, Icon, containerStyle, textStyle },
9
+ }) => {
7
10
  return (
8
- <div className='flex gap-4 w-full h-auto text-xs text-center p-2 border-1 rounded-md' style={containerStyle}>
11
+ <div
12
+ className="flex gap-4 w-full h-auto text-xs text-center p-2 border-1 rounded-md"
13
+ style={containerStyle}
14
+ >
9
15
  {Icon && <Icon />}
10
16
  <p style={textStyle}>{text}</p>
11
17
  </div>
12
- )
13
- }
18
+ );
19
+ };
14
20
 
15
- export default MakeDescription
21
+ export default MakeDescription;
@@ -1,53 +1,100 @@
1
- 'use client'
1
+ 'use client';
2
2
 
3
- import React, { FC, useContext, useEffect, useMemo } from 'react'
4
- import { Controller } from 'react-hook-form'
5
- import { useFieldRender } from '../../hooks/field-render'
6
- import { IMakeInputProps } from '../../interfaces/make-input'
7
- import { ComponentStateContext } from '../../context/component/component-state'
8
- import { generateId } from '../../tools/general'
3
+ import React, { FC, useContext, useEffect, useId } from 'react';
4
+ import { Controller } from 'react-hook-form';
9
5
 
10
- const MakeInput: FC<IMakeInputProps> = ({ element: { validation: { required, ...validation }, enableIf, renderIf, ...element }, ...props }) => {
11
- const { Input } = useContext(ComponentStateContext)
12
- const { render, enable, checkField } = useFieldRender({ ...props, element: { enableIf, renderIf, ...element} })
6
+ import { IMakeInputProps } from '../../interfaces/make-input';
7
+ import { ComponentStateContext } from '../../context/component/component-state';
8
+ import useEnableIf from '../../hooks/use-enable-if';
9
+ import useRenderIf from '../../hooks/use-render-if';
10
+
11
+ const MakeInput: FC<IMakeInputProps> = ({
12
+ element,
13
+ control,
14
+ watch,
15
+ unregister,
16
+ }) => {
17
+ const { Input } = useContext(ComponentStateContext);
18
+
19
+ const {
20
+ name: elementName,
21
+ validation: { required, message, regex, ...otherValidation },
22
+ enableIf,
23
+ renderIf,
24
+ ...inputProps
25
+ } = element;
26
+
27
+ const { checkEnable, enable, setEnable } = useEnableIf({
28
+ elementEnableIf: enableIf,
29
+ });
30
+ const { checkRender, render, setRender } = useRenderIf({
31
+ elementRenderIf: renderIf,
32
+ });
33
+
34
+ const elementId = useId();
13
35
 
14
- const elementId = useMemo(() => element.id ?? generateId(), [])
15
-
16
36
  useEffect(() => {
17
- const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }))
18
- return () => subscription.unsubscribe()
19
- }, [checkField, props])
37
+ const { unsubscribe } = watch((formData, { name, type }) => {
38
+ if (!name) return;
39
+
40
+ if (enableIf) {
41
+ checkEnable(formData, { name, type }).then((enableStatus) => {
42
+ if (enableStatus === undefined || enableStatus === null) return;
43
+ if (enable !== enableStatus) setEnable(enableStatus);
44
+ });
45
+ }
46
+
47
+ if (renderIf) {
48
+ checkRender(formData, { name, type }).then((renderStatus) => {
49
+ if (renderStatus === undefined || renderStatus === null) return;
50
+
51
+ if (render !== renderStatus) {
52
+ if (render && !renderStatus) unregister(elementName as string);
53
+ setRender(!!renderStatus);
54
+ }
55
+ });
56
+ }
57
+ });
58
+
59
+ return () => unsubscribe();
60
+ }, [watch, render, enable]);
61
+
62
+ if (!render) return null;
20
63
 
21
64
  return (
22
- render
23
- ? <Controller
24
- control={props.control}
25
- name={element.name}
26
- rules={{
27
- required: {
28
- value: required,
29
- message: validation.message ?? ''
30
- },
31
- pattern: validation.regex ? {
32
- value: validation.regex,
33
- message: validation.message ?? ''
34
- } : undefined,
35
- ...validation
36
- }}
37
- render={({ field: { onChange, value }, fieldState: { invalid, error } }) => (
38
- <Input
39
- {...element}
40
- id={elementId}
41
- onChange={onChange}
42
- value={value ?? ''}
43
- invalid={invalid}
44
- error={error}
45
- disabled={element.disabled ?? !enable}
46
- />
47
- )}
48
- />
49
- : null
50
- )
51
- }
52
-
53
- export default MakeInput
65
+ <Controller
66
+ control={control}
67
+ name={elementName}
68
+ rules={{
69
+ required: {
70
+ value: required,
71
+ message: message ?? '',
72
+ },
73
+ pattern: regex
74
+ ? {
75
+ value: regex,
76
+ message: message ?? '',
77
+ }
78
+ : undefined,
79
+ ...otherValidation,
80
+ }}
81
+ render={({
82
+ field: { onChange, value },
83
+ fieldState: { invalid, error },
84
+ }) => (
85
+ <Input
86
+ {...inputProps}
87
+ name={elementName}
88
+ id={elementId}
89
+ onChange={onChange}
90
+ value={value ?? ''}
91
+ invalid={invalid}
92
+ error={error}
93
+ disabled={element.disabled ?? !enable}
94
+ />
95
+ )}
96
+ />
97
+ );
98
+ };
99
+
100
+ export default MakeInput;
@@ -1,55 +1,125 @@
1
- 'use client'
1
+ 'use client';
2
2
 
3
- import React, { FC, useContext, useEffect, useMemo } from 'react'
4
- import { Controller } from 'react-hook-form'
5
- import { useFieldRender } from '../../hooks/field-render'
6
- import { generateId } from '../../tools/general'
7
- import { IMakeSelectProps } from '../../interfaces/make-select'
8
- import { ComponentStateContext } from '../../context/component/component-state'
3
+ import React, { FC, useContext, useEffect, useId, useState } from 'react';
4
+ import { Controller } from 'react-hook-form';
9
5
 
10
- const MakeSelect: FC<IMakeSelectProps> = ({ element: { validation: { required, ...validation }, enableIf, renderIf, ...element }, ...props }) => {
11
- const { Select } = useContext(ComponentStateContext)
12
- const { render, enable, checkField, liveData, liveSearching } = useFieldRender({ ...props, element: { renderIf, enableIf, ...element} })
6
+ import { IMakeSelectProps } from '../../interfaces/make-select';
7
+ import { ComponentStateContext } from '../../context/component/component-state';
8
+ import useEnableIf from '../../hooks/use-enable-if';
9
+ import useRenderIf from '../../hooks/use-render-if';
10
+ import useLiveData from '../../hooks/use-live-data';
13
11
 
14
- const elementId = useMemo(() => element.id ?? generateId(), [])
12
+ const MakeSelect: FC<IMakeSelectProps> = ({
13
+ element,
14
+ control,
15
+ watch,
16
+ setValue,
17
+ unregister,
18
+ }) => {
19
+ const { Select } = useContext(ComponentStateContext);
20
+
21
+ const {
22
+ name: elementName,
23
+ validation: { required, message, regex, ...otherValidation },
24
+ enableIf,
25
+ renderIf,
26
+ liveData: elementLiveData,
27
+ ...inputProps
28
+ } = element;
29
+
30
+ const [liveSearching, setLiveSearching] = useState<boolean>(false);
31
+
32
+ const { checkLiveData, liveData, setLiveData } = useLiveData({
33
+ elementLiveData,
34
+ });
35
+ const { checkEnable, enable, setEnable } = useEnableIf({
36
+ elementEnableIf: enableIf,
37
+ });
38
+ const { checkRender, render, setRender } = useRenderIf({
39
+ elementRenderIf: renderIf,
40
+ });
41
+
42
+ const elementId = useId();
15
43
 
16
44
  useEffect(() => {
17
- const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }))
18
- return () => subscription.unsubscribe()
19
- }, [checkField, props, props.watch])
45
+ const { unsubscribe } = watch((formData, { name, type }) => {
46
+ if (!name) return;
47
+
48
+ if (enableIf) {
49
+ checkEnable(formData, { name, type }).then((enableStatus) => {
50
+ if (enableStatus === undefined || enableStatus === null) return;
51
+ if (enable !== enableStatus) setEnable(enableStatus);
52
+ });
53
+ }
54
+
55
+ if (renderIf) {
56
+ checkRender(formData, { name, type }).then((renderStatus) => {
57
+ if (renderStatus === undefined || renderStatus === null) return;
58
+
59
+ if (render !== renderStatus) {
60
+ if (render && !renderStatus) unregister(elementName as string);
61
+ setRender(!!renderStatus);
62
+ }
63
+ });
64
+ }
65
+
66
+ if (elementLiveData) {
67
+ setLiveSearching(true);
68
+
69
+ checkLiveData(formData, { name, type })
70
+ .then((options) => {
71
+ if (options === undefined || options === null) return;
72
+
73
+ setLiveData(options);
74
+ setValue(elementName, options);
75
+ })
76
+ .finally(() => {
77
+ setLiveSearching(false);
78
+ });
79
+ }
80
+ });
81
+
82
+ return () => unsubscribe();
83
+ }, [watch, render, enable, liveData]);
84
+
85
+ if (!render) return null;
20
86
 
21
87
  return (
22
- render
23
- ? <Controller
24
- control={props.control}
25
- name={element.name}
26
- rules={{
27
- required: {
28
- value: required,
29
- message: validation.message ?? ''
30
- },
31
- pattern: validation.regex ? {
32
- value: validation.regex,
33
- message: validation.message ?? ''
34
- } : undefined,
35
- ...validation
36
- }}
37
- render={({ field: { onChange, value }, fieldState: { invalid, error } }) => (
38
- <Select
39
- {...element}
40
- id={elementId}
41
- onChange={onChange}
42
- value={value}
43
- invalid={invalid}
44
- error={error}
45
- disabled={element.disabled ?? !enable}
46
- liveSearching={liveSearching}
47
- options={liveData || (element.options ?? [])}
48
- />
49
- )}
50
- />
51
- : <></>
52
- )
53
- }
54
-
55
- export default MakeSelect
88
+ <Controller
89
+ control={control}
90
+ name={elementName}
91
+ rules={{
92
+ required: {
93
+ value: required,
94
+ message: message ?? '',
95
+ },
96
+ pattern: regex
97
+ ? {
98
+ value: regex,
99
+ message: message ?? '',
100
+ }
101
+ : undefined,
102
+ ...otherValidation,
103
+ }}
104
+ render={({
105
+ field: { onChange, value },
106
+ fieldState: { invalid, error },
107
+ }) => (
108
+ <Select
109
+ {...inputProps}
110
+ id={elementId}
111
+ name={elementName}
112
+ onChange={onChange}
113
+ value={value}
114
+ invalid={invalid}
115
+ error={error}
116
+ disabled={element.disabled ?? !enable}
117
+ liveSearching={liveSearching}
118
+ options={liveData || (element.options ?? [])}
119
+ />
120
+ )}
121
+ />
122
+ );
123
+ };
124
+
125
+ export default MakeSelect;
@@ -1,53 +1,100 @@
1
- 'use client'
1
+ 'use client';
2
2
 
3
- import React, { FC, useContext, useEffect, useMemo } from 'react'
4
- import { Controller } from 'react-hook-form'
5
- import { useFieldRender } from '../../hooks/field-render'
6
- import { generateId } from '../../tools/general'
7
- import { IMakeTextareaProps } from '../../interfaces/make-textarea'
8
- import { ComponentStateContext } from '../../context/component/component-state'
3
+ import React, { FC, useContext, useEffect, useId } from 'react';
4
+ import { Controller } from 'react-hook-form';
9
5
 
10
- const MakeTextarea: FC<IMakeTextareaProps> = ({ element: { validation: { required, ...validation }, enableIf, renderIf, ...element }, ...props }) => {
11
- const { Textarea } = useContext(ComponentStateContext)
12
- const { render, enable, checkField } = useFieldRender({ ...props, element: { enableIf, renderIf, ...element } })
6
+ import { IMakeTextareaProps } from '../../interfaces/make-textarea';
7
+ import { ComponentStateContext } from '../../context/component/component-state';
8
+ import useEnableIf from '../../hooks/use-enable-if';
9
+ import useRenderIf from '../../hooks/use-render-if';
10
+
11
+ const MakeTextarea: FC<IMakeTextareaProps> = ({
12
+ element,
13
+ control,
14
+ watch,
15
+ unregister,
16
+ }) => {
17
+ const { Textarea } = useContext(ComponentStateContext);
18
+
19
+ const {
20
+ name: elementName,
21
+ validation: { required, message, regex, ...otherValidation },
22
+ enableIf,
23
+ renderIf,
24
+ ...inputProps
25
+ } = element;
26
+
27
+ const { checkEnable, enable, setEnable } = useEnableIf({
28
+ elementEnableIf: enableIf,
29
+ });
30
+ const { checkRender, render, setRender } = useRenderIf({
31
+ elementRenderIf: renderIf,
32
+ });
33
+
34
+ const elementId = useId();
13
35
 
14
- const elementId = useMemo(() => element.id ?? generateId(), [])
15
-
16
36
  useEffect(() => {
17
- const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }))
18
- return () => subscription.unsubscribe()
19
- }, [checkField, props, props.watch])
37
+ const { unsubscribe } = watch((formData, { name, type }) => {
38
+ if (!name) return;
39
+
40
+ if (enableIf) {
41
+ checkEnable(formData, { name, type }).then((enableStatus) => {
42
+ if (enableStatus === undefined || enableStatus === null) return;
43
+ if (enable !== enableStatus) setEnable(enableStatus);
44
+ });
45
+ }
46
+
47
+ if (renderIf) {
48
+ checkRender(formData, { name, type }).then((renderStatus) => {
49
+ if (renderStatus === undefined || renderStatus === null) return;
50
+
51
+ if (render !== renderStatus) {
52
+ if (render && !renderStatus) unregister(elementName as string);
53
+ setRender(!!renderStatus);
54
+ }
55
+ });
56
+ }
57
+ });
58
+
59
+ return () => unsubscribe();
60
+ }, [watch, render, enable]);
61
+
62
+ if (!render) return null;
20
63
 
21
64
  return (
22
- render
23
- ? <Controller
24
- name={element.name}
25
- control={props.control}
26
- rules={{
27
- required: {
28
- value: required,
29
- message: validation.message ?? ''
30
- },
31
- pattern: validation.regex ? {
32
- value: validation.regex,
33
- message: validation.message ?? ''
34
- } : undefined,
35
- ...validation
36
- }}
37
- render={({ field: { onChange, value }, fieldState: { invalid, error } }) => (
38
- <Textarea
39
- {...element}
40
- id={elementId}
41
- onChange={onChange}
42
- value={value ?? ''}
43
- invalid={invalid}
44
- error={error}
45
- disabled={element.disabled ?? !enable}
46
- />
47
- )}
48
- />
49
- : null
50
- )
51
- }
52
-
53
- export default MakeTextarea
65
+ <Controller
66
+ name={elementName}
67
+ control={control}
68
+ rules={{
69
+ required: {
70
+ value: required,
71
+ message: message ?? '',
72
+ },
73
+ pattern: regex
74
+ ? {
75
+ value: regex,
76
+ message: message ?? '',
77
+ }
78
+ : undefined,
79
+ ...otherValidation,
80
+ }}
81
+ render={({
82
+ field: { onChange, value },
83
+ fieldState: { invalid, error },
84
+ }) => (
85
+ <Textarea
86
+ {...inputProps}
87
+ id={elementId}
88
+ name={elementName}
89
+ onChange={onChange}
90
+ value={value ?? ''}
91
+ invalid={invalid}
92
+ error={error}
93
+ disabled={element.disabled ?? !enable}
94
+ />
95
+ )}
96
+ />
97
+ );
98
+ };
99
+
100
+ export default MakeTextarea;