dynamic-modal 1.1.19 → 1.1.21

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 (137) hide show
  1. package/dist/components/input-upload/input-upload.js +3 -9
  2. package/dist/components/make-button/make-button.js +4 -36
  3. package/dist/components/make-custom-upload/make-custom-upload.js +5 -37
  4. package/dist/components/make-description/make-description.js +4 -9
  5. package/dist/components/make-input/make-input.js +5 -37
  6. package/dist/components/make-select/make-select.js +5 -37
  7. package/dist/components/make-table/make-table.js +12 -53
  8. package/dist/components/make-textarea/make-textarea.js +5 -37
  9. package/dist/components/make-toggle/make-toggle.js +5 -37
  10. package/dist/components/make-upload/make-upload.js +5 -37
  11. package/dist/components/make-watcher/make-watcher.js +4 -36
  12. package/dist/components/portal/portal.js +4 -36
  13. package/dist/context/component/component-state.d.ts +1 -1
  14. package/dist/context/component/component-state.js +4 -36
  15. package/dist/hooks/modal-handler.js +1 -1
  16. package/dist/hooks/use-enable-if.js +1 -1
  17. package/dist/hooks/use-live-data.js +1 -1
  18. package/dist/hooks/use-render-if.js +1 -1
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.js +4 -0
  21. package/dist/interfaces/make-description.d.ts +2 -1
  22. package/dist/modal.d.ts +1 -2
  23. package/dist/modal.js +35 -75
  24. package/dist/src/components/input-upload/input-upload.d.ts +4 -0
  25. package/dist/src/components/input-upload/input-upload.js +41 -0
  26. package/dist/src/components/make-button/make-button.d.ts +4 -0
  27. package/dist/src/components/make-button/make-button.js +14 -0
  28. package/dist/src/components/make-custom-upload/make-custom-upload.d.ts +4 -0
  29. package/dist/src/components/make-custom-upload/make-custom-upload.js +60 -0
  30. package/dist/src/components/make-description/make-description.d.ts +4 -0
  31. package/dist/src/components/make-description/make-description.js +6 -0
  32. package/dist/src/components/make-input/make-input.d.ts +4 -0
  33. package/dist/src/components/make-input/make-input.js +60 -0
  34. package/dist/src/components/make-select/make-select.d.ts +4 -0
  35. package/dist/src/components/make-select/make-select.js +78 -0
  36. package/dist/src/components/make-table/make-table.d.ts +4 -0
  37. package/dist/src/components/make-table/make-table.js +100 -0
  38. package/dist/src/components/make-textarea/make-textarea.d.ts +4 -0
  39. package/dist/src/components/make-textarea/make-textarea.js +60 -0
  40. package/dist/src/components/make-toggle/make-toggle.d.ts +4 -0
  41. package/dist/src/components/make-toggle/make-toggle.js +60 -0
  42. package/dist/src/components/make-upload/make-upload.d.ts +4 -0
  43. package/dist/src/components/make-upload/make-upload.js +59 -0
  44. package/dist/src/components/make-watcher/make-watcher.d.ts +4 -0
  45. package/dist/src/components/make-watcher/make-watcher.js +28 -0
  46. package/dist/src/components/portal/portal.d.ts +3 -0
  47. package/dist/src/components/portal/portal.js +28 -0
  48. package/dist/src/context/component/component-state.d.ts +4 -0
  49. package/dist/src/context/component/component-state.js +8 -0
  50. package/dist/src/hooks/modal-handler.d.ts +7 -0
  51. package/dist/src/hooks/modal-handler.js +25 -0
  52. package/dist/src/hooks/use-enable-if.d.ts +10 -0
  53. package/dist/src/hooks/use-enable-if.js +36 -0
  54. package/dist/src/hooks/use-live-data.d.ts +11 -0
  55. package/dist/src/hooks/use-live-data.js +23 -0
  56. package/dist/src/hooks/use-render-if.d.ts +10 -0
  57. package/dist/src/hooks/use-render-if.js +36 -0
  58. package/dist/src/interfaces/component-state.d.ts +29 -0
  59. package/dist/src/interfaces/component-state.js +1 -0
  60. package/dist/src/interfaces/custom-upload.d.ts +12 -0
  61. package/dist/src/interfaces/custom-upload.js +1 -0
  62. package/dist/src/interfaces/field.d.ts +33 -0
  63. package/dist/src/interfaces/field.js +1 -0
  64. package/dist/src/interfaces/input-upload.d.ts +19 -0
  65. package/dist/src/interfaces/input-upload.js +1 -0
  66. package/dist/src/interfaces/make-button.d.ts +20 -0
  67. package/dist/src/interfaces/make-button.js +1 -0
  68. package/{src/interfaces/make-custom-upload.ts → dist/src/interfaces/make-custom-upload.d.ts} +2 -4
  69. package/dist/src/interfaces/make-custom-upload.js +1 -0
  70. package/dist/src/interfaces/make-description.d.ts +13 -0
  71. package/dist/src/interfaces/make-description.js +1 -0
  72. package/{src/interfaces/make-field-group.ts → dist/src/interfaces/make-field-group.d.ts} +5 -8
  73. package/dist/src/interfaces/make-field-group.js +1 -0
  74. package/{src/interfaces/make-input.ts → dist/src/interfaces/make-input.d.ts} +6 -9
  75. package/dist/src/interfaces/make-input.js +1 -0
  76. package/{src/interfaces/make-select.ts → dist/src/interfaces/make-select.d.ts} +6 -8
  77. package/dist/src/interfaces/make-select.js +1 -0
  78. package/dist/src/interfaces/make-table.d.ts +26 -0
  79. package/dist/src/interfaces/make-table.js +1 -0
  80. package/{src/interfaces/make-textarea.ts → dist/src/interfaces/make-textarea.d.ts} +4 -6
  81. package/dist/src/interfaces/make-textarea.js +1 -0
  82. package/{src/interfaces/make-toggle.ts → dist/src/interfaces/make-toggle.d.ts} +2 -4
  83. package/dist/src/interfaces/make-toggle.js +1 -0
  84. package/dist/src/interfaces/make-upload.d.ts +12 -0
  85. package/dist/src/interfaces/make-upload.js +1 -0
  86. package/{src/interfaces/make-watcher.ts → dist/src/interfaces/make-watcher.d.ts} +3 -5
  87. package/dist/src/interfaces/make-watcher.js +1 -0
  88. package/dist/src/interfaces/modal.d.ts +48 -0
  89. package/dist/src/interfaces/modal.js +1 -0
  90. package/dist/src/interfaces/option.d.ts +4 -0
  91. package/dist/src/interfaces/option.js +1 -0
  92. package/dist/src/interfaces/portal.d.ts +8 -0
  93. package/dist/src/interfaces/portal.js +1 -0
  94. package/dist/src/modal.d.ts +3 -0
  95. package/dist/src/modal.js +135 -0
  96. package/dist/src/util/general/general.util.d.ts +3 -0
  97. package/dist/src/util/general/general.util.js +15 -0
  98. package/dist/util/general/general.util.js +1 -1
  99. package/package.json +20 -2
  100. package/README-ES.md +0 -217
  101. package/eslint.config.mjs +0 -72
  102. package/examples/enable-if.ts +0 -128
  103. package/examples/live-data.ts +0 -61
  104. package/examples/render-if.ts +0 -129
  105. package/examples/simple.ts +0 -75
  106. package/index.ts +0 -5
  107. package/src/components/input-upload/input-upload.tsx +0 -82
  108. package/src/components/make-button/make-button.tsx +0 -25
  109. package/src/components/make-custom-upload/make-custom-upload.tsx +0 -100
  110. package/src/components/make-description/make-description.tsx +0 -21
  111. package/src/components/make-input/make-input.tsx +0 -100
  112. package/src/components/make-select/make-select.tsx +0 -125
  113. package/src/components/make-table/make-table.tsx +0 -201
  114. package/src/components/make-textarea/make-textarea.tsx +0 -100
  115. package/src/components/make-toggle/make-toggle.tsx +0 -100
  116. package/src/components/make-upload/make-upload.tsx +0 -92
  117. package/src/components/make-watcher/make-watcher.tsx +0 -49
  118. package/src/components/portal/portal.tsx +0 -41
  119. package/src/context/component/component-state.tsx +0 -25
  120. package/src/hooks/modal-handler.ts +0 -41
  121. package/src/hooks/use-enable-if.ts +0 -68
  122. package/src/hooks/use-live-data.ts +0 -47
  123. package/src/hooks/use-render-if.ts +0 -69
  124. package/src/interfaces/component-state.ts +0 -55
  125. package/src/interfaces/custom-upload.ts +0 -13
  126. package/src/interfaces/field.ts +0 -43
  127. package/src/interfaces/input-upload.ts +0 -23
  128. package/src/interfaces/make-button.ts +0 -23
  129. package/src/interfaces/make-description.ts +0 -15
  130. package/src/interfaces/make-table.ts +0 -29
  131. package/src/interfaces/make-upload.ts +0 -14
  132. package/src/interfaces/modal.ts +0 -75
  133. package/src/interfaces/option.ts +0 -4
  134. package/src/interfaces/portal.ts +0 -9
  135. package/src/modal.tsx +0 -331
  136. package/src/util/general/general.util.ts +0 -29
  137. package/tsconfig.json +0 -13
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { IMakeTableProps } from '../../interfaces/make-table';
3
+ declare const MakeTable: FC<IMakeTableProps>;
4
+ export default MakeTable;
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
4
+ import useRenderIf from '../../hooks/use-render-if';
5
+ import { ComponentStateContext } from '../../context/component/component-state';
6
+ import useLiveData from '../../hooks/use-live-data';
7
+ import { Controller } from 'react-hook-form';
8
+ const MakeTable = ({ element, watch, control, setValue }) => {
9
+ const [liveSearching, setLiveSearching] = useState(false);
10
+ const [selected, setSelected] = useState('');
11
+ const [rowSelected, setRowSelected] = useState(new Map());
12
+ const { Select } = useContext(ComponentStateContext);
13
+ const { Button } = useContext(ComponentStateContext);
14
+ const { selectTitleName, selectValueName, selectActionName, selectPlaceholder, renderIf, columns, name: elementName, data, liveData: elementLiveData, style, buttonStyle } = element;
15
+ const { checkLiveData, liveData, setLiveData } = useLiveData({
16
+ elementLiveData,
17
+ });
18
+ const { checkRender, render, setRender } = useRenderIf({
19
+ elementRenderIf: renderIf,
20
+ });
21
+ const addToTable = useCallback((selected) => {
22
+ if (selected === '')
23
+ return;
24
+ const elementSelected = data.find((e) => e[selectValueName] === selected);
25
+ if (elementSelected) {
26
+ const currentElements = new Map(rowSelected.entries());
27
+ currentElements.set(selected, elementSelected);
28
+ setValue(elementName, Array.from(currentElements.values()));
29
+ setRowSelected(currentElements);
30
+ setSelected('');
31
+ }
32
+ }, [data, rowSelected, setRowSelected, setSelected]);
33
+ const tableButtonAction = useCallback((row, isDeleteAction, action) => {
34
+ const id = row[selectValueName];
35
+ if (isDeleteAction) {
36
+ const currentElements = new Map(rowSelected.entries());
37
+ currentElements.delete(id);
38
+ setRowSelected(currentElements);
39
+ return;
40
+ }
41
+ if (action)
42
+ action(row);
43
+ }, [rowSelected, setRowSelected]);
44
+ useEffect(() => {
45
+ const { unsubscribe } = watch((formData, { name, type }) => {
46
+ if (!name)
47
+ return;
48
+ if (renderIf) {
49
+ checkRender(formData, { name, type }).then((renderStatus) => {
50
+ if (renderStatus === undefined || renderStatus === null)
51
+ return;
52
+ if (render !== renderStatus) {
53
+ setRender(!!renderStatus);
54
+ }
55
+ });
56
+ }
57
+ if (elementLiveData) {
58
+ setLiveSearching(true);
59
+ checkLiveData(formData, { name, type })
60
+ .then((options) => {
61
+ if (options === undefined || options === null)
62
+ return;
63
+ setLiveData(options);
64
+ })
65
+ .finally(() => {
66
+ setLiveSearching(false);
67
+ });
68
+ }
69
+ });
70
+ return () => unsubscribe();
71
+ }, [watch, render, liveData]);
72
+ if (!render)
73
+ return null;
74
+ const selectOptions = useMemo(() => {
75
+ return data.map((e) => {
76
+ const id = e[selectValueName];
77
+ const name = e[selectTitleName];
78
+ return {
79
+ id,
80
+ name
81
+ };
82
+ });
83
+ }, [data]);
84
+ const keyColumns = useMemo(() => {
85
+ return columns.map((e) => e.title);
86
+ }, [columns]);
87
+ const tableData = useMemo(() => {
88
+ return Array.from(rowSelected.values());
89
+ }, [rowSelected]);
90
+ return (_jsxs("div", { className: 'flex flex-col gap-2', style: { ...style }, children: [_jsxs("div", { className: "flex w-full justify-between gap-4", children: [_jsx(Controller, { control: control, name: elementName, defaultValue: [], render: ({ field: { value } }) => (_jsx("input", { type: 'hidden', value: value })) }), _jsx(Select, { name: 'table-select-field', placeholder: selectPlaceholder, isSearch: true, value: selected, invalid: false, options: liveData || selectOptions, liveSearching: liveSearching, onChange: (selected) => {
91
+ setSelected(selected);
92
+ } }), _jsx(Button, { style: buttonStyle, text: selectActionName, onClick: () => addToTable(selected) })] }), _jsxs("table", { className: "text-[11px] w-full shadow-md sm:rounded-lg", children: [_jsx("thead", { className: "sticky top-0 text-gray-700 bg-gray-50 text-center z-10", children: _jsx("tr", { children: keyColumns.map((title) => (_jsx("th", { scope: 'col', className: 'px-6 py-3', children: title }))) }) }), _jsx("tbody", { children: tableData.map((row, index) => {
93
+ return (_jsx("tr", { className: "bg-white border-b hover:bg-gray-50 text-center", children: columns.map(({ Icon, isButton, action, isDeleteAction, style, ...column }) => {
94
+ if (!isButton)
95
+ return (_jsx("td", { className: 'px-6 py-4', style: style, children: row[column.key] ?? '' }));
96
+ return (_jsx("td", { children: _jsx("button", { className: 'p-2 rounded-md text-lg', onClick: () => { tableButtonAction(row, isDeleteAction, action); }, style: style, children: Icon && _jsx(Icon, {}) }) }));
97
+ }) }, `row-${row[selectValueName]}-i-${index}`));
98
+ }) })] })] }));
99
+ };
100
+ export default MakeTable;
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { IMakeTextareaProps } from '../../interfaces/make-textarea';
3
+ declare const MakeTextarea: FC<IMakeTextareaProps>;
4
+ export default MakeTextarea;
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useContext, useEffect, useId } from 'react';
4
+ import { Controller } from 'react-hook-form';
5
+ import { ComponentStateContext } from '../../context/component/component-state';
6
+ import useEnableIf from '../../hooks/use-enable-if';
7
+ import useRenderIf from '../../hooks/use-render-if';
8
+ const MakeTextarea = ({ element, control, watch, unregister, }) => {
9
+ const { Textarea } = useContext(ComponentStateContext);
10
+ const { name: elementName, validation: { required, message, regex, ...otherValidation }, enableIf, renderIf, ...inputProps } = element;
11
+ const { checkEnable, enable, setEnable } = useEnableIf({
12
+ elementEnableIf: enableIf,
13
+ });
14
+ const { checkRender, render, setRender } = useRenderIf({
15
+ elementRenderIf: renderIf,
16
+ });
17
+ const elementId = useId();
18
+ useEffect(() => {
19
+ const { unsubscribe } = watch((formData, { name, type }) => {
20
+ if (!name)
21
+ return;
22
+ if (enableIf) {
23
+ checkEnable(formData, { name, type }).then((enableStatus) => {
24
+ if (enableStatus === undefined || enableStatus === null)
25
+ return;
26
+ if (enable !== enableStatus)
27
+ setEnable(enableStatus);
28
+ });
29
+ }
30
+ if (renderIf) {
31
+ checkRender(formData, { name, type }).then((renderStatus) => {
32
+ if (renderStatus === undefined || renderStatus === null)
33
+ return;
34
+ if (render !== renderStatus) {
35
+ if (render && !renderStatus)
36
+ unregister(elementName);
37
+ setRender(!!renderStatus);
38
+ }
39
+ });
40
+ }
41
+ });
42
+ return () => unsubscribe();
43
+ }, [watch, render, enable]);
44
+ if (!render)
45
+ return null;
46
+ return (_jsx(Controller, { name: elementName, control: control, rules: {
47
+ required: {
48
+ value: required,
49
+ message: message ?? '',
50
+ },
51
+ pattern: regex
52
+ ? {
53
+ value: regex,
54
+ message: message ?? '',
55
+ }
56
+ : undefined,
57
+ ...otherValidation,
58
+ }, render: ({ field: { onChange, value }, fieldState: { invalid, error }, }) => (_jsx(Textarea, { ...inputProps, id: elementId, name: elementName, onChange: onChange, value: value ?? '', invalid: invalid, error: error, disabled: element.disabled ?? !enable })) }));
59
+ };
60
+ export default MakeTextarea;
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { IMakeToggleProps } from '../../interfaces/make-toggle';
3
+ declare const MakeToggle: FC<IMakeToggleProps>;
4
+ export default MakeToggle;
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useContext, useEffect, useId } from 'react';
4
+ import { Controller } from 'react-hook-form';
5
+ import { ComponentStateContext } from '../../context/component/component-state';
6
+ import useEnableIf from '../../hooks/use-enable-if';
7
+ import useRenderIf from '../../hooks/use-render-if';
8
+ const MakeToggle = ({ element, control, watch, unregister, }) => {
9
+ const { Toggle } = useContext(ComponentStateContext);
10
+ const { name: elementName, validation: { required, message, regex, ...otherValidation }, enableIf, renderIf, ...inputProps } = element;
11
+ const { checkEnable, enable, setEnable } = useEnableIf({
12
+ elementEnableIf: enableIf,
13
+ });
14
+ const { checkRender, render, setRender } = useRenderIf({
15
+ elementRenderIf: renderIf,
16
+ });
17
+ const elementId = useId();
18
+ useEffect(() => {
19
+ const { unsubscribe } = watch((formData, { name, type }) => {
20
+ if (!name)
21
+ return;
22
+ if (enableIf) {
23
+ checkEnable(formData, { name, type }).then((enableStatus) => {
24
+ if (enableStatus === undefined || enableStatus === null)
25
+ return;
26
+ if (enable !== enableStatus)
27
+ setEnable(enableStatus);
28
+ });
29
+ }
30
+ if (renderIf) {
31
+ checkRender(formData, { name, type }).then((renderStatus) => {
32
+ if (renderStatus === undefined || renderStatus === null)
33
+ return;
34
+ if (render !== renderStatus) {
35
+ if (render && !renderStatus)
36
+ unregister(elementName);
37
+ setRender(!!renderStatus);
38
+ }
39
+ });
40
+ }
41
+ });
42
+ return () => unsubscribe();
43
+ }, [watch, render, enable]);
44
+ if (!render)
45
+ return null;
46
+ return (_jsx(Controller, { control: control, name: elementName, rules: {
47
+ required: {
48
+ value: required,
49
+ message: message ?? '',
50
+ },
51
+ pattern: regex
52
+ ? {
53
+ value: regex,
54
+ message: message ?? '',
55
+ }
56
+ : undefined,
57
+ ...otherValidation,
58
+ }, render: ({ field: { onChange, value }, fieldState: { invalid, error }, }) => (_jsx(Toggle, { ...inputProps, id: elementId, name: elementName, onChange: onChange, value: value ?? '', invalid: invalid, error: error, disabled: element.disabled ?? !enable })) }));
59
+ };
60
+ export default MakeToggle;
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { IMakeUploadProps } from '../../interfaces/make-upload';
3
+ declare const MakeUpload: FC<IMakeUploadProps>;
4
+ export default MakeUpload;
@@ -0,0 +1,59 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useId } from 'react';
4
+ import { Controller } from 'react-hook-form';
5
+ import InputUpload from '../input-upload/input-upload';
6
+ import useEnableIf from '../../hooks/use-enable-if';
7
+ import useRenderIf from '../../hooks/use-render-if';
8
+ const MakeUpload = ({ element, control, watch, unregister, }) => {
9
+ const { name: elementName, validation: { required, message, regex, ...otherValidation }, enableIf, renderIf, ...inputProps } = element;
10
+ const { checkEnable, enable, setEnable } = useEnableIf({
11
+ elementEnableIf: enableIf,
12
+ });
13
+ const { checkRender, render, setRender } = useRenderIf({
14
+ elementRenderIf: renderIf,
15
+ });
16
+ const elementId = useId();
17
+ useEffect(() => {
18
+ const { unsubscribe } = watch((formData, { name, type }) => {
19
+ if (!name)
20
+ return;
21
+ if (enableIf) {
22
+ checkEnable(formData, { name, type }).then((enableStatus) => {
23
+ if (enableStatus === undefined || enableStatus === null)
24
+ return;
25
+ if (enable !== enableStatus)
26
+ setEnable(enableStatus);
27
+ });
28
+ }
29
+ if (renderIf) {
30
+ checkRender(formData, { name, type }).then((renderStatus) => {
31
+ if (renderStatus === undefined || renderStatus === null)
32
+ return;
33
+ if (render !== renderStatus) {
34
+ if (render && !renderStatus)
35
+ unregister(elementName);
36
+ setRender(!!renderStatus);
37
+ }
38
+ });
39
+ }
40
+ });
41
+ return () => unsubscribe();
42
+ }, [watch, render, enable]);
43
+ if (!render)
44
+ return null;
45
+ return (_jsx(Controller, { control: control, name: elementName, rules: {
46
+ required: {
47
+ value: required,
48
+ message: message ?? '',
49
+ },
50
+ pattern: regex
51
+ ? {
52
+ value: regex,
53
+ message: message ?? '',
54
+ }
55
+ : undefined,
56
+ ...otherValidation,
57
+ }, render: ({ field: { onChange } }) => (_jsx(InputUpload, { ...inputProps, id: elementId, name: elementName, onChange: onChange, disabled: element.disabled ?? !enable })) }));
58
+ };
59
+ export default MakeUpload;
@@ -0,0 +1,4 @@
1
+ import { FC } from 'react';
2
+ import { IMakeWatcherProps } from '../../interfaces/make-watcher';
3
+ declare const MakeWatcher: FC<IMakeWatcherProps>;
4
+ export default MakeWatcher;
@@ -0,0 +1,28 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useContext, useEffect, useId, useState } from 'react';
4
+ import { ComponentStateContext } from '../../context/component/component-state';
5
+ const MakeWatcher = ({ element, watch }) => {
6
+ const [value, setValue] = useState('');
7
+ const { Input } = useContext(ComponentStateContext);
8
+ const { watchList, style, ...watcherProps } = element;
9
+ const elementId = useId();
10
+ useEffect(() => {
11
+ const { unsubscribe } = watch((formData, { name }) => {
12
+ if (!name)
13
+ return;
14
+ if (watchList.includes(name)) {
15
+ const watchValue = [];
16
+ watchList.forEach((watchName) => {
17
+ const fragment = formData[watchName];
18
+ if (fragment)
19
+ watchValue.push(fragment);
20
+ });
21
+ setValue(watchValue.join(' '));
22
+ }
23
+ });
24
+ return () => unsubscribe();
25
+ }, [watch]);
26
+ return (_jsx(Input, { ...watcherProps, name: `watcher-${elementId}`, id: elementId, value: value ?? '', onChange: () => { }, invalid: false, disabled: true, style: style }));
27
+ };
28
+ export default MakeWatcher;
@@ -0,0 +1,3 @@
1
+ import { FC } from 'react';
2
+ import { IPortal } from '../../interfaces/portal';
3
+ export declare const Portal: FC<IPortal>;
@@ -0,0 +1,28 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useRef, useEffect, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ export const Portal = (props) => {
6
+ const ref = useRef(null);
7
+ const [mounted, setMounted] = useState(false);
8
+ useEffect(() => {
9
+ if (mounted && !props.portalOpen && props.closeTime > 0) {
10
+ const timeoutId = setTimeout(() => {
11
+ setMounted(false);
12
+ ref.current = null;
13
+ }, props.closeTime);
14
+ return () => clearTimeout(timeoutId);
15
+ }
16
+ else if (mounted && !props.portalOpen) {
17
+ setMounted(false);
18
+ ref.current = null;
19
+ }
20
+ else if (!mounted && props.portalOpen) {
21
+ ref.current = document.querySelector(props.portalTag ?? '#portal');
22
+ setMounted(true);
23
+ }
24
+ }, [mounted, props.closeTime, props.portalOpen, props.portalTag]);
25
+ if (!mounted && !ref.current)
26
+ return null;
27
+ return createPortal(_jsx("div", { className: `transition-all delay-100 fixed top-0 left-0 w-full h-full grid place-items-center bg-black bg-opacity-40 z-20 ${props.useBlur && 'backdrop-blur-sm'}`, children: props.children }), ref.current);
28
+ };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { IComponentState, IComponentStateProps } from '../../interfaces/component-state';
3
+ export declare const ComponentStateContext: React.Context<IComponentState>;
4
+ export declare const ComponentState: ({ children, components, }: IComponentStateProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useMemo, createContext } from 'react';
4
+ export const ComponentStateContext = createContext({});
5
+ export const ComponentState = ({ children, components, }) => {
6
+ const value = useMemo(() => components, [components]);
7
+ return (_jsx(ComponentStateContext.Provider, { value: value, children: children }));
8
+ };
@@ -0,0 +1,7 @@
1
+ import { IModal, IModalConfigProps } from '../interfaces/modal';
2
+ interface IModalHandler {
3
+ openModal: (config: IModalConfigProps) => void;
4
+ modalProps: IModal;
5
+ }
6
+ export declare function useModalHandler(): IModalHandler;
7
+ export {};
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ export function useModalHandler() {
4
+ const initialState = {
5
+ modalProps: {
6
+ config: {},
7
+ close: () => { },
8
+ open: false,
9
+ },
10
+ openModal: () => { },
11
+ };
12
+ const [modalConfig, setModalConfig] = useState(initialState);
13
+ const openModal = (config) => {
14
+ if (!config) {
15
+ alert(`¡WARNING! this modal was not returned config, please check before use`);
16
+ return;
17
+ }
18
+ setModalConfig({ openModal, modalProps: { config, open: true, close } });
19
+ };
20
+ const closeModal = () => setModalConfig(initialState);
21
+ return {
22
+ openModal,
23
+ modalProps: { ...modalConfig.modalProps, close: closeModal },
24
+ };
25
+ }
@@ -0,0 +1,10 @@
1
+ import { IModalRenderCondition } from '../interfaces/modal';
2
+ export interface IRenderIfProps {
3
+ elementEnableIf?: IModalRenderCondition;
4
+ }
5
+ declare const useEnableIf: ({ elementEnableIf }: IRenderIfProps) => {
6
+ enable: boolean;
7
+ checkEnable: (formData: Record<string, unknown>, { name }: Record<"name", string> & Record<"type", string | undefined>) => Promise<boolean | undefined>;
8
+ setEnable: import("react").Dispatch<import("react").SetStateAction<boolean>>;
9
+ };
10
+ export default useEnableIf;
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import { liveDataHandler } from '../util/general/general.util';
4
+ const useEnableIf = ({ elementEnableIf }) => {
5
+ const [enable, setEnable] = useState(() => {
6
+ return elementEnableIf === undefined;
7
+ });
8
+ const checkEnable = async (formData, { name }) => {
9
+ const targetFieldData = formData[name];
10
+ // if (
11
+ // targetFieldData === undefined ||
12
+ // targetFieldData === '' ||
13
+ // targetFieldData === null
14
+ // )
15
+ // return false;
16
+ const enableIfConfig = elementEnableIf;
17
+ const isLiveEnable = !!enableIfConfig?.action && !!enableIfConfig.condition;
18
+ if (isLiveEnable && enableIfConfig.condition.includes(name)) {
19
+ const enableStatus = await liveDataHandler(targetFieldData, formData, enableIfConfig.action);
20
+ return enableStatus;
21
+ }
22
+ else {
23
+ const enableConditionList = Object.keys(elementEnableIf);
24
+ if (enableConditionList.includes(name)) {
25
+ const enableStatus = enableIfConfig[name].includes(targetFieldData) || enableIfConfig[name].includes('*');
26
+ return enableStatus;
27
+ }
28
+ }
29
+ };
30
+ return {
31
+ enable,
32
+ checkEnable,
33
+ setEnable,
34
+ };
35
+ };
36
+ export default useEnableIf;
@@ -0,0 +1,11 @@
1
+ import { IModalLiveDataCondition } from '../interfaces/modal';
2
+ import { IOption } from '../interfaces/option';
3
+ export interface ILiveDataProps {
4
+ elementLiveData?: IModalLiveDataCondition;
5
+ }
6
+ declare const useLiveData: ({ elementLiveData }: ILiveDataProps) => {
7
+ liveData: IOption[] | undefined;
8
+ checkLiveData: (formData: Record<string, unknown>, { name }: Record<"name", string> & Record<"type", string | undefined>) => Promise<IOption[] | null>;
9
+ setLiveData: import("react").Dispatch<import("react").SetStateAction<IOption[] | undefined>>;
10
+ };
11
+ export default useLiveData;
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import { liveDataAction } from '../util/general/general.util';
4
+ const useLiveData = ({ elementLiveData }) => {
5
+ const [liveData, setLiveData] = useState(undefined);
6
+ const checkLiveData = async (formData, { name }) => {
7
+ const targetFieldData = formData[name];
8
+ const liveDataConfig = elementLiveData;
9
+ const isLiveData = !!liveDataConfig?.action && !!liveDataConfig.condition;
10
+ if (!isLiveData)
11
+ return null;
12
+ if (liveDataConfig.condition.includes(name)) {
13
+ return await liveDataAction(targetFieldData, formData, liveDataConfig.action);
14
+ }
15
+ return null;
16
+ };
17
+ return {
18
+ liveData,
19
+ checkLiveData,
20
+ setLiveData,
21
+ };
22
+ };
23
+ export default useLiveData;
@@ -0,0 +1,10 @@
1
+ import { IModalRenderCondition } from '../interfaces/modal';
2
+ export interface IRenderIfProps {
3
+ elementRenderIf?: IModalRenderCondition;
4
+ }
5
+ declare const useRenderIf: ({ elementRenderIf }: IRenderIfProps) => {
6
+ render: boolean;
7
+ checkRender: (formData: Record<string, unknown>, { name }: Record<"name", string> & Record<"type", string | undefined>) => Promise<boolean | undefined>;
8
+ setRender: import("react").Dispatch<import("react").SetStateAction<boolean>>;
9
+ };
10
+ export default useRenderIf;
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import { liveDataHandler } from '../util/general/general.util';
4
+ const useRenderIf = ({ elementRenderIf }) => {
5
+ const [render, setRender] = useState(() => {
6
+ return elementRenderIf === undefined;
7
+ });
8
+ const checkRender = async (formData, { name }) => {
9
+ const targetFieldData = formData[name];
10
+ // if (
11
+ // targetFieldData === undefined ||
12
+ // targetFieldData === '' ||
13
+ // targetFieldData === null
14
+ // )
15
+ // return false;
16
+ const renderIfConfig = elementRenderIf;
17
+ const isLiveRender = !!renderIfConfig?.action && !!renderIfConfig?.condition;
18
+ if (isLiveRender && renderIfConfig.condition.includes(name)) {
19
+ const renderStatus = await liveDataHandler(targetFieldData, formData, renderIfConfig.action);
20
+ return renderStatus;
21
+ }
22
+ else {
23
+ const renderConditionList = Object.keys(elementRenderIf);
24
+ if (renderConditionList.includes(name)) {
25
+ const renderStatus = renderIfConfig[name].includes(targetFieldData) || renderIfConfig[name].includes('*');
26
+ return renderStatus;
27
+ }
28
+ }
29
+ };
30
+ return {
31
+ render,
32
+ checkRender,
33
+ setRender,
34
+ };
35
+ };
36
+ export default useRenderIf;
@@ -0,0 +1,29 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+ import { FieldError } from 'react-hook-form';
3
+ import { IOption } from './option';
4
+ import { IMakeInput } from './make-input';
5
+ import { IMakeButton } from './make-button';
6
+ import { IMakeSelect } from './make-select';
7
+ import { IMakeTextarea } from './make-textarea';
8
+ import { IMakeToggle } from './make-toggle';
9
+ import { IMakeCustomUpload } from './make-custom-upload';
10
+ export interface IComponentAditionalProps {
11
+ onChange: (...event: any[]) => void;
12
+ value: any;
13
+ invalid: boolean;
14
+ error?: FieldError;
15
+ liveSearching?: boolean;
16
+ }
17
+ export interface IComponentState {
18
+ ModalButtonCancel: FC<Omit<IMakeButton, 'elementType'>>;
19
+ ModalButtonAction: FC<Omit<IMakeButton, 'elementType'>>;
20
+ Button: FC<Omit<IMakeButton, 'elementType'>>;
21
+ Input: FC<Omit<IMakeInput, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
22
+ CustomUpload: FC<Omit<IMakeCustomUpload, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
23
+ Select: FC<Omit<IMakeSelect, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps & Record<'options', Array<IOption>>>;
24
+ Textarea: FC<Omit<IMakeTextarea, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
25
+ Toggle: FC<Omit<IMakeToggle, 'elementType' | 'validation' | 'renderIf' | 'enableIf'> & IComponentAditionalProps>;
26
+ }
27
+ export interface IComponentStateProps extends PropsWithChildren {
28
+ components: IComponentState;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { ChangeEvent, CSSProperties } from 'react';
2
+ export interface ICustomUpload {
3
+ id?: string;
4
+ value?: string;
5
+ onChange: (event: ChangeEvent<HTMLInputElement>) => void;
6
+ accept?: string;
7
+ label?: string;
8
+ helpText?: string;
9
+ style?: CSSProperties;
10
+ name: string;
11
+ disabled?: boolean;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { CSSProperties } from 'react';
2
+ import { Control, FieldValues, UseFormSetValue, UseFormUnregister, UseFormWatch } from 'react-hook-form';
3
+ import { IModalRenderCondition } from './modal';
4
+ export interface IValidationBase<T> {
5
+ value: T;
6
+ message: string;
7
+ }
8
+ export interface IField {
9
+ name: string;
10
+ id?: string;
11
+ label?: string;
12
+ style?: CSSProperties;
13
+ placeholder?: string;
14
+ defaultValue?: any;
15
+ renderIf?: IModalRenderCondition;
16
+ enableIf?: IModalRenderCondition;
17
+ validation: {
18
+ required: boolean;
19
+ regex?: RegExp;
20
+ message?: string;
21
+ maxLength?: IValidationBase<number>;
22
+ minLength?: IValidationBase<number>;
23
+ min?: IValidationBase<number | string>;
24
+ max?: IValidationBase<number | string>;
25
+ };
26
+ disabled?: boolean;
27
+ }
28
+ export interface IFieldProps {
29
+ control: Control<FieldValues, unknown>;
30
+ watch: UseFormWatch<FieldValues>;
31
+ setValue: UseFormSetValue<FieldValues>;
32
+ unregister: UseFormUnregister<FieldValues>;
33
+ }
@@ -0,0 +1 @@
1
+ export {};