dynamic-modal 1.0.12 → 1.1.1
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-ES.md +109 -11
- package/README.md +110 -13
- package/dist/components/input-upload/input-upload.js +8 -42
- package/dist/components/make-button/make-button.js +41 -18
- package/dist/components/make-description/make-description.d.ts +4 -0
- package/dist/components/make-description/make-description.js +13 -0
- package/dist/components/make-input/make-input.d.ts +1 -1
- package/dist/components/make-input/make-input.js +12 -6
- package/dist/components/make-select/make-select.js +12 -6
- package/dist/components/make-textarea/make-textarea.js +12 -6
- package/dist/components/make-toggle/make-toggle.js +12 -9
- package/dist/components/make-upload/make-upload.js +8 -7
- package/dist/context/component/component-state.d.ts +4 -0
- package/dist/context/component/component-state.js +45 -0
- package/dist/interfaces/component-state.d.ts +27 -0
- package/dist/interfaces/field.d.ts +3 -2
- package/dist/interfaces/input-upload.d.ts +1 -1
- package/dist/interfaces/make-button.d.ts +5 -6
- package/dist/interfaces/make-description.d.ts +12 -0
- package/dist/interfaces/make-field-group.d.ts +1 -0
- package/dist/interfaces/{make-field.d.ts → make-input.d.ts} +2 -2
- package/dist/interfaces/make-select.d.ts +3 -1
- package/dist/interfaces/make-textarea.d.ts +1 -1
- package/dist/interfaces/make-toggle.d.ts +1 -1
- package/dist/interfaces/make-upload.d.ts +1 -1
- package/dist/interfaces/modal.d.ts +14 -19
- package/dist/modal.js +42 -35
- package/dist/tools/general.js +1 -0
- package/examples/enable-if.ts +5 -7
- package/examples/live-data.ts +7 -9
- package/examples/render-if.ts +6 -8
- package/examples/simple.ts +6 -8
- package/index.ts +4 -2
- package/package.json +16 -17
- package/src/components/input-upload/input-upload.tsx +7 -12
- package/src/components/make-button/make-button.tsx +11 -10
- package/src/components/make-description/make-description.tsx +15 -0
- package/src/components/make-input/make-input.tsx +25 -19
- package/src/components/make-select/make-select.tsx +23 -22
- package/src/components/make-textarea/make-textarea.tsx +18 -13
- package/src/components/make-toggle/make-toggle.tsx +24 -15
- package/src/components/make-upload/make-upload.tsx +12 -6
- package/src/components/portal/portal.tsx +1 -0
- package/src/context/component/component-state.tsx +18 -0
- package/src/hooks/field-render.ts +1 -0
- package/src/hooks/modal-handler.ts +1 -0
- package/src/interfaces/component-state.ts +33 -0
- package/src/interfaces/field.ts +8 -7
- package/src/interfaces/input-upload.ts +11 -11
- package/src/interfaces/make-button.ts +10 -11
- package/src/interfaces/make-description.ts +14 -0
- package/src/interfaces/make-field-group.ts +5 -4
- package/src/interfaces/{make-field.ts → make-input.ts} +2 -2
- package/src/interfaces/make-select.ts +3 -1
- package/src/interfaces/make-textarea.ts +1 -1
- package/src/interfaces/make-toggle.ts +2 -2
- package/src/interfaces/make-upload.ts +7 -7
- package/src/interfaces/modal.ts +15 -21
- package/src/interfaces/option.ts +2 -2
- package/src/interfaces/portal.ts +4 -4
- package/src/modal.tsx +43 -53
- package/src/tools/general.ts +2 -0
- package/.idea/dynamic-modal.iml +0 -12
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/components/make-autocomplete/make-autocomplete.d.ts +0 -4
- package/dist/components/make-autocomplete/make-autocomplete.js +0 -70
- package/dist/components/make-multi-select/make-multi-select.d.ts +0 -4
- package/dist/components/make-multi-select/make-multi-select.js +0 -70
- package/dist/components/make-text/make-text.d.ts +0 -4
- package/dist/components/make-text/make-text.js +0 -11
- package/dist/components/make-title/make-title.d.ts +0 -4
- package/dist/components/make-title/make-title.js +0 -10
- package/dist/interfaces/make-autocomplete.d.ts +0 -11
- package/dist/interfaces/make-multi-select.d.ts +0 -12
- package/dist/interfaces/make-text.d.ts +0 -10
- package/dist/interfaces/make-text.js +0 -2
- package/dist/interfaces/make-title.d.ts +0 -3
- package/dist/interfaces/make-title.js +0 -2
- package/src/components/make-autocomplete/make-autocomplete.tsx +0 -54
- package/src/components/make-multi-select/make-multi-select.tsx +0 -56
- package/src/components/make-text/make-text.tsx +0 -16
- package/src/components/make-title/make-title.tsx +0 -12
- package/src/interfaces/make-autocomplete.ts +0 -13
- package/src/interfaces/make-multi-select.ts +0 -14
- package/src/interfaces/make-text.ts +0 -12
- package/src/interfaces/make-title.ts +0 -3
- /package/dist/interfaces/{make-autocomplete.js → component-state.js} +0 -0
- /package/dist/interfaces/{make-field.js → make-description.js} +0 -0
- /package/dist/interfaces/{make-multi-select.js → make-input.js} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { IField, IFieldProps } from './field'
|
|
2
2
|
|
|
3
3
|
export interface IMakeUpload extends Omit<IField, 'defaultValue'> {
|
|
4
|
-
elementType: 'upload'
|
|
5
|
-
helpText?: string
|
|
6
|
-
read: boolean
|
|
7
|
-
image?: boolean
|
|
8
|
-
accept?:string
|
|
9
|
-
readAsArrayBuffer?: boolean
|
|
4
|
+
elementType: 'upload'
|
|
5
|
+
helpText?: string
|
|
6
|
+
read: boolean
|
|
7
|
+
image?: boolean
|
|
8
|
+
accept?:string
|
|
9
|
+
readAsArrayBuffer?: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface IMakeUploadProps extends IFieldProps {
|
|
13
|
-
element: IMakeUpload
|
|
13
|
+
element: Omit<IMakeUpload, 'elementType'>
|
|
14
14
|
}
|
package/src/interfaces/modal.ts
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { CSSProperties } from 'react'
|
|
3
3
|
import { IMakeSelect } from './make-select'
|
|
4
|
-
import { IMakeInput } from './make-
|
|
4
|
+
import { IMakeInput } from './make-input'
|
|
5
5
|
import { IMakeTextarea } from './make-textarea'
|
|
6
6
|
import { IMakeToggle } from './make-toggle'
|
|
7
|
-
import {
|
|
8
|
-
import { IMakeText } from './make-text'
|
|
7
|
+
import { IMakeDescription } from './make-description'
|
|
9
8
|
import { IMakeFieldGroup } from './make-field-group'
|
|
10
9
|
import { IMakeUpload } from './make-upload'
|
|
11
10
|
import { IOption } from './option'
|
|
12
11
|
import { IMakeButton } from './make-button'
|
|
13
|
-
import { IMakeAutoComplete } from './make-autocomplete'
|
|
14
12
|
|
|
15
|
-
export type IModalField = IMakeSelect | IMakeInput | IMakeFieldGroup | IMakeTextarea | IMakeToggle |
|
|
13
|
+
export type IModalField = IMakeSelect | IMakeInput | IMakeFieldGroup | IMakeTextarea | IMakeToggle | IMakeDescription | IMakeUpload | IMakeButton
|
|
16
14
|
|
|
17
|
-
export type IFormField = IMakeSelect | IMakeInput | IMakeTextarea | IMakeToggle
|
|
15
|
+
export type IFormField = IMakeSelect | IMakeInput | IMakeTextarea | IMakeToggle
|
|
18
16
|
|
|
19
17
|
export type IModalRenderCondition = Record<string, Array<string | number>>
|
|
20
18
|
|
|
21
19
|
export type IModalLiveDataCondition = {
|
|
22
|
-
action: (data: string, ...args: any[]) => Promise<Array<IOption
|
|
20
|
+
action: (data: string, ...args: any[]) => Promise<Array<IOption>>
|
|
23
21
|
condition: Array<string>
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
export interface IModalConfigProps {
|
|
27
|
-
fields: Array<IModalField>
|
|
28
|
-
title: string
|
|
29
|
-
action: {
|
|
30
|
-
name: string
|
|
31
|
-
action?: (data: any) => void
|
|
32
|
-
hide?: boolean
|
|
33
|
-
}
|
|
34
|
-
cancel?: {
|
|
35
|
-
name?: string;
|
|
36
|
-
action?: () => void
|
|
37
|
-
hide?: boolean;
|
|
38
|
-
}
|
|
39
24
|
reservedData?: Record<string, any>
|
|
40
|
-
|
|
25
|
+
title: string
|
|
26
|
+
fields: Array<IModalField>
|
|
27
|
+
out: (data: any) => void
|
|
28
|
+
onClose?: () => void
|
|
29
|
+
style?: CSSProperties;
|
|
41
30
|
overFlowBody?: string | number
|
|
42
31
|
minHeightBody?: string | number
|
|
32
|
+
actions: {
|
|
33
|
+
containerStyle?: CSSProperties
|
|
34
|
+
cancel?: Omit<IMakeButton, 'elementType'>
|
|
35
|
+
action: Omit<IMakeButton, 'elementType'>
|
|
36
|
+
}
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
export type IModalConfigLoader<T = any, D = any> = (props: T, action: (modalResult: D) => void) => IModalConfigProps
|
package/src/interfaces/option.ts
CHANGED
package/src/interfaces/portal.ts
CHANGED
package/src/modal.tsx
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import React, { useContext, useEffect, useState } from 'react'
|
|
3
4
|
import { useForm } from 'react-hook-form'
|
|
4
|
-
import { Button } from '@nextui-org/react'
|
|
5
5
|
import { Portal } from './components/portal/portal'
|
|
6
6
|
import MakeToggle from './components/make-toggle/make-toggle'
|
|
7
7
|
import MakeInput from './components/make-input/make-input'
|
|
8
8
|
import MakeSelect from './components/make-select/make-select'
|
|
9
9
|
import MakeTextarea from './components/make-textarea/make-textarea'
|
|
10
10
|
import { IModal, IModalField, IModalConfigProps, IFormField } from './interfaces/modal'
|
|
11
|
-
import
|
|
12
|
-
import MakeText from './components/make-text/make-text'
|
|
11
|
+
import MakeDescription from './components/make-description/make-description'
|
|
13
12
|
import { IFieldProps } from './interfaces/field'
|
|
14
13
|
import MakeUpload from './components/make-upload/make-upload'
|
|
15
14
|
import MakeButton from './components/make-button/make-button'
|
|
16
|
-
import
|
|
15
|
+
import { IMakeInput } from './interfaces/make-input'
|
|
16
|
+
import { IMakeSelect } from './interfaces/make-select'
|
|
17
|
+
import { IMakeTextarea } from './interfaces/make-textarea'
|
|
18
|
+
import { IMakeToggle } from './interfaces/make-toggle'
|
|
19
|
+
import { IMakeDescription } from './interfaces/make-description'
|
|
20
|
+
import { IMakeUpload } from './interfaces/make-upload'
|
|
21
|
+
import { IMakeButton } from './interfaces/make-button'
|
|
22
|
+
import { ComponentStateContext } from './context/component/component-state'
|
|
17
23
|
|
|
18
24
|
export const Modal = ({ open, close, config }: IModal) => {
|
|
25
|
+
const { ModalButtonAction, ModalButtonCancel } = useContext(ComponentStateContext)
|
|
19
26
|
const [modalReady, setModalReady] = useState<IModalConfigProps | undefined>(undefined)
|
|
20
27
|
const [defaultLoaded, setDefaultLoaded] = useState<boolean>(false)
|
|
21
28
|
|
|
@@ -60,7 +67,7 @@ export const Modal = ({ open, close, config }: IModal) => {
|
|
|
60
67
|
setDefaultLoaded(true)
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
const getRender = (element: IModalField, index: number, isEndOfRender: boolean = false) => {
|
|
70
|
+
const getRender = ({ elementType, ...element }: IModalField, index: number, isEndOfRender: boolean = false) => {
|
|
64
71
|
if (isEndOfRender && modalReady) setTimeout(() => autoLoadField(modalReady.fields), 200)
|
|
65
72
|
|
|
66
73
|
const props: IFieldProps = {
|
|
@@ -70,29 +77,26 @@ export const Modal = ({ open, close, config }: IModal) => {
|
|
|
70
77
|
unregister
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
return
|
|
74
|
-
? <MakeInput {...props} key={`modal-input-${index}`} element={element} />
|
|
75
|
-
:
|
|
76
|
-
? <MakeSelect {...props} key={`modal-select-${index}`} element={element} />
|
|
77
|
-
:
|
|
78
|
-
? <MakeTextarea {...props} key={`modal-textarea-${index}`} element={element} />
|
|
79
|
-
:
|
|
80
|
-
? <MakeToggle {...props} key={`modal-toggle-${index}`} element={element} />
|
|
81
|
-
:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
? <MakeButton {...props} key={`modal-button-${index}`} element={element} />
|
|
89
|
-
: element.elementType === 'autocomplete'
|
|
90
|
-
? <MakeAutocomplete {...props} key={`modal-autocomplete-${index}`} element={element} />
|
|
91
|
-
: null
|
|
80
|
+
return elementType === 'input'
|
|
81
|
+
? <MakeInput {...props} key={`modal-input-${index}`} element={element as IMakeInput} />
|
|
82
|
+
: elementType === 'select'
|
|
83
|
+
? <MakeSelect {...props} key={`modal-select-${index}`} element={element as IMakeSelect} />
|
|
84
|
+
: elementType === 'textarea'
|
|
85
|
+
? <MakeTextarea {...props} key={`modal-textarea-${index}`} element={element as IMakeTextarea} />
|
|
86
|
+
: elementType === 'toggle'
|
|
87
|
+
? <MakeToggle {...props} key={`modal-toggle-${index}`} element={element as IMakeToggle} />
|
|
88
|
+
: elementType === 'text'
|
|
89
|
+
? <MakeDescription {...props} key={`modal-text-${index}`} element={element as IMakeDescription} />
|
|
90
|
+
: elementType === 'upload'
|
|
91
|
+
? <MakeUpload {...props} key={`modal-upload-${index}`} element={element as IMakeUpload} />
|
|
92
|
+
: elementType === 'button'
|
|
93
|
+
? <MakeButton {...props} key={`modal-button-${index}`} element={element as IMakeButton} />
|
|
94
|
+
: null
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
const closeHandler = (): void => {
|
|
95
|
-
if (modalReady?.
|
|
98
|
+
if (modalReady?.onClose) modalReady.onClose()
|
|
99
|
+
|
|
96
100
|
setTimeout(() => {
|
|
97
101
|
const form = getValues()
|
|
98
102
|
unregister(Object.keys(form))
|
|
@@ -103,7 +107,7 @@ export const Modal = ({ open, close, config }: IModal) => {
|
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
const actionHandler = (data: Record<string, string | number | object>): void => {
|
|
106
|
-
|
|
110
|
+
modalReady?.out({ ...(modalReady?.reservedData ?? {}), ...data })
|
|
107
111
|
closeHandler()
|
|
108
112
|
}
|
|
109
113
|
|
|
@@ -114,11 +118,11 @@ export const Modal = ({ open, close, config }: IModal) => {
|
|
|
114
118
|
return (
|
|
115
119
|
modalReady
|
|
116
120
|
? <Portal closeTime={200} portalOpen={open} portalTag={'#modal-portal'}>
|
|
117
|
-
<div className='rounded bg-white relative w-auto h-auto min-h-[200px] min-w-[500px]' style={
|
|
121
|
+
<div className='rounded bg-white relative w-auto h-auto min-h-[200px] min-w-[500px]' style={modalReady.style} >
|
|
118
122
|
<form className='flex flex-col p-4 gap-4' autoComplete='off' onSubmit={handleSubmit(actionHandler)}>
|
|
119
123
|
<h2 className='text-bold text-center border-b pb-4 font-semibold'>{modalReady.title}</h2>
|
|
120
124
|
<div
|
|
121
|
-
className='flex flex-col
|
|
125
|
+
className='flex flex-col gap-4 py-4'
|
|
122
126
|
style={{
|
|
123
127
|
overflowY: modalReady.overFlowBody ? 'auto' : undefined,
|
|
124
128
|
height: modalReady.overFlowBody,
|
|
@@ -131,38 +135,24 @@ export const Modal = ({ open, close, config }: IModal) => {
|
|
|
131
135
|
|
|
132
136
|
if (element.elementType === 'group') {
|
|
133
137
|
return (
|
|
134
|
-
<div key={`modal-group-${index}`} className='flex
|
|
135
|
-
{
|
|
136
|
-
|
|
138
|
+
<div key={`modal-group-${index}`} className='flex flex-col w-full gap-2'>
|
|
139
|
+
{ element.title && <h3 className='font-bold border-b-2 pb-2 mb-2'>{element.title}</h3> }
|
|
140
|
+
<div key={`modal-group-${index}`} className='flex gap-4 w-full' style={element.style}>
|
|
141
|
+
{
|
|
142
|
+
element.groups
|
|
137
143
|
.filter(sub => ['input', 'select', 'toggle', 'multiselect', 'upload', 'button', 'autocomplete'].includes(sub.elementType))
|
|
138
144
|
.map((sub, subIndex) => getRender(sub, index + subIndex, isEndOfRender))
|
|
139
|
-
|
|
145
|
+
}
|
|
146
|
+
</div>
|
|
140
147
|
</div>
|
|
141
148
|
)
|
|
142
149
|
} else { return getRender(element, index, isEndOfRender) }
|
|
143
150
|
})
|
|
144
151
|
}
|
|
145
152
|
</div>
|
|
146
|
-
<div className='flex items-center justify-
|
|
147
|
-
{modalReady.cancel &&
|
|
148
|
-
|
|
149
|
-
variant='bordered'
|
|
150
|
-
onClick={closeHandler}
|
|
151
|
-
type='reset'
|
|
152
|
-
className='w-[140px]'
|
|
153
|
-
>
|
|
154
|
-
{modalReady.cancel.name ?? 'Close'}
|
|
155
|
-
</Button>
|
|
156
|
-
}
|
|
157
|
-
{modalReady.action &&
|
|
158
|
-
<Button
|
|
159
|
-
color='primary'
|
|
160
|
-
type='submit'
|
|
161
|
-
className='w-[140px]'
|
|
162
|
-
>
|
|
163
|
-
{modalReady.action.name ?? 'Ok'}
|
|
164
|
-
</Button>
|
|
165
|
-
}
|
|
153
|
+
<div className='flex gap-4 items-center justify-center border-t' style={modalReady?.actions.containerStyle}>
|
|
154
|
+
{modalReady.actions.cancel && <ModalButtonCancel {...modalReady.actions.cancel} onClick={closeHandler} />}
|
|
155
|
+
<ModalButtonAction {...modalReady.actions.action} type='submit' />
|
|
166
156
|
</div>
|
|
167
157
|
</form>
|
|
168
158
|
</div>
|
package/src/tools/general.ts
CHANGED
package/.idea/dynamic-modal.iml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/dynamic-modal.iml" filepath="$PROJECT_DIR$/.idea/dynamic-modal.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/vcs.xml
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
|
-
var t = {};
|
|
37
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
-
t[p] = s[p];
|
|
39
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
-
t[p[i]] = s[p[i]];
|
|
43
|
-
}
|
|
44
|
-
return t;
|
|
45
|
-
};
|
|
46
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
const react_1 = __importStar(require("react"));
|
|
48
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
49
|
-
const field_render_1 = require("../../hooks/field-render");
|
|
50
|
-
const general_1 = require("../../tools/general");
|
|
51
|
-
const react_2 = require("@nextui-org/react");
|
|
52
|
-
const MakeAutocomplete = (_a) => {
|
|
53
|
-
var _b, _c;
|
|
54
|
-
var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), element = __rest(_d, ["validation"]), props = __rest(_a, ["element"]);
|
|
55
|
-
const { render, enable, checkField, liveData, liveSearching } = (0, field_render_1.useFieldRender)(Object.assign(Object.assign({}, props), { element }));
|
|
56
|
-
(0, react_1.useEffect)(() => {
|
|
57
|
-
const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }));
|
|
58
|
-
return () => subscription.unsubscribe();
|
|
59
|
-
}, [checkField, props, props.watch]);
|
|
60
|
-
return (render
|
|
61
|
-
? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: Object.assign({ required, pattern: {
|
|
62
|
-
value: (_b = validation.regex) !== null && _b !== void 0 ? _b : /(.*)/,
|
|
63
|
-
message: (_c = validation.message) !== null && _c !== void 0 ? _c : ''
|
|
64
|
-
} }, validation), render: ({ field: { onChange, value }, fieldState: { invalid } }) => {
|
|
65
|
-
var _a, _b, _c, _d;
|
|
66
|
-
return (react_1.default.createElement(react_2.Autocomplete, Object.assign({ size: 'sm' }, element, { isDisabled: (_a = element.disabled) !== null && _a !== void 0 ? _a : !enable, id: (_b = element.id) !== null && _b !== void 0 ? _b : (0, general_1.generateId)(), onSelectionChange: onChange, label: liveSearching ? 'Loading...' : element.label, selectedKey: value, color: invalid ? 'danger' : undefined, isInvalid: invalid, errorMessage: invalid ? ((_c = validation.message) !== null && _c !== void 0 ? _c : '') : undefined }), (liveData || ((_d = element.options) !== null && _d !== void 0 ? _d : [])).map((opt) => (react_1.default.createElement(react_2.AutocompleteItem, { key: opt.id, value: opt.id }, opt.name)))));
|
|
67
|
-
} })
|
|
68
|
-
: react_1.default.createElement(react_1.default.Fragment, null));
|
|
69
|
-
};
|
|
70
|
-
exports.default = MakeAutocomplete;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
|
-
var t = {};
|
|
37
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
-
t[p] = s[p];
|
|
39
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
-
t[p[i]] = s[p[i]];
|
|
43
|
-
}
|
|
44
|
-
return t;
|
|
45
|
-
};
|
|
46
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
const react_1 = __importStar(require("react"));
|
|
48
|
-
const react_hook_form_1 = require("react-hook-form");
|
|
49
|
-
const field_render_1 = require("../../hooks/field-render");
|
|
50
|
-
const general_1 = require("../../tools/general");
|
|
51
|
-
const react_2 = require("@nextui-org/react");
|
|
52
|
-
const MakeMultiSelect = (_a) => {
|
|
53
|
-
var _b, _c;
|
|
54
|
-
var _d = _a.element, _e = _d.validation, { required } = _e, validation = __rest(_e, ["required"]), element = __rest(_d, ["validation"]), props = __rest(_a, ["element"]);
|
|
55
|
-
const { render, enable, checkField, liveData, liveSearching } = (0, field_render_1.useFieldRender)(Object.assign(Object.assign({}, props), { element }));
|
|
56
|
-
(0, react_1.useEffect)(() => {
|
|
57
|
-
const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }));
|
|
58
|
-
return () => subscription.unsubscribe();
|
|
59
|
-
}, [checkField, props, props.watch]);
|
|
60
|
-
return (render
|
|
61
|
-
? react_1.default.createElement(react_hook_form_1.Controller, { control: props.control, name: element.name, rules: Object.assign({ required, pattern: {
|
|
62
|
-
value: (_b = validation.regex) !== null && _b !== void 0 ? _b : /(.*)/,
|
|
63
|
-
message: (_c = validation.message) !== null && _c !== void 0 ? _c : ''
|
|
64
|
-
} }, validation), render: ({ field: { onChange, value }, fieldState: { invalid } }) => {
|
|
65
|
-
var _a, _b, _c, _d;
|
|
66
|
-
return (react_1.default.createElement(react_2.Select, Object.assign({ size: 'sm' }, element, { id: (_a = element.id) !== null && _a !== void 0 ? _a : (0, general_1.generateId)(), onSelectionChange: onChange, label: liveSearching ? 'Loading...' : element.label, selectionMode: "multiple", selectedKeys: value, color: invalid ? 'danger' : undefined, isInvalid: invalid, errorMessage: invalid ? ((_b = validation.message) !== null && _b !== void 0 ? _b : '') : undefined, disabled: (_c = element.disabled) !== null && _c !== void 0 ? _c : !enable, className: 'max-w-lg' }), (liveData || ((_d = element.options) !== null && _d !== void 0 ? _d : [])).map((opt) => (react_1.default.createElement(react_2.SelectItem, { key: opt.id, value: opt.id }, opt.name)))));
|
|
67
|
-
} })
|
|
68
|
-
: null);
|
|
69
|
-
};
|
|
70
|
-
exports.default = MakeMultiSelect;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const MakeText = ({ element }) => {
|
|
8
|
-
return (react_1.default.createElement("div", { className: 'text-xs text-center' },
|
|
9
|
-
react_1.default.createElement("p", { style: element.styles }, element.text)));
|
|
10
|
-
};
|
|
11
|
-
exports.default = MakeText;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const MakeTitle = ({ title }) => {
|
|
8
|
-
return (react_1.default.createElement("div", { className: 'flex text-center items-center justify-center text-xl' }, title));
|
|
9
|
-
};
|
|
10
|
-
exports.default = MakeTitle;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IField, IFieldProps } from './field';
|
|
2
|
-
import { IModalLiveDataCondition } from './modal';
|
|
3
|
-
import { IOption } from './option';
|
|
4
|
-
export interface IMakeAutoComplete extends IField {
|
|
5
|
-
elementType: 'autocomplete';
|
|
6
|
-
options: Array<IOption>;
|
|
7
|
-
liveData?: IModalLiveDataCondition;
|
|
8
|
-
}
|
|
9
|
-
export interface IMakeAutoCompleteProps extends IFieldProps {
|
|
10
|
-
element: IMakeAutoComplete;
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { IOption } from './option';
|
|
2
|
-
import { IField, IFieldProps } from './field';
|
|
3
|
-
import { IModalLiveDataCondition } from './modal';
|
|
4
|
-
export interface IMakeMultiSelect extends Omit<IField, 'defaultValue'> {
|
|
5
|
-
elementType: 'multiselect';
|
|
6
|
-
options: Array<IOption>;
|
|
7
|
-
liveData?: IModalLiveDataCondition;
|
|
8
|
-
defaultValue?: Array<string>;
|
|
9
|
-
}
|
|
10
|
-
export interface IMakeMultiSelectProps extends IFieldProps {
|
|
11
|
-
element: IMakeMultiSelect;
|
|
12
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CSSProperties } from 'react';
|
|
2
|
-
import { IFieldProps } from './field';
|
|
3
|
-
export interface IMakeText {
|
|
4
|
-
elementType: 'text';
|
|
5
|
-
text: string;
|
|
6
|
-
styles?: CSSProperties;
|
|
7
|
-
}
|
|
8
|
-
export interface IMakeTextProps extends IFieldProps {
|
|
9
|
-
element: IMakeText;
|
|
10
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React, { FC, useEffect } from 'react'
|
|
2
|
-
import { Controller } from 'react-hook-form'
|
|
3
|
-
import { useFieldRender } from '../../hooks/field-render'
|
|
4
|
-
import { generateId } from '../../tools/general'
|
|
5
|
-
import { Autocomplete, AutocompleteItem } from '@nextui-org/react'
|
|
6
|
-
import { IMakeAutoCompleteProps } from '../../interfaces/make-autocomplete'
|
|
7
|
-
|
|
8
|
-
const MakeAutocomplete: FC<IMakeAutoCompleteProps> = ({ element: { validation: { required, ...validation }, ...element }, ...props }) => {
|
|
9
|
-
const { render, enable, checkField, liveData, liveSearching } = useFieldRender({ ...props, element })
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const subscription = props.watch((value, { name, type }) => checkField(value, { name, type }))
|
|
13
|
-
return () => subscription.unsubscribe()
|
|
14
|
-
}, [checkField, props, props.watch])
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
render
|
|
18
|
-
? <Controller
|
|
19
|
-
control={props.control}
|
|
20
|
-
name={element.name}
|
|
21
|
-
rules={{
|
|
22
|
-
required,
|
|
23
|
-
pattern: {
|
|
24
|
-
value: validation.regex as RegExp ?? /(.*)/,
|
|
25
|
-
message: validation.message ?? ''
|
|
26
|
-
},
|
|
27
|
-
...validation
|
|
28
|
-
}}
|
|
29
|
-
render={({ field: { onChange, value }, fieldState: { invalid } }) => (
|
|
30
|
-
<Autocomplete
|
|
31
|
-
size='sm'
|
|
32
|
-
{...element}
|
|
33
|
-
isDisabled={element.disabled ?? !enable}
|
|
34
|
-
id={element.id ?? generateId()}
|
|
35
|
-
onSelectionChange={onChange}
|
|
36
|
-
label={liveSearching ? 'Loading...' : element.label}
|
|
37
|
-
selectedKey={value}
|
|
38
|
-
color={invalid ? 'danger' : undefined}
|
|
39
|
-
isInvalid={invalid}
|
|
40
|
-
errorMessage={invalid ? (validation.message ?? '') : undefined}
|
|
41
|
-
>
|
|
42
|
-
{
|
|
43
|
-
(liveData || (element.options ?? [])).map((opt) => (
|
|
44
|
-
<AutocompleteItem key={opt.id} value={opt.id}>{opt.name}</AutocompleteItem>
|
|
45
|
-
))
|
|
46
|
-
}
|
|
47
|
-
</Autocomplete>
|
|
48
|
-
)}
|
|
49
|
-
/>
|
|
50
|
-
: <></>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default MakeAutocomplete
|