dynamic-modal 1.0.11 → 1.0.12
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/.idea/dynamic-modal.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README-ES.md +119 -119
- package/README.md +119 -119
- package/dist/components/input-upload/input-upload.js +18 -8
- package/dist/components/make-autocomplete/make-autocomplete.js +24 -17
- package/dist/components/make-input/make-input.js +24 -17
- package/dist/components/make-multi-select/make-multi-select.js +24 -17
- package/dist/components/make-select/make-select.js +24 -17
- package/dist/components/make-textarea/make-textarea.js +23 -16
- package/dist/components/make-toggle/make-toggle.js +36 -14
- package/dist/components/make-upload/make-upload.js +20 -8
- package/dist/components/portal/portal.js +17 -7
- package/dist/interfaces/field.d.ts +7 -4
- package/dist/interfaces/input-upload.d.ts +1 -15
- package/dist/modal.js +17 -7
- package/eslint.config.mjs +13 -13
- package/examples/enable-if.ts +129 -129
- package/examples/live-data.ts +63 -63
- package/examples/render-if.ts +130 -130
- package/examples/simple.ts +76 -76
- package/index.ts +2 -2
- package/package.json +48 -48
- package/src/components/input-upload/input-upload.tsx +72 -72
- package/src/components/make-autocomplete/make-autocomplete.tsx +54 -53
- package/src/components/make-button/make-button.tsx +17 -17
- package/src/components/make-input/make-input.tsx +47 -46
- package/src/components/make-multi-select/make-multi-select.tsx +56 -55
- package/src/components/make-select/make-select.tsx +54 -53
- package/src/components/make-text/make-text.tsx +16 -16
- package/src/components/make-textarea/make-textarea.tsx +48 -47
- package/src/components/make-title/make-title.tsx +12 -12
- package/src/components/make-toggle/make-toggle.tsx +44 -44
- package/src/components/make-upload/make-upload.tsx +34 -41
- package/src/components/portal/portal.tsx +36 -36
- package/src/hooks/field-render.ts +108 -108
- package/src/hooks/modal-handler.ts +37 -37
- package/src/interfaces/field.ts +35 -31
- package/src/interfaces/input-upload.ts +21 -37
- package/src/interfaces/make-autocomplete.ts +13 -13
- package/src/interfaces/make-button.ts +20 -20
- package/src/interfaces/make-field-group.ts +13 -13
- package/src/interfaces/make-field.ts +14 -14
- package/src/interfaces/make-multi-select.ts +14 -14
- package/src/interfaces/make-select.ts +12 -12
- package/src/interfaces/make-text.ts +12 -12
- package/src/interfaces/make-textarea.ts +11 -11
- package/src/interfaces/make-title.ts +3 -3
- package/src/interfaces/make-toggle.ts +9 -9
- package/src/interfaces/make-upload.ts +14 -14
- package/src/interfaces/modal.ts +51 -51
- package/src/interfaces/option.ts +3 -3
- package/src/interfaces/portal.ts +8 -8
- package/src/modal.tsx +174 -174
- package/src/tools/general.ts +6 -6
- package/tsconfig.json +13 -13
|
@@ -1,55 +1,56 @@
|
|
|
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 { IMakeMultiSelectProps } from '../../interfaces/make-multi-select'
|
|
6
|
-
import { Select, SelectItem } from '@nextui-org/react'
|
|
7
|
-
|
|
8
|
-
const MakeMultiSelect: FC<IMakeMultiSelectProps> = ({ element, ...props }) => {
|
|
9
|
-
const { render, enable, checkField, liveData, liveSearching } = useFieldRender({
|
|
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:
|
|
25
|
-
message:
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 { IMakeMultiSelectProps } from '../../interfaces/make-multi-select'
|
|
6
|
+
import { Select, SelectItem } from '@nextui-org/react'
|
|
7
|
+
|
|
8
|
+
const MakeMultiSelect: FC<IMakeMultiSelectProps> = ({ 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
|
+
<Select
|
|
31
|
+
size='sm'
|
|
32
|
+
{...element}
|
|
33
|
+
id={element.id ?? generateId()}
|
|
34
|
+
onSelectionChange={onChange}
|
|
35
|
+
label={liveSearching ? 'Loading...' : element.label}
|
|
36
|
+
selectionMode="multiple"
|
|
37
|
+
selectedKeys={value}
|
|
38
|
+
color={invalid ? 'danger' : undefined}
|
|
39
|
+
isInvalid={invalid}
|
|
40
|
+
errorMessage={invalid ? (validation.message ?? '') : undefined}
|
|
41
|
+
disabled={element.disabled ?? !enable}
|
|
42
|
+
className='max-w-lg'
|
|
43
|
+
>
|
|
44
|
+
{
|
|
45
|
+
(liveData || (element.options ?? [])).map((opt) => (
|
|
46
|
+
<SelectItem key={opt.id} value={opt.id}>{opt.name}</SelectItem>
|
|
47
|
+
))
|
|
48
|
+
}
|
|
49
|
+
</Select>
|
|
50
|
+
)}
|
|
51
|
+
/>
|
|
52
|
+
: null
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default MakeMultiSelect
|
|
@@ -1,53 +1,54 @@
|
|
|
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 { IMakeSelectProps } from '../../interfaces/make-select'
|
|
6
|
-
import { Select, SelectItem } from '@nextui-org/react'
|
|
7
|
-
|
|
8
|
-
const MakeSelect: FC<IMakeSelectProps> = ({ element, ...props }) => {
|
|
9
|
-
const { render, enable, checkField, liveData, liveSearching } = useFieldRender({
|
|
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:
|
|
25
|
-
message:
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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 { IMakeSelectProps } from '../../interfaces/make-select'
|
|
6
|
+
import { Select, SelectItem } from '@nextui-org/react'
|
|
7
|
+
|
|
8
|
+
const MakeSelect: FC<IMakeSelectProps> = ({ 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
|
+
<Select
|
|
31
|
+
size='sm'
|
|
32
|
+
{...element}
|
|
33
|
+
id={element.id ?? generateId()}
|
|
34
|
+
onChange={onChange}
|
|
35
|
+
label={liveSearching ? 'Loading...' : element.label}
|
|
36
|
+
selectedKeys={[value]}
|
|
37
|
+
color={invalid ? 'danger' : undefined}
|
|
38
|
+
isInvalid={invalid}
|
|
39
|
+
errorMessage={invalid ? (validation.message ?? '') : undefined}
|
|
40
|
+
disabled={element.disabled ?? !enable}
|
|
41
|
+
>
|
|
42
|
+
{
|
|
43
|
+
(liveData || (element.options ?? [])).map((opt) => (
|
|
44
|
+
<SelectItem key={opt.id} value={opt.id}>{opt.name}</SelectItem>
|
|
45
|
+
))
|
|
46
|
+
}
|
|
47
|
+
</Select>
|
|
48
|
+
)}
|
|
49
|
+
/>
|
|
50
|
+
: <></>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default MakeSelect
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import React, { FC } from 'react'
|
|
2
|
-
import { IMakeTextProps } from '../../interfaces/make-text'
|
|
3
|
-
|
|
4
|
-
const MakeText: FC<IMakeTextProps> = ({
|
|
5
|
-
element
|
|
6
|
-
}) => {
|
|
7
|
-
return (
|
|
8
|
-
<div className='text-xs text-center'>
|
|
9
|
-
<p style={element.styles}>
|
|
10
|
-
{element.text}
|
|
11
|
-
</p>
|
|
12
|
-
</div>
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default MakeText
|
|
1
|
+
import React, { FC } from 'react'
|
|
2
|
+
import { IMakeTextProps } from '../../interfaces/make-text'
|
|
3
|
+
|
|
4
|
+
const MakeText: FC<IMakeTextProps> = ({
|
|
5
|
+
element
|
|
6
|
+
}) => {
|
|
7
|
+
return (
|
|
8
|
+
<div className='text-xs text-center'>
|
|
9
|
+
<p style={element.styles}>
|
|
10
|
+
{element.text}
|
|
11
|
+
</p>
|
|
12
|
+
</div>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default MakeText
|
|
@@ -1,47 +1,48 @@
|
|
|
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 { IMakeTextareaProps } from '../../interfaces/make-textarea'
|
|
6
|
-
import { Textarea } from '@nextui-org/react'
|
|
7
|
-
|
|
8
|
-
const MakeTextarea: FC<IMakeTextareaProps> = ({ element, ...props }) => {
|
|
9
|
-
const { render, enable, checkField } = 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
|
-
name={element.name}
|
|
20
|
-
control={props.control}
|
|
21
|
-
rules={{
|
|
22
|
-
required
|
|
23
|
-
pattern: {
|
|
24
|
-
value:
|
|
25
|
-
message:
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 { IMakeTextareaProps } from '../../interfaces/make-textarea'
|
|
6
|
+
import { Textarea } from '@nextui-org/react'
|
|
7
|
+
|
|
8
|
+
const MakeTextarea: FC<IMakeTextareaProps> = ({ element: { validation: { required, ...validation }, ...element }, ...props }) => {
|
|
9
|
+
const { render, enable, checkField } = 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
|
+
name={element.name}
|
|
20
|
+
control={props.control}
|
|
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
|
+
<Textarea
|
|
31
|
+
{...element}
|
|
32
|
+
disableAutosize
|
|
33
|
+
id={element.id ?? generateId()}
|
|
34
|
+
onChange={onChange}
|
|
35
|
+
label={element.label}
|
|
36
|
+
value={value ?? ''}
|
|
37
|
+
color={invalid ? 'danger' : undefined}
|
|
38
|
+
isInvalid={invalid}
|
|
39
|
+
errorMessage={invalid ? (validation.message ?? '') : undefined}
|
|
40
|
+
disabled={element.disabled ?? !enable}
|
|
41
|
+
/>
|
|
42
|
+
)}
|
|
43
|
+
/>
|
|
44
|
+
: null
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default MakeTextarea
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { FC } from 'react'
|
|
2
|
-
import { IMakeTitle } from '../../interfaces/make-title'
|
|
3
|
-
|
|
4
|
-
const MakeTitle: FC<IMakeTitle> = ({ title }) => {
|
|
5
|
-
return (
|
|
6
|
-
<div className='flex text-center items-center justify-center text-xl'>
|
|
7
|
-
{title}
|
|
8
|
-
</div>
|
|
9
|
-
)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default MakeTitle
|
|
1
|
+
import React, { FC } from 'react'
|
|
2
|
+
import { IMakeTitle } from '../../interfaces/make-title'
|
|
3
|
+
|
|
4
|
+
const MakeTitle: FC<IMakeTitle> = ({ title }) => {
|
|
5
|
+
return (
|
|
6
|
+
<div className='flex text-center items-center justify-center text-xl'>
|
|
7
|
+
{title}
|
|
8
|
+
</div>
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default MakeTitle
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import React, { FC, useEffect } from 'react'
|
|
2
|
-
import { Controller } from 'react-hook-form'
|
|
3
|
-
import { useFieldRender } from '../../hooks/field-render'
|
|
4
|
-
import { IMakeToggleProps } from '../../interfaces/make-toggle'
|
|
5
|
-
import { Switch } from '@nextui-org/react'
|
|
6
|
-
import { generateId } from '../../tools/general'
|
|
7
|
-
|
|
8
|
-
const MakeToggle: FC<IMakeToggleProps> = (props) => {
|
|
9
|
-
const { render, enable, checkField } = useFieldRender(props)
|
|
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={
|
|
21
|
-
rules={{
|
|
22
|
-
required
|
|
23
|
-
pattern: {
|
|
24
|
-
value:
|
|
25
|
-
message:
|
|
26
|
-
}
|
|
27
|
-
}}
|
|
28
|
-
render={({ field: { onChange, value } }) => (
|
|
29
|
-
<Switch
|
|
30
|
-
{...
|
|
31
|
-
id={
|
|
32
|
-
isSelected={value}
|
|
33
|
-
onValueChange={onChange}
|
|
34
|
-
isDisabled={
|
|
35
|
-
>
|
|
36
|
-
{
|
|
37
|
-
</Switch>
|
|
38
|
-
)}
|
|
39
|
-
/>
|
|
40
|
-
: null
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default MakeToggle
|
|
1
|
+
import React, { FC, useEffect } from 'react'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import { useFieldRender } from '../../hooks/field-render'
|
|
4
|
+
import { IMakeToggleProps } from '../../interfaces/make-toggle'
|
|
5
|
+
import { Switch } from '@nextui-org/react'
|
|
6
|
+
import { generateId } from '../../tools/general'
|
|
7
|
+
|
|
8
|
+
const MakeToggle: FC<IMakeToggleProps> = ({ element: { validation: { required, ...validation }, ...element }, ...props }) => {
|
|
9
|
+
const { render, enable, checkField } = 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
|
+
}}
|
|
28
|
+
render={({ field: { onChange, value } }) => (
|
|
29
|
+
<Switch
|
|
30
|
+
{...element}
|
|
31
|
+
id={element.id ?? generateId()}
|
|
32
|
+
isSelected={value}
|
|
33
|
+
onValueChange={onChange}
|
|
34
|
+
isDisabled={element.disabled ?? !enable}
|
|
35
|
+
>
|
|
36
|
+
{element.label}
|
|
37
|
+
</Switch>
|
|
38
|
+
)}
|
|
39
|
+
/>
|
|
40
|
+
: null
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default MakeToggle
|
|
@@ -1,41 +1,34 @@
|
|
|
1
|
-
import React,{ FC } from 'react'
|
|
2
|
-
import { Controller } from 'react-hook-form'
|
|
3
|
-
import InputUpload from '../input-upload/input-upload'
|
|
4
|
-
import { useFieldRender } from '../../hooks/field-render'
|
|
5
|
-
import { IMakeUploadProps } from '../../interfaces/make-upload'
|
|
6
|
-
|
|
7
|
-
const MakeUpload : FC<IMakeUploadProps> = (props) => {
|
|
8
|
-
const { render, enable } = useFieldRender(props)
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
render
|
|
12
|
-
? <Controller
|
|
13
|
-
control={props.control}
|
|
14
|
-
name={
|
|
15
|
-
rules={{
|
|
16
|
-
required
|
|
17
|
-
pattern: {
|
|
18
|
-
value:
|
|
19
|
-
message:
|
|
20
|
-
}
|
|
21
|
-
}}
|
|
22
|
-
render={({ field: { onChange } }) => (
|
|
23
|
-
<InputUpload
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)}
|
|
36
|
-
/>
|
|
37
|
-
: null
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default MakeUpload
|
|
1
|
+
import React,{ FC } from 'react'
|
|
2
|
+
import { Controller } from 'react-hook-form'
|
|
3
|
+
import InputUpload from '../input-upload/input-upload'
|
|
4
|
+
import { useFieldRender } from '../../hooks/field-render'
|
|
5
|
+
import { IMakeUploadProps } from '../../interfaces/make-upload'
|
|
6
|
+
|
|
7
|
+
const MakeUpload : FC<IMakeUploadProps> = ({ element: { validation: { required, ...validation }, ...element }, ...props }) => {
|
|
8
|
+
const { render, enable } = useFieldRender({ ...props, element })
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
render
|
|
12
|
+
? <Controller
|
|
13
|
+
control={props.control}
|
|
14
|
+
name={element.name}
|
|
15
|
+
rules={{
|
|
16
|
+
required,
|
|
17
|
+
pattern: {
|
|
18
|
+
value: validation.regex as RegExp ?? /(.*)/,
|
|
19
|
+
message: validation.message ?? ''
|
|
20
|
+
}
|
|
21
|
+
}}
|
|
22
|
+
render={({ field: { onChange } }) => (
|
|
23
|
+
<InputUpload
|
|
24
|
+
{...element}
|
|
25
|
+
disabled={element.disabled ?? !enable}
|
|
26
|
+
onChange={onChange}
|
|
27
|
+
/>
|
|
28
|
+
)}
|
|
29
|
+
/>
|
|
30
|
+
: null
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default MakeUpload
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import React, { useRef, useEffect, useState, FC } from 'react'
|
|
3
|
-
import { createPortal } from 'react-dom'
|
|
4
|
-
import { IPortal } from '../../interfaces/portal'
|
|
5
|
-
|
|
6
|
-
export const Portal: FC<IPortal> = (props) => {
|
|
7
|
-
const ref = useRef<Element | null>(null)
|
|
8
|
-
const [mounted, setMounted] = useState(false)
|
|
9
|
-
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (mounted && !props.portalOpen && props.closeTime > 0) {
|
|
12
|
-
const timeoutId = setTimeout(() => {
|
|
13
|
-
setMounted(false)
|
|
14
|
-
ref.current = null
|
|
15
|
-
}, props.closeTime)
|
|
16
|
-
|
|
17
|
-
return () => clearTimeout(timeoutId)
|
|
18
|
-
} else if (mounted && !props.portalOpen) {
|
|
19
|
-
setMounted(false)
|
|
20
|
-
ref.current = null
|
|
21
|
-
} else if (!mounted && props.portalOpen) {
|
|
22
|
-
ref.current = document.querySelector<HTMLElement>(props.portalTag ?? '#portal')
|
|
23
|
-
setMounted(true)
|
|
24
|
-
}
|
|
25
|
-
}, [mounted, props.closeTime, props.portalOpen, props.portalTag])
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
mounted && ref.current
|
|
29
|
-
? createPortal(
|
|
30
|
-
<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'>
|
|
31
|
-
{props.children}
|
|
32
|
-
</div>
|
|
33
|
-
, ref.current)
|
|
34
|
-
: null
|
|
35
|
-
)
|
|
36
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
import React, { useRef, useEffect, useState, FC } from 'react'
|
|
3
|
+
import { createPortal } from 'react-dom'
|
|
4
|
+
import { IPortal } from '../../interfaces/portal'
|
|
5
|
+
|
|
6
|
+
export const Portal: FC<IPortal> = (props) => {
|
|
7
|
+
const ref = useRef<Element | null>(null)
|
|
8
|
+
const [mounted, setMounted] = useState(false)
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (mounted && !props.portalOpen && props.closeTime > 0) {
|
|
12
|
+
const timeoutId = setTimeout(() => {
|
|
13
|
+
setMounted(false)
|
|
14
|
+
ref.current = null
|
|
15
|
+
}, props.closeTime)
|
|
16
|
+
|
|
17
|
+
return () => clearTimeout(timeoutId)
|
|
18
|
+
} else if (mounted && !props.portalOpen) {
|
|
19
|
+
setMounted(false)
|
|
20
|
+
ref.current = null
|
|
21
|
+
} else if (!mounted && props.portalOpen) {
|
|
22
|
+
ref.current = document.querySelector<HTMLElement>(props.portalTag ?? '#portal')
|
|
23
|
+
setMounted(true)
|
|
24
|
+
}
|
|
25
|
+
}, [mounted, props.closeTime, props.portalOpen, props.portalTag])
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
mounted && ref.current
|
|
29
|
+
? createPortal(
|
|
30
|
+
<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'>
|
|
31
|
+
{props.children}
|
|
32
|
+
</div>
|
|
33
|
+
, ref.current)
|
|
34
|
+
: null
|
|
35
|
+
)
|
|
36
|
+
}
|