dynamic-modal 1.1.1 → 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.
Files changed (52) hide show
  1. package/README-ES.md +217 -217
  2. package/README.md +216 -215
  3. package/dist/components/input-upload/input-upload.js +1 -1
  4. package/dist/components/make-button/make-button.js +7 -17
  5. package/dist/components/make-input/make-input.js +9 -19
  6. package/dist/components/make-select/make-select.js +9 -19
  7. package/dist/components/make-textarea/make-textarea.js +9 -19
  8. package/dist/components/make-toggle/make-toggle.js +9 -19
  9. package/dist/components/make-upload/make-upload.js +2 -2
  10. package/dist/components/portal/portal.js +7 -17
  11. package/dist/context/component/component-state.js +7 -17
  12. package/dist/hooks/field-render.js +1 -1
  13. package/dist/interfaces/field.d.ts +3 -2
  14. package/dist/interfaces/make-select.d.ts +2 -1
  15. package/dist/interfaces/modal.d.ts +2 -1
  16. package/dist/modal.js +38 -19
  17. package/eslint.config.mjs +14 -14
  18. package/examples/enable-if.ts +127 -127
  19. package/examples/live-data.ts +61 -61
  20. package/examples/render-if.ts +128 -128
  21. package/examples/simple.ts +74 -74
  22. package/index.ts +5 -5
  23. package/package.json +46 -47
  24. package/src/components/input-upload/input-upload.tsx +67 -67
  25. package/src/components/make-button/make-button.tsx +18 -18
  26. package/src/components/make-description/make-description.tsx +15 -15
  27. package/src/components/make-input/make-input.tsx +53 -53
  28. package/src/components/make-select/make-select.tsx +55 -55
  29. package/src/components/make-textarea/make-textarea.tsx +53 -53
  30. package/src/components/make-toggle/make-toggle.tsx +53 -53
  31. package/src/components/make-upload/make-upload.tsx +40 -40
  32. package/src/components/portal/portal.tsx +37 -37
  33. package/src/context/component/component-state.tsx +17 -17
  34. package/src/hooks/field-render.ts +109 -109
  35. package/src/hooks/modal-handler.ts +38 -38
  36. package/src/interfaces/component-state.ts +33 -33
  37. package/src/interfaces/field.ts +37 -36
  38. package/src/interfaces/input-upload.ts +21 -21
  39. package/src/interfaces/make-button.ts +19 -19
  40. package/src/interfaces/make-description.ts +14 -14
  41. package/src/interfaces/make-field-group.ts +14 -14
  42. package/src/interfaces/make-input.ts +14 -14
  43. package/src/interfaces/make-select.ts +15 -14
  44. package/src/interfaces/make-textarea.ts +11 -11
  45. package/src/interfaces/make-toggle.ts +9 -9
  46. package/src/interfaces/make-upload.ts +14 -14
  47. package/src/interfaces/modal.ts +47 -45
  48. package/src/interfaces/option.ts +3 -3
  49. package/src/interfaces/portal.ts +8 -8
  50. package/src/modal.tsx +196 -164
  51. package/src/tools/general.ts +8 -8
  52. package/tsconfig.json +13 -13
@@ -1,40 +1,40 @@
1
- 'use client'
2
-
3
- import React,{ FC } from 'react'
4
- import { Controller } from 'react-hook-form'
5
- import InputUpload from '../input-upload/input-upload'
6
- import { useFieldRender } from '../../hooks/field-render'
7
- import { IMakeUploadProps } from '../../interfaces/make-upload'
8
-
9
- const MakeUpload : FC<IMakeUploadProps> = ({ element: { validation: { required, ...validation }, ...element }, ...props }) => {
10
- const { render, enable } = useFieldRender({ ...props, element })
11
-
12
- return (
13
- render
14
- ? <Controller
15
- control={props.control}
16
- name={element.name}
17
- rules={{
18
- required: {
19
- value: required,
20
- message: validation.message ?? ''
21
- },
22
- pattern: validation.regex ? {
23
- value: validation.regex,
24
- message: validation.message ?? ''
25
- } : undefined,
26
- ...validation
27
- }}
28
- render={({ field: { onChange } }) => (
29
- <InputUpload
30
- {...element}
31
- onChange={onChange}
32
- disabled={element.disabled ?? !enable}
33
- />
34
- )}
35
- />
36
- : null
37
- )
38
- }
39
-
40
- export default MakeUpload
1
+ 'use client'
2
+
3
+ import React,{ FC } from 'react'
4
+ import { Controller } from 'react-hook-form'
5
+ import InputUpload from '../input-upload/input-upload'
6
+ import { useFieldRender } from '../../hooks/field-render'
7
+ import { IMakeUploadProps } from '../../interfaces/make-upload'
8
+
9
+ const MakeUpload : FC<IMakeUploadProps> = ({ element: { validation: { required, ...validation }, enableIf, renderIf, ...element }, ...props }) => {
10
+ const { render, enable } = useFieldRender({ ...props, element: { enableIf, renderIf, ...element} })
11
+
12
+ return (
13
+ render
14
+ ? <Controller
15
+ control={props.control}
16
+ name={element.name}
17
+ rules={{
18
+ required: {
19
+ value: required,
20
+ message: validation.message ?? ''
21
+ },
22
+ pattern: validation.regex ? {
23
+ value: validation.regex,
24
+ message: validation.message ?? ''
25
+ } : undefined,
26
+ ...validation
27
+ }}
28
+ render={({ field: { onChange } }) => (
29
+ <InputUpload
30
+ {...element}
31
+ onChange={onChange}
32
+ disabled={element.disabled ?? !enable}
33
+ />
34
+ )}
35
+ />
36
+ : null
37
+ )
38
+ }
39
+
40
+ export default MakeUpload
@@ -1,37 +1,37 @@
1
- 'use client'
2
-
3
- import React, { useRef, useEffect, useState, FC } from 'react'
4
- import { createPortal } from 'react-dom'
5
- import { IPortal } from '../../interfaces/portal'
6
-
7
- export const Portal: FC<IPortal> = (props) => {
8
- const ref = useRef<Element | null>(null)
9
- const [mounted, setMounted] = useState(false)
10
-
11
- useEffect(() => {
12
- if (mounted && !props.portalOpen && props.closeTime > 0) {
13
- const timeoutId = setTimeout(() => {
14
- setMounted(false)
15
- ref.current = null
16
- }, props.closeTime)
17
-
18
- return () => clearTimeout(timeoutId)
19
- } else if (mounted && !props.portalOpen) {
20
- setMounted(false)
21
- ref.current = null
22
- } else if (!mounted && props.portalOpen) {
23
- ref.current = document.querySelector<HTMLElement>(props.portalTag ?? '#portal')
24
- setMounted(true)
25
- }
26
- }, [mounted, props.closeTime, props.portalOpen, props.portalTag])
27
-
28
- return (
29
- mounted && ref.current
30
- ? createPortal(
31
- <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'>
32
- {props.children}
33
- </div>
34
- , ref.current)
35
- : null
36
- )
37
- }
1
+ 'use client'
2
+
3
+ import React, { useRef, useEffect, useState, FC } from 'react'
4
+ import { createPortal } from 'react-dom'
5
+ import { IPortal } from '../../interfaces/portal'
6
+
7
+ export const Portal: FC<IPortal> = (props) => {
8
+ const ref = useRef<Element | null>(null)
9
+ const [mounted, setMounted] = useState(false)
10
+
11
+ useEffect(() => {
12
+ if (mounted && !props.portalOpen && props.closeTime > 0) {
13
+ const timeoutId = setTimeout(() => {
14
+ setMounted(false)
15
+ ref.current = null
16
+ }, props.closeTime)
17
+
18
+ return () => clearTimeout(timeoutId)
19
+ } else if (mounted && !props.portalOpen) {
20
+ setMounted(false)
21
+ ref.current = null
22
+ } else if (!mounted && props.portalOpen) {
23
+ ref.current = document.querySelector<HTMLElement>(props.portalTag ?? '#portal')
24
+ setMounted(true)
25
+ }
26
+ }, [mounted, props.closeTime, props.portalOpen, props.portalTag])
27
+
28
+ return (
29
+ mounted && ref.current
30
+ ? createPortal(
31
+ <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'>
32
+ {props.children}
33
+ </div>
34
+ , ref.current)
35
+ : null
36
+ )
37
+ }
@@ -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
+
@@ -1,36 +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
-
5
- export interface IValidationBase<T> {
6
- value: T
7
- message: string
8
- }
9
-
10
- export interface IField {
11
- name: string
12
- id?: string
13
- label?: string
14
- style?: CSSProperties
15
- placeholder?: string
16
- defaultValue?: any
17
- renderIf?: Record<string, Array<string | number>>
18
- enableIf?: Record<string, Array<string | number>>
19
- validation: {
20
- required: boolean
21
- regex?: RegExp
22
- message?: string
23
- maxLength?: IValidationBase<number>
24
- minLength?: IValidationBase<number>
25
- min?: IValidationBase<number | string>
26
- max?: IValidationBase<number | string>
27
- }
28
- disabled?: boolean
29
- }
30
-
31
- export interface IFieldProps {
32
- control: Control<FieldValues, unknown>
33
- watch: UseFormWatch<FieldValues>
34
- setValue: UseFormSetValue<FieldValues>
35
- unregister: UseFormUnregister<FieldValues>
36
- }
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
+ }