dynamic-modal 1.1.8 → 1.1.10
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.md +0 -1
- package/dist/components/input-upload/input-upload.js +3 -3
- package/dist/components/make-button/make-button.js +19 -10
- package/dist/components/make-description/make-description.js +2 -2
- package/dist/components/make-input/make-input.js +57 -29
- package/dist/components/make-select/make-select.js +66 -29
- package/dist/components/make-textarea/make-textarea.js +57 -29
- package/dist/components/make-toggle/make-toggle.js +57 -29
- package/dist/components/make-upload/make-upload.js +72 -18
- package/dist/components/portal/portal.js +20 -10
- package/dist/context/component/component-state.d.ts +3 -3
- package/dist/context/component/component-state.js +20 -11
- package/dist/hooks/use-enable-if.d.ts +9 -0
- package/dist/hooks/use-enable-if.js +45 -0
- package/dist/hooks/use-live-data.d.ts +14 -0
- package/dist/hooks/use-live-data.js +42 -0
- package/dist/hooks/use-render-if.d.ts +12 -0
- package/dist/hooks/use-render-if.js +51 -0
- package/dist/interfaces/component-state.d.ts +8 -8
- package/dist/interfaces/modal.d.ts +4 -2
- package/dist/modal.js +70 -58
- package/dist/util/general/general.util.d.ts +3 -0
- package/dist/util/general/general.util.js +28 -0
- package/eslint.config.mjs +72 -14
- package/examples/live-data.ts +0 -1
- package/package.json +11 -9
- package/src/components/input-upload/input-upload.tsx +40 -28
- package/src/components/make-button/make-button.tsx +11 -13
- package/src/components/make-description/make-description.tsx +14 -8
- package/src/components/make-input/make-input.tsx +94 -47
- package/src/components/make-select/make-select.tsx +118 -48
- package/src/components/make-textarea/make-textarea.tsx +94 -47
- package/src/components/make-toggle/make-toggle.tsx +94 -47
- package/src/components/make-upload/make-upload.tsx +88 -36
- package/src/components/portal/portal.tsx +27 -25
- package/src/context/component/component-state.tsx +16 -9
- package/src/hooks/modal-handler.ts +17 -14
- package/src/hooks/use-enable-if.ts +64 -0
- package/src/hooks/use-live-data.ts +45 -0
- package/src/hooks/use-render-if.ts +59 -0
- package/src/interfaces/component-state.ts +38 -23
- package/src/interfaces/field.ts +33 -27
- package/src/interfaces/input-upload.ts +17 -15
- package/src/interfaces/make-button.ts +14 -13
- package/src/interfaces/make-description.ts +9 -8
- package/src/interfaces/make-field-group.ts +9 -8
- package/src/interfaces/make-input.ts +9 -8
- package/src/interfaces/make-select.ts +9 -9
- package/src/interfaces/make-textarea.ts +5 -5
- package/src/interfaces/make-toggle.ts +3 -3
- package/src/interfaces/make-upload.ts +8 -8
- package/src/interfaces/modal.ts +57 -39
- package/src/interfaces/option.ts +3 -3
- package/src/interfaces/portal.ts +5 -5
- package/src/modal.tsx +243 -147
- package/src/util/general/general.util.ts +27 -0
- package/tsconfig.json +1 -1
- package/dist/hooks/field-render.d.ts +0 -20
- package/dist/hooks/field-render.js +0 -94
- package/dist/tools/general.d.ts +0 -1
- package/dist/tools/general.js +0 -11
- package/src/hooks/field-render.ts +0 -120
- package/src/tools/general.ts +0 -8
package/src/interfaces/field.ts
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Control,
|
|
4
|
+
FieldValues,
|
|
5
|
+
UseFormSetValue,
|
|
6
|
+
UseFormUnregister,
|
|
7
|
+
UseFormWatch,
|
|
8
|
+
} from 'react-hook-form';
|
|
9
|
+
|
|
10
|
+
import { IModalRenderCondition } from './modal';
|
|
5
11
|
|
|
6
12
|
export interface IValidationBase<T> {
|
|
7
|
-
value: T
|
|
8
|
-
message: string
|
|
13
|
+
value: T;
|
|
14
|
+
message: string;
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
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
|
|
18
|
+
name: string;
|
|
19
|
+
id?: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
style?: CSSProperties;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
defaultValue?: any;
|
|
24
|
+
renderIf?: IModalRenderCondition;
|
|
25
|
+
enableIf?: IModalRenderCondition;
|
|
20
26
|
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
|
|
27
|
+
required: boolean;
|
|
28
|
+
regex?: RegExp;
|
|
29
|
+
message?: string;
|
|
30
|
+
maxLength?: IValidationBase<number>;
|
|
31
|
+
minLength?: IValidationBase<number>;
|
|
32
|
+
min?: IValidationBase<number | string>;
|
|
33
|
+
max?: IValidationBase<number | string>;
|
|
34
|
+
};
|
|
35
|
+
disabled?: boolean;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
export interface IFieldProps {
|
|
33
|
-
control: Control<FieldValues, unknown
|
|
34
|
-
watch: UseFormWatch<FieldValues
|
|
35
|
-
setValue: UseFormSetValue<FieldValues
|
|
36
|
-
unregister: UseFormUnregister<FieldValues
|
|
39
|
+
control: Control<FieldValues, unknown>;
|
|
40
|
+
watch: UseFormWatch<FieldValues>;
|
|
41
|
+
setValue: UseFormSetValue<FieldValues>;
|
|
42
|
+
unregister: UseFormUnregister<FieldValues>;
|
|
37
43
|
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { ChangeEvent, CSSProperties } from 'react'
|
|
1
|
+
import { ChangeEvent, CSSProperties } from 'react';
|
|
2
2
|
|
|
3
3
|
export interface IFileResult {
|
|
4
|
-
name: string
|
|
5
|
-
size: number
|
|
6
|
-
data: string
|
|
4
|
+
name: string;
|
|
5
|
+
size: number;
|
|
6
|
+
data: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface IInputUpload {
|
|
10
|
-
id?: string
|
|
11
|
-
value?: string
|
|
12
|
-
onChange: (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
id?: string;
|
|
11
|
+
value?: string;
|
|
12
|
+
onChange: (
|
|
13
|
+
event: ChangeEvent<HTMLInputElement> | IFileResult | FileList | null,
|
|
14
|
+
) => void;
|
|
15
|
+
accept?: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
helpText?: string;
|
|
18
|
+
style?: CSSProperties;
|
|
19
|
+
readAsArrayBuffer?: boolean;
|
|
20
|
+
name: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
read?: boolean;
|
|
21
23
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
import { IFieldProps } from './field';
|
|
3
4
|
|
|
4
5
|
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
|
|
6
|
+
id?: string;
|
|
7
|
+
elementType: 'button';
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: CSSProperties;
|
|
11
|
+
variant?: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
type?: 'button' | 'submit' | 'reset';
|
|
14
|
+
onClick?: () => void;
|
|
15
|
+
color?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export interface IMakeButtonProps extends IFieldProps {
|
|
18
|
-
element: Omit<IMakeButton, 'elementType'
|
|
19
|
+
element: Omit<IMakeButton, 'elementType'>;
|
|
19
20
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { CSSProperties, FC } from 'react'
|
|
2
|
-
|
|
1
|
+
import { CSSProperties, FC } from 'react';
|
|
2
|
+
|
|
3
|
+
import { IFieldProps } from './field';
|
|
3
4
|
|
|
4
5
|
export interface IMakeDescription {
|
|
5
|
-
elementType: 'text'
|
|
6
|
-
text: string
|
|
7
|
-
containerStyle?: CSSProperties
|
|
8
|
-
textStyle?: CSSProperties
|
|
9
|
-
Icon?: FC
|
|
6
|
+
elementType: 'text';
|
|
7
|
+
text: string;
|
|
8
|
+
containerStyle?: CSSProperties;
|
|
9
|
+
textStyle?: CSSProperties;
|
|
10
|
+
Icon?: FC;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface IMakeDescriptionProps extends IFieldProps {
|
|
13
|
-
element: Omit<IMakeDescription, 'elementType'
|
|
14
|
+
element: Omit<IMakeDescription, 'elementType'>;
|
|
14
15
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { CSSProperties } from 'react'
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
import { IFieldProps } from './field';
|
|
4
|
+
import { IModalField } from './modal';
|
|
4
5
|
|
|
5
6
|
export interface IMakeFieldGroup {
|
|
6
|
-
elementType: 'group'
|
|
7
|
-
groups: Array<IModalField
|
|
8
|
-
style?: CSSProperties
|
|
9
|
-
title?: string
|
|
7
|
+
elementType: 'group';
|
|
8
|
+
groups: Array<IModalField>;
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
title?: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface IMakeFieldGroupProps extends IFieldProps {
|
|
13
|
-
element: IMakeFieldGroup
|
|
14
|
+
element: IMakeFieldGroup;
|
|
14
15
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { HTMLInputTypeAttribute } from 'react'
|
|
2
|
-
|
|
1
|
+
import { HTMLInputTypeAttribute } from 'react';
|
|
2
|
+
|
|
3
|
+
import { IField, IFieldProps } from './field';
|
|
3
4
|
|
|
4
5
|
export interface IMakeInput extends IField {
|
|
5
|
-
elementType: 'input'
|
|
6
|
-
placeholder?: string
|
|
7
|
-
min?: string
|
|
8
|
-
max?: string
|
|
9
|
-
type?: HTMLInputTypeAttribute
|
|
6
|
+
elementType: 'input';
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
min?: string;
|
|
9
|
+
max?: string;
|
|
10
|
+
type?: HTMLInputTypeAttribute;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface IMakeInputProps extends IFieldProps {
|
|
13
|
-
element: Omit<IMakeInput, 'elementType'
|
|
14
|
+
element: Omit<IMakeInput, 'elementType'>;
|
|
14
15
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { IField, IFieldProps } from './field'
|
|
2
|
-
import { IModalLiveDataCondition } from './modal'
|
|
3
|
-
import { IOption } from './option'
|
|
1
|
+
import { IField, IFieldProps } from './field';
|
|
2
|
+
import { IModalLiveDataCondition } from './modal';
|
|
3
|
+
import { IOption } from './option';
|
|
4
4
|
|
|
5
5
|
export interface IMakeSelect extends IField {
|
|
6
|
-
elementType: 'select'
|
|
7
|
-
options: Array<IOption
|
|
8
|
-
liveData?: IModalLiveDataCondition
|
|
9
|
-
isSearch?: boolean
|
|
10
|
-
isMulti?: boolean
|
|
6
|
+
elementType: 'select';
|
|
7
|
+
options: Array<IOption>;
|
|
8
|
+
liveData?: IModalLiveDataCondition;
|
|
9
|
+
isSearch?: boolean;
|
|
10
|
+
isMulti?: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface IMakeSelectProps extends IFieldProps {
|
|
14
|
-
element: Omit<IMakeSelect, 'elementType'
|
|
14
|
+
element: Omit<IMakeSelect, 'elementType'>;
|
|
15
15
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { IField, IFieldProps } from './field'
|
|
1
|
+
import { IField, IFieldProps } from './field';
|
|
2
2
|
|
|
3
3
|
export interface IMakeTextarea extends IField {
|
|
4
|
-
elementType: 'textarea'
|
|
5
|
-
cols?: number
|
|
6
|
-
rows?: number
|
|
4
|
+
elementType: 'textarea';
|
|
5
|
+
cols?: number;
|
|
6
|
+
rows?: number;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface IMakeTextareaProps extends IFieldProps {
|
|
10
|
-
element: Omit<IMakeTextarea, 'elementType'
|
|
10
|
+
element: Omit<IMakeTextarea, 'elementType'>;
|
|
11
11
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IField, IFieldProps } from './field'
|
|
1
|
+
import { IField, IFieldProps } from './field';
|
|
2
2
|
|
|
3
3
|
export interface IMakeToggle extends IField {
|
|
4
|
-
elementType: 'toggle'
|
|
4
|
+
elementType: 'toggle';
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export interface IMakeToggleProps extends IFieldProps {
|
|
8
|
-
element: Omit<IMakeToggle, 'elementType'
|
|
8
|
+
element: Omit<IMakeToggle, 'elementType'>;
|
|
9
9
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { IField, IFieldProps } from './field'
|
|
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: Omit<IMakeUpload, 'elementType'
|
|
13
|
+
element: Omit<IMakeUpload, 'elementType'>;
|
|
14
14
|
}
|
package/src/interfaces/modal.ts
CHANGED
|
@@ -1,50 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IMakeSelect } from './make-select'
|
|
4
|
-
import { IMakeInput } from './make-input'
|
|
5
|
-
import { IMakeTextarea } from './make-textarea'
|
|
6
|
-
import { IMakeToggle } from './make-toggle'
|
|
7
|
-
import { IMakeDescription } from './make-description'
|
|
8
|
-
import { IMakeFieldGroup } from './make-field-group'
|
|
9
|
-
import { IMakeUpload } from './make-upload'
|
|
10
|
-
import { IOption } from './option'
|
|
11
|
-
import { IMakeButton } from './make-button'
|
|
12
|
-
|
|
13
|
-
export type IModalField =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
import { IMakeSelect } from './make-select';
|
|
4
|
+
import { IMakeInput } from './make-input';
|
|
5
|
+
import { IMakeTextarea } from './make-textarea';
|
|
6
|
+
import { IMakeToggle } from './make-toggle';
|
|
7
|
+
import { IMakeDescription } from './make-description';
|
|
8
|
+
import { IMakeFieldGroup } from './make-field-group';
|
|
9
|
+
import { IMakeUpload } from './make-upload';
|
|
10
|
+
import { IOption } from './option';
|
|
11
|
+
import { IMakeButton } from './make-button';
|
|
12
|
+
|
|
13
|
+
export type IModalField =
|
|
14
|
+
| IMakeSelect
|
|
15
|
+
| IMakeInput
|
|
16
|
+
| IMakeFieldGroup
|
|
17
|
+
| IMakeTextarea
|
|
18
|
+
| IMakeToggle
|
|
19
|
+
| IMakeDescription
|
|
20
|
+
| IMakeUpload
|
|
21
|
+
| IMakeButton;
|
|
22
|
+
|
|
23
|
+
export type IFormField = IMakeSelect | IMakeInput | IMakeTextarea | IMakeToggle;
|
|
24
|
+
|
|
25
|
+
export interface IModalRenderAction {
|
|
26
|
+
action: (data: string, ...args: any[]) => Promise<boolean>;
|
|
27
|
+
condition: Array<string>;
|
|
20
28
|
}
|
|
21
29
|
|
|
30
|
+
export type IModalRenderCriteria = Record<
|
|
31
|
+
string,
|
|
32
|
+
Array<string | number | boolean> | undefined
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
export type IModalRenderCondition = IModalRenderAction | IModalRenderCriteria;
|
|
36
|
+
|
|
22
37
|
export type IModalLiveDataCondition = {
|
|
23
|
-
action: (data: string, ...args: any[]) => Promise<Array<IOption
|
|
24
|
-
condition: Array<string
|
|
25
|
-
}
|
|
38
|
+
action: (data: string, ...args: any[]) => Promise<Array<IOption>>;
|
|
39
|
+
condition: Array<string>;
|
|
40
|
+
};
|
|
26
41
|
|
|
27
42
|
export interface IModalConfigProps {
|
|
28
|
-
reservedData?: Record<string, any
|
|
29
|
-
title: string
|
|
30
|
-
fields: Array<IModalField
|
|
31
|
-
out: (data: any) => void
|
|
32
|
-
onClose?: () => void
|
|
33
|
-
style?: CSSProperties
|
|
34
|
-
overFlowBody?: string | number
|
|
35
|
-
minHeightBody?: string | number
|
|
36
|
-
useSubmit?: boolean
|
|
43
|
+
reservedData?: Record<string, any>;
|
|
44
|
+
title: string;
|
|
45
|
+
fields: Array<IModalField>;
|
|
46
|
+
out: (data: any) => void;
|
|
47
|
+
onClose?: () => void;
|
|
48
|
+
style?: CSSProperties;
|
|
49
|
+
overFlowBody?: string | number;
|
|
50
|
+
minHeightBody?: string | number;
|
|
51
|
+
useSubmit?: boolean;
|
|
37
52
|
actions: {
|
|
38
|
-
containerStyle?: CSSProperties
|
|
39
|
-
cancel?: Omit<IMakeButton, 'elementType'
|
|
40
|
-
action: Omit<IMakeButton, 'elementType'
|
|
41
|
-
}
|
|
53
|
+
containerStyle?: CSSProperties;
|
|
54
|
+
cancel?: Omit<IMakeButton, 'elementType'>;
|
|
55
|
+
action: Omit<IMakeButton, 'elementType'>;
|
|
56
|
+
};
|
|
42
57
|
}
|
|
43
58
|
|
|
44
|
-
export type IModalConfigLoader<T = any, D = any> = (
|
|
59
|
+
export type IModalConfigLoader<T = any, D = any> = (
|
|
60
|
+
props: T,
|
|
61
|
+
action: (modalResult: D) => void,
|
|
62
|
+
) => IModalConfigProps;
|
|
45
63
|
|
|
46
64
|
export interface IModal {
|
|
47
|
-
open: boolean
|
|
48
|
-
close: () => void
|
|
49
|
-
config: IModalConfigProps
|
|
65
|
+
open: boolean;
|
|
66
|
+
close: () => void;
|
|
67
|
+
config: IModalConfigProps;
|
|
50
68
|
}
|
package/src/interfaces/option.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export interface IOption {
|
|
2
|
-
id: string
|
|
3
|
-
name: string
|
|
4
|
-
}
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
package/src/interfaces/portal.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ReactNode } from 'react'
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
export interface IPortal {
|
|
4
|
-
children: ReactNode
|
|
5
|
-
closeTime: number
|
|
6
|
-
portalOpen: boolean
|
|
7
|
-
portalTag?: string
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
closeTime: number;
|
|
6
|
+
portalOpen: boolean;
|
|
7
|
+
portalTag?: string;
|
|
8
8
|
}
|