dynamic-modal 1.1.4 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-ES.md +217 -217
- package/README.md +216 -216
- package/dist/components/input-upload/input-upload.js +1 -1
- package/dist/components/make-button/make-button.js +7 -17
- package/dist/components/make-input/make-input.js +7 -17
- package/dist/components/make-select/make-select.js +7 -17
- package/dist/components/make-textarea/make-textarea.js +7 -17
- package/dist/components/make-toggle/make-toggle.js +7 -17
- package/dist/components/portal/portal.js +7 -17
- package/dist/context/component/component-state.js +7 -17
- package/dist/interfaces/modal.d.ts +1 -0
- package/dist/modal.js +38 -19
- package/eslint.config.mjs +14 -14
- package/examples/enable-if.ts +127 -127
- package/examples/live-data.ts +61 -61
- package/examples/render-if.ts +128 -128
- package/examples/simple.ts +74 -74
- package/index.ts +5 -5
- package/package.json +46 -47
- package/src/components/input-upload/input-upload.tsx +67 -67
- package/src/components/make-button/make-button.tsx +18 -18
- package/src/components/make-description/make-description.tsx +15 -15
- package/src/components/make-input/make-input.tsx +53 -53
- package/src/components/make-select/make-select.tsx +55 -55
- package/src/components/make-textarea/make-textarea.tsx +53 -53
- package/src/components/make-toggle/make-toggle.tsx +53 -53
- package/src/components/make-upload/make-upload.tsx +40 -40
- package/src/components/portal/portal.tsx +37 -37
- package/src/context/component/component-state.tsx +17 -17
- package/src/hooks/field-render.ts +109 -109
- package/src/hooks/modal-handler.ts +38 -38
- package/src/interfaces/component-state.ts +33 -33
- package/src/interfaces/field.ts +37 -37
- package/src/interfaces/input-upload.ts +21 -21
- package/src/interfaces/make-button.ts +19 -19
- package/src/interfaces/make-description.ts +14 -14
- package/src/interfaces/make-field-group.ts +14 -14
- package/src/interfaces/make-input.ts +14 -14
- package/src/interfaces/make-select.ts +15 -15
- package/src/interfaces/make-textarea.ts +11 -11
- package/src/interfaces/make-toggle.ts +9 -9
- package/src/interfaces/make-upload.ts +14 -14
- package/src/interfaces/modal.ts +47 -46
- package/src/interfaces/option.ts +3 -3
- package/src/interfaces/portal.ts +8 -8
- package/src/modal.tsx +196 -164
- package/src/tools/general.ts +8 -8
- package/tsconfig.json +13 -13
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import React, { useMemo } from "react"
|
|
4
|
-
import { createContext } from "react"
|
|
5
|
-
import { IComponentState, IComponentStateProps } from "../../interfaces/component-state"
|
|
6
|
-
|
|
7
|
-
export const ComponentStateContext = createContext<IComponentState>({} as IComponentState)
|
|
8
|
-
|
|
9
|
-
export const ComponentState = ({ children, components }: IComponentStateProps) => {
|
|
10
|
-
|
|
11
|
-
const value: IComponentState = useMemo(() => components, [])
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<ComponentStateContext.Provider value={value}>
|
|
15
|
-
{children}
|
|
16
|
-
</ComponentStateContext.Provider>
|
|
17
|
-
)
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { useMemo } from "react"
|
|
4
|
+
import { createContext } from "react"
|
|
5
|
+
import { IComponentState, IComponentStateProps } from "../../interfaces/component-state"
|
|
6
|
+
|
|
7
|
+
export const ComponentStateContext = createContext<IComponentState>({} as IComponentState)
|
|
8
|
+
|
|
9
|
+
export const ComponentState = ({ children, components }: IComponentStateProps) => {
|
|
10
|
+
|
|
11
|
+
const value: IComponentState = useMemo(() => components, [])
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ComponentStateContext.Provider value={value}>
|
|
15
|
+
{children}
|
|
16
|
+
</ComponentStateContext.Provider>
|
|
17
|
+
)
|
|
18
18
|
}
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { useCallback, useMemo, useState } from 'react'
|
|
4
|
-
import { IField, IFieldProps } from '../interfaces/field'
|
|
5
|
-
import { IOption } from '../interfaces/option'
|
|
6
|
-
import { IModalLiveDataCondition, IModalRenderCondition } from '../interfaces/modal'
|
|
7
|
-
|
|
8
|
-
export type IFormData = Record<string, unknown>
|
|
9
|
-
|
|
10
|
-
export interface IWatchEvent {
|
|
11
|
-
name: string | undefined
|
|
12
|
-
type: string | undefined
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface IFieldRender {
|
|
16
|
-
render: boolean | null
|
|
17
|
-
enable: boolean | null
|
|
18
|
-
checkField: (formData: IFormData, { name, type }: IWatchEvent) => void
|
|
19
|
-
liveData?: Array<IOption
|
|
20
|
-
liveSearching?: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface IFieldRenderProps extends Pick<IFieldProps, 'setValue' | 'unregister'> {
|
|
24
|
-
element: Partial<Pick<IField, 'enableIf' | 'renderIf' | 'name' >> & Partial<Record<'liveData', IModalLiveDataCondition>>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const useFieldRender = ({ element, setValue, unregister }: IFieldRenderProps): IFieldRender => {
|
|
28
|
-
const [render, setRender] = useState<boolean|null>(null)
|
|
29
|
-
const [enable, setEnable] = useState<boolean|null>(null)
|
|
30
|
-
const [liveSearching, setLiveSearching] = useState<boolean>(false)
|
|
31
|
-
const [liveData, setLiveData] = useState<Array<IOption> | undefined>(undefined)
|
|
32
|
-
|
|
33
|
-
const renderCondition = useMemo<boolean>(
|
|
34
|
-
() => {
|
|
35
|
-
const isRender: boolean = element.renderIf !== undefined
|
|
36
|
-
if (render === null) setRender(!isRender)
|
|
37
|
-
return isRender
|
|
38
|
-
}, [element.renderIf, render]
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
const enableCondition = useMemo<boolean>(
|
|
42
|
-
() => {
|
|
43
|
-
const isEnable: boolean = element.enableIf !== undefined
|
|
44
|
-
if (enable === null) setEnable(!isEnable)
|
|
45
|
-
return isEnable
|
|
46
|
-
}, [element.enableIf, enable]
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
const liveDataCondition = useMemo<boolean>(
|
|
50
|
-
() => {
|
|
51
|
-
return element.liveData !== undefined
|
|
52
|
-
}, [element.liveData]
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
const renderConditionList: Array<string> = useMemo(() => {
|
|
56
|
-
return renderCondition ? Object.keys(element.renderIf as IModalRenderCondition) : []
|
|
57
|
-
}, [element.renderIf, renderCondition])
|
|
58
|
-
|
|
59
|
-
const enableConditionList: Array<string> = useMemo(() => {
|
|
60
|
-
return enableCondition ? Object.keys(element.enableIf as IModalRenderCondition) : []
|
|
61
|
-
}, [enableCondition, element.enableIf])
|
|
62
|
-
|
|
63
|
-
const liveDataAction = useCallback(
|
|
64
|
-
async (field: string |number | Array<unknown>, formData: IFormData) => {
|
|
65
|
-
if (typeof field === 'string' && element.liveData?.action) {
|
|
66
|
-
const options = element.liveData.action(field, formData)
|
|
67
|
-
return options ?? []
|
|
68
|
-
}
|
|
69
|
-
return [] as Array<IOption>
|
|
70
|
-
}, [element.liveData]
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
const checkField = useCallback(
|
|
74
|
-
async (formData: IFormData, { name }: IWatchEvent) => {
|
|
75
|
-
const key: string = name ?? ''
|
|
76
|
-
const targetField = formData[key] as string | number
|
|
77
|
-
const fieldValidValue: boolean = targetField !== undefined && targetField !== null && targetField !== ''
|
|
78
|
-
|
|
79
|
-
if (renderCondition && renderConditionList.includes(key) && fieldValidValue) {
|
|
80
|
-
const renderStatus: boolean = (element.renderIf as IModalRenderCondition)[key]!.includes(targetField) || (element.renderIf as IModalRenderCondition)[key]!.includes('*')
|
|
81
|
-
if (render !== renderStatus) {
|
|
82
|
-
setRender(renderStatus)
|
|
83
|
-
if(!renderStatus) unregister(element.name as string)
|
|
84
|
-
}
|
|
85
|
-
} else if (enableCondition && enableConditionList.includes(key) && fieldValidValue) {
|
|
86
|
-
const enableStatus: boolean = (element.enableIf as IModalRenderCondition)[key]!.includes(targetField) || (element.enableIf as IModalRenderCondition)[key]!.includes('*')
|
|
87
|
-
if (enable !== enableStatus) setEnable(enableStatus)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (liveDataCondition && element.liveData?.condition.includes(key)) {
|
|
91
|
-
if (targetField) {
|
|
92
|
-
setLiveSearching(true)
|
|
93
|
-
const options: Array<IOption> = await liveDataAction(targetField, formData)
|
|
94
|
-
if (liveData && JSON.stringify(liveData) !== JSON.stringify(options)) { setValue(element.name as string, options) }
|
|
95
|
-
setLiveData(options)
|
|
96
|
-
setLiveSearching(false)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}, [enable, enableCondition, enableConditionList, liveData, liveDataAction, liveDataCondition, render, renderCondition, renderConditionList]
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
render,
|
|
104
|
-
enable,
|
|
105
|
-
checkField,
|
|
106
|
-
liveData,
|
|
107
|
-
liveSearching
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useCallback, useMemo, useState } from 'react'
|
|
4
|
+
import { IField, IFieldProps } from '../interfaces/field'
|
|
5
|
+
import { IOption } from '../interfaces/option'
|
|
6
|
+
import { IModalLiveDataCondition, IModalRenderCondition } from '../interfaces/modal'
|
|
7
|
+
|
|
8
|
+
export type IFormData = Record<string, unknown>
|
|
9
|
+
|
|
10
|
+
export interface IWatchEvent {
|
|
11
|
+
name: string | undefined
|
|
12
|
+
type: string | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IFieldRender {
|
|
16
|
+
render: boolean | null
|
|
17
|
+
enable: boolean | null
|
|
18
|
+
checkField: (formData: IFormData, { name, type }: IWatchEvent) => void
|
|
19
|
+
liveData?: Array<IOption>
|
|
20
|
+
liveSearching?: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IFieldRenderProps extends Pick<IFieldProps, 'setValue' | 'unregister'> {
|
|
24
|
+
element: Partial<Pick<IField, 'enableIf' | 'renderIf' | 'name' >> & Partial<Record<'liveData', IModalLiveDataCondition>>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const useFieldRender = ({ element, setValue, unregister }: IFieldRenderProps): IFieldRender => {
|
|
28
|
+
const [render, setRender] = useState<boolean|null>(null)
|
|
29
|
+
const [enable, setEnable] = useState<boolean|null>(null)
|
|
30
|
+
const [liveSearching, setLiveSearching] = useState<boolean>(false)
|
|
31
|
+
const [liveData, setLiveData] = useState<Array<IOption> | undefined>(undefined)
|
|
32
|
+
|
|
33
|
+
const renderCondition = useMemo<boolean>(
|
|
34
|
+
() => {
|
|
35
|
+
const isRender: boolean = element.renderIf !== undefined
|
|
36
|
+
if (render === null) setRender(!isRender)
|
|
37
|
+
return isRender
|
|
38
|
+
}, [element.renderIf, render]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const enableCondition = useMemo<boolean>(
|
|
42
|
+
() => {
|
|
43
|
+
const isEnable: boolean = element.enableIf !== undefined
|
|
44
|
+
if (enable === null) setEnable(!isEnable)
|
|
45
|
+
return isEnable
|
|
46
|
+
}, [element.enableIf, enable]
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const liveDataCondition = useMemo<boolean>(
|
|
50
|
+
() => {
|
|
51
|
+
return element.liveData !== undefined
|
|
52
|
+
}, [element.liveData]
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
const renderConditionList: Array<string> = useMemo(() => {
|
|
56
|
+
return renderCondition ? Object.keys(element.renderIf as IModalRenderCondition) : []
|
|
57
|
+
}, [element.renderIf, renderCondition])
|
|
58
|
+
|
|
59
|
+
const enableConditionList: Array<string> = useMemo(() => {
|
|
60
|
+
return enableCondition ? Object.keys(element.enableIf as IModalRenderCondition) : []
|
|
61
|
+
}, [enableCondition, element.enableIf])
|
|
62
|
+
|
|
63
|
+
const liveDataAction = useCallback(
|
|
64
|
+
async (field: string |number | Array<unknown>, formData: IFormData) => {
|
|
65
|
+
if (typeof field === 'string' && element.liveData?.action) {
|
|
66
|
+
const options = element.liveData.action(field, formData)
|
|
67
|
+
return options ?? []
|
|
68
|
+
}
|
|
69
|
+
return [] as Array<IOption>
|
|
70
|
+
}, [element.liveData]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const checkField = useCallback(
|
|
74
|
+
async (formData: IFormData, { name }: IWatchEvent) => {
|
|
75
|
+
const key: string = name ?? ''
|
|
76
|
+
const targetField = formData[key] as string | number
|
|
77
|
+
const fieldValidValue: boolean = targetField !== undefined && targetField !== null && targetField !== ''
|
|
78
|
+
|
|
79
|
+
if (renderCondition && renderConditionList.includes(key) && fieldValidValue) {
|
|
80
|
+
const renderStatus: boolean = (element.renderIf as IModalRenderCondition)[key]!.includes(targetField) || (element.renderIf as IModalRenderCondition)[key]!.includes('*')
|
|
81
|
+
if (render !== renderStatus) {
|
|
82
|
+
setRender(renderStatus)
|
|
83
|
+
if(!renderStatus) unregister(element.name as string)
|
|
84
|
+
}
|
|
85
|
+
} else if (enableCondition && enableConditionList.includes(key) && fieldValidValue) {
|
|
86
|
+
const enableStatus: boolean = (element.enableIf as IModalRenderCondition)[key]!.includes(targetField) || (element.enableIf as IModalRenderCondition)[key]!.includes('*')
|
|
87
|
+
if (enable !== enableStatus) setEnable(enableStatus)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (liveDataCondition && element.liveData?.condition.includes(key)) {
|
|
91
|
+
if (targetField) {
|
|
92
|
+
setLiveSearching(true)
|
|
93
|
+
const options: Array<IOption> = await liveDataAction(targetField, formData)
|
|
94
|
+
if (liveData && JSON.stringify(liveData) !== JSON.stringify(options)) { setValue(element.name as string, options) }
|
|
95
|
+
setLiveData(options)
|
|
96
|
+
setLiveSearching(false)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, [enable, enableCondition, enableConditionList, liveData, liveDataAction, liveDataCondition, render, renderCondition, renderConditionList]
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
render,
|
|
104
|
+
enable,
|
|
105
|
+
checkField,
|
|
106
|
+
liveData,
|
|
107
|
+
liveSearching
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { useState } from 'react'
|
|
4
|
-
import { IModal, IModalConfigProps } from '../interfaces/modal'
|
|
5
|
-
|
|
6
|
-
interface IModalHandler {
|
|
7
|
-
openModal: (config: IModalConfigProps) => void
|
|
8
|
-
modalProps: IModal
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function useModalHandler (): IModalHandler {
|
|
12
|
-
const initialState: IModalHandler = {
|
|
13
|
-
modalProps: {
|
|
14
|
-
config: {} as IModalConfigProps,
|
|
15
|
-
close: () => {},
|
|
16
|
-
open: false,
|
|
17
|
-
},
|
|
18
|
-
openModal: () => {},
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const [modalConfig, setModalConfig] = useState<IModalHandler>(initialState)
|
|
22
|
-
|
|
23
|
-
const openModal = (config: IModalConfigProps) => {
|
|
24
|
-
if (!config) {
|
|
25
|
-
alert(`¡WARNING! this modal was not returned config, please check before use`)
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
setModalConfig({ openModal, modalProps: { config, open: true, close } })
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const closeModal = () => setModalConfig(initialState)
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
openModal,
|
|
36
|
-
modalProps: { ...modalConfig.modalProps, close: closeModal },
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react'
|
|
4
|
+
import { IModal, IModalConfigProps } from '../interfaces/modal'
|
|
5
|
+
|
|
6
|
+
interface IModalHandler {
|
|
7
|
+
openModal: (config: IModalConfigProps) => void
|
|
8
|
+
modalProps: IModal
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useModalHandler (): IModalHandler {
|
|
12
|
+
const initialState: IModalHandler = {
|
|
13
|
+
modalProps: {
|
|
14
|
+
config: {} as IModalConfigProps,
|
|
15
|
+
close: () => {},
|
|
16
|
+
open: false,
|
|
17
|
+
},
|
|
18
|
+
openModal: () => {},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const [modalConfig, setModalConfig] = useState<IModalHandler>(initialState)
|
|
22
|
+
|
|
23
|
+
const openModal = (config: IModalConfigProps) => {
|
|
24
|
+
if (!config) {
|
|
25
|
+
alert(`¡WARNING! this modal was not returned config, please check before use`)
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setModalConfig({ openModal, modalProps: { config, open: true, close } })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const closeModal = () => setModalConfig(initialState)
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
openModal,
|
|
36
|
+
modalProps: { ...modalConfig.modalProps, close: closeModal },
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { FC, PropsWithChildren } from "react"
|
|
3
|
-
import { FieldError } from "react-hook-form"
|
|
4
|
-
import { IOption } from "./option"
|
|
5
|
-
import { IMakeInput } from "./make-input"
|
|
6
|
-
import { IMakeButton } from "./make-button"
|
|
7
|
-
import { IMakeSelect } from "./make-select"
|
|
8
|
-
import { IMakeTextarea } from "./make-textarea"
|
|
9
|
-
import { IMakeToggle } from "./make-toggle"
|
|
10
|
-
|
|
11
|
-
export interface IComponentAditionalProps {
|
|
12
|
-
onChange: (...event: any[]) => void
|
|
13
|
-
value: any
|
|
14
|
-
invalid: boolean
|
|
15
|
-
error?: FieldError
|
|
16
|
-
liveSearching?: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface IComponentState {
|
|
20
|
-
ModalButtonCancel: FC<Omit<IMakeButton, 'elementType'>>
|
|
21
|
-
ModalButtonAction: FC<Omit<IMakeButton, 'elementType'>>
|
|
22
|
-
Button: FC<Omit<IMakeButton, 'elementType'>>
|
|
23
|
-
//Description: FC<Omit<IMakeDescription, 'elementType'>>
|
|
24
|
-
Input: FC<Omit<IMakeInput, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps>
|
|
25
|
-
Select: FC<Omit<IMakeSelect, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps & Record<'options', Array<IOption>>>
|
|
26
|
-
Textarea: FC<Omit<IMakeTextarea, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps>
|
|
27
|
-
Toggle: FC<Omit<IMakeToggle, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IComponentStateProps extends PropsWithChildren {
|
|
31
|
-
components: IComponentState
|
|
32
|
-
}
|
|
33
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { FC, PropsWithChildren } from "react"
|
|
3
|
+
import { FieldError } from "react-hook-form"
|
|
4
|
+
import { IOption } from "./option"
|
|
5
|
+
import { IMakeInput } from "./make-input"
|
|
6
|
+
import { IMakeButton } from "./make-button"
|
|
7
|
+
import { IMakeSelect } from "./make-select"
|
|
8
|
+
import { IMakeTextarea } from "./make-textarea"
|
|
9
|
+
import { IMakeToggle } from "./make-toggle"
|
|
10
|
+
|
|
11
|
+
export interface IComponentAditionalProps {
|
|
12
|
+
onChange: (...event: any[]) => void
|
|
13
|
+
value: any
|
|
14
|
+
invalid: boolean
|
|
15
|
+
error?: FieldError
|
|
16
|
+
liveSearching?: boolean
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IComponentState {
|
|
20
|
+
ModalButtonCancel: FC<Omit<IMakeButton, 'elementType'>>
|
|
21
|
+
ModalButtonAction: FC<Omit<IMakeButton, 'elementType'>>
|
|
22
|
+
Button: FC<Omit<IMakeButton, 'elementType'>>
|
|
23
|
+
//Description: FC<Omit<IMakeDescription, 'elementType'>>
|
|
24
|
+
Input: FC<Omit<IMakeInput, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps>
|
|
25
|
+
Select: FC<Omit<IMakeSelect, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps & Record<'options', Array<IOption>>>
|
|
26
|
+
Textarea: FC<Omit<IMakeTextarea, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps>
|
|
27
|
+
Toggle: FC<Omit<IMakeToggle, 'elementType' | 'validation' |'renderIf' | 'enableIf'> & IComponentAditionalProps>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IComponentStateProps extends PropsWithChildren {
|
|
31
|
+
components: IComponentState
|
|
32
|
+
}
|
|
33
|
+
|
package/src/interfaces/field.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { CSSProperties } from 'react'
|
|
3
|
-
import { Control, FieldValues, UseFormSetValue, UseFormUnregister, UseFormWatch } from 'react-hook-form'
|
|
4
|
-
import { IModalRenderCondition } from './modal'
|
|
5
|
-
|
|
6
|
-
export interface IValidationBase<T> {
|
|
7
|
-
value: T
|
|
8
|
-
message: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IField {
|
|
12
|
-
name: string
|
|
13
|
-
id?: string
|
|
14
|
-
label?: string
|
|
15
|
-
style?: CSSProperties
|
|
16
|
-
placeholder?: string
|
|
17
|
-
defaultValue?: any
|
|
18
|
-
renderIf?: IModalRenderCondition
|
|
19
|
-
enableIf?: IModalRenderCondition
|
|
20
|
-
validation: {
|
|
21
|
-
required: boolean
|
|
22
|
-
regex?: RegExp
|
|
23
|
-
message?: string
|
|
24
|
-
maxLength?: IValidationBase<number>
|
|
25
|
-
minLength?: IValidationBase<number>
|
|
26
|
-
min?: IValidationBase<number | string>
|
|
27
|
-
max?: IValidationBase<number | string>
|
|
28
|
-
}
|
|
29
|
-
disabled?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface IFieldProps {
|
|
33
|
-
control: Control<FieldValues, unknown>
|
|
34
|
-
watch: UseFormWatch<FieldValues>
|
|
35
|
-
setValue: UseFormSetValue<FieldValues>
|
|
36
|
-
unregister: UseFormUnregister<FieldValues>
|
|
37
|
-
}
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { CSSProperties } from 'react'
|
|
3
|
+
import { Control, FieldValues, UseFormSetValue, UseFormUnregister, UseFormWatch } from 'react-hook-form'
|
|
4
|
+
import { IModalRenderCondition } from './modal'
|
|
5
|
+
|
|
6
|
+
export interface IValidationBase<T> {
|
|
7
|
+
value: T
|
|
8
|
+
message: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IField {
|
|
12
|
+
name: string
|
|
13
|
+
id?: string
|
|
14
|
+
label?: string
|
|
15
|
+
style?: CSSProperties
|
|
16
|
+
placeholder?: string
|
|
17
|
+
defaultValue?: any
|
|
18
|
+
renderIf?: IModalRenderCondition
|
|
19
|
+
enableIf?: IModalRenderCondition
|
|
20
|
+
validation: {
|
|
21
|
+
required: boolean
|
|
22
|
+
regex?: RegExp
|
|
23
|
+
message?: string
|
|
24
|
+
maxLength?: IValidationBase<number>
|
|
25
|
+
minLength?: IValidationBase<number>
|
|
26
|
+
min?: IValidationBase<number | string>
|
|
27
|
+
max?: IValidationBase<number | string>
|
|
28
|
+
}
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IFieldProps {
|
|
33
|
+
control: Control<FieldValues, unknown>
|
|
34
|
+
watch: UseFormWatch<FieldValues>
|
|
35
|
+
setValue: UseFormSetValue<FieldValues>
|
|
36
|
+
unregister: UseFormUnregister<FieldValues>
|
|
37
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ChangeEvent, CSSProperties } from 'react'
|
|
2
|
-
|
|
3
|
-
export interface IFileResult {
|
|
4
|
-
name: string
|
|
5
|
-
size: number
|
|
6
|
-
data: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface IInputUpload {
|
|
10
|
-
id?: string
|
|
11
|
-
value?: string
|
|
12
|
-
onChange: (event: ChangeEvent<HTMLInputElement> | IFileResult | FileList | null) => void
|
|
13
|
-
accept?:string
|
|
14
|
-
label?: string
|
|
15
|
-
helpText?: string
|
|
16
|
-
style?:CSSProperties
|
|
17
|
-
readAsArrayBuffer?: boolean
|
|
18
|
-
name: string
|
|
19
|
-
disabled?: boolean
|
|
20
|
-
read?: boolean
|
|
21
|
-
}
|
|
1
|
+
import { ChangeEvent, CSSProperties } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface IFileResult {
|
|
4
|
+
name: string
|
|
5
|
+
size: number
|
|
6
|
+
data: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IInputUpload {
|
|
10
|
+
id?: string
|
|
11
|
+
value?: string
|
|
12
|
+
onChange: (event: ChangeEvent<HTMLInputElement> | IFileResult | FileList | null) => void
|
|
13
|
+
accept?:string
|
|
14
|
+
label?: string
|
|
15
|
+
helpText?: string
|
|
16
|
+
style?:CSSProperties
|
|
17
|
+
readAsArrayBuffer?: boolean
|
|
18
|
+
name: string
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
read?: boolean
|
|
21
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
import { IFieldProps } from './field'
|
|
3
|
-
|
|
4
|
-
export interface IMakeButton {
|
|
5
|
-
id?: string
|
|
6
|
-
elementType: 'button'
|
|
7
|
-
disabled?: boolean
|
|
8
|
-
className?: string
|
|
9
|
-
style?: CSSProperties
|
|
10
|
-
variant?: string
|
|
11
|
-
text?: string
|
|
12
|
-
type?: 'button' | 'submit' | 'reset'
|
|
13
|
-
onClick?: () => void
|
|
14
|
-
color?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IMakeButtonProps extends IFieldProps {
|
|
18
|
-
element: Omit<IMakeButton, 'elementType'>
|
|
19
|
-
}
|
|
1
|
+
import { CSSProperties } from 'react'
|
|
2
|
+
import { IFieldProps } from './field'
|
|
3
|
+
|
|
4
|
+
export interface IMakeButton {
|
|
5
|
+
id?: string
|
|
6
|
+
elementType: 'button'
|
|
7
|
+
disabled?: boolean
|
|
8
|
+
className?: string
|
|
9
|
+
style?: CSSProperties
|
|
10
|
+
variant?: string
|
|
11
|
+
text?: string
|
|
12
|
+
type?: 'button' | 'submit' | 'reset'
|
|
13
|
+
onClick?: () => void
|
|
14
|
+
color?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IMakeButtonProps extends IFieldProps {
|
|
18
|
+
element: Omit<IMakeButton, 'elementType'>
|
|
19
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CSSProperties, FC } from 'react'
|
|
2
|
-
import { IFieldProps } from './field'
|
|
3
|
-
|
|
4
|
-
export interface IMakeDescription {
|
|
5
|
-
elementType: 'text'
|
|
6
|
-
text: string
|
|
7
|
-
containerStyle?: CSSProperties
|
|
8
|
-
textStyle?: CSSProperties
|
|
9
|
-
Icon?: FC
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IMakeDescriptionProps extends IFieldProps {
|
|
13
|
-
element: Omit<IMakeDescription, 'elementType'>
|
|
14
|
-
}
|
|
1
|
+
import { CSSProperties, FC } from 'react'
|
|
2
|
+
import { IFieldProps } from './field'
|
|
3
|
+
|
|
4
|
+
export interface IMakeDescription {
|
|
5
|
+
elementType: 'text'
|
|
6
|
+
text: string
|
|
7
|
+
containerStyle?: CSSProperties
|
|
8
|
+
textStyle?: CSSProperties
|
|
9
|
+
Icon?: FC
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IMakeDescriptionProps extends IFieldProps {
|
|
13
|
+
element: Omit<IMakeDescription, 'elementType'>
|
|
14
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
import { IFieldProps } from './field'
|
|
3
|
-
import { IModalField } from './modal'
|
|
4
|
-
|
|
5
|
-
export interface IMakeFieldGroup {
|
|
6
|
-
elementType: 'group'
|
|
7
|
-
groups: Array<IModalField>
|
|
8
|
-
style?: CSSProperties
|
|
9
|
-
title?: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IMakeFieldGroupProps extends IFieldProps {
|
|
13
|
-
element: IMakeFieldGroup
|
|
14
|
-
}
|
|
1
|
+
import { CSSProperties } from 'react'
|
|
2
|
+
import { IFieldProps } from './field'
|
|
3
|
+
import { IModalField } from './modal'
|
|
4
|
+
|
|
5
|
+
export interface IMakeFieldGroup {
|
|
6
|
+
elementType: 'group'
|
|
7
|
+
groups: Array<IModalField>
|
|
8
|
+
style?: CSSProperties
|
|
9
|
+
title?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IMakeFieldGroupProps extends IFieldProps {
|
|
13
|
+
element: IMakeFieldGroup
|
|
14
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { HTMLInputTypeAttribute } from 'react'
|
|
2
|
-
import { IField, IFieldProps } from './field'
|
|
3
|
-
|
|
4
|
-
export interface IMakeInput extends IField {
|
|
5
|
-
elementType: 'input'
|
|
6
|
-
placeholder?: string
|
|
7
|
-
min?: string
|
|
8
|
-
max?: string
|
|
9
|
-
type?: HTMLInputTypeAttribute
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IMakeInputProps extends IFieldProps {
|
|
13
|
-
element: Omit<IMakeInput, 'elementType'>
|
|
14
|
-
}
|
|
1
|
+
import { HTMLInputTypeAttribute } from 'react'
|
|
2
|
+
import { IField, IFieldProps } from './field'
|
|
3
|
+
|
|
4
|
+
export interface IMakeInput extends IField {
|
|
5
|
+
elementType: 'input'
|
|
6
|
+
placeholder?: string
|
|
7
|
+
min?: string
|
|
8
|
+
max?: string
|
|
9
|
+
type?: HTMLInputTypeAttribute
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IMakeInputProps extends IFieldProps {
|
|
13
|
+
element: Omit<IMakeInput, 'elementType'>
|
|
14
|
+
}
|