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,62 +1,62 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { IModalConfigLoader } from '../src/interfaces/modal'
3
- import { IOption } from '../src/interfaces/option'
4
-
5
- type IncomingProps = {
6
- typeList: Array<IOption>
7
-
8
- //Define function to receive selected element and formData (if you need to use) make read or select operations and build
9
- //next select array of elements
10
- optionReadAction : (typeId: string, formData: any) => Promise<Array<IOption>>
11
- }
12
-
13
- type ResultProps = Omit<IncomingProps,'optionReadAction'|'typeList'> & Record<'typeId'|'optionId', string>
14
-
15
- export interface ILiveDataModal {
16
- default: IModalConfigLoader<IncomingProps, ResultProps>
17
- }
18
-
19
- const liveDataModal: ILiveDataModal = {
20
- default: (props, action) => {
21
- return {
22
- reservedData: {}, //Put here any data that you want store and receive into modal output
23
- fields: [ //Put here any elements for render into modal
24
- {
25
- elementType: 'select',
26
- label: 'Type',
27
- options: props.typeList,
28
- name: 'typeId', //Element to be observed
29
- validation: {
30
- required: true,
31
- message: 'Please select a valid type'
32
- }
33
- },
34
- {
35
- elementType: 'select',
36
- label: 'Options',
37
- options: [],
38
- name: 'optionId',
39
- validation: {
40
- required: true,
41
- message: 'Please select a valid option'
42
- },
43
- liveData: {
44
- action: props.optionReadAction, //Define live data action (function that receive data selected from other field for execute and build other options)
45
- condition: ['typeId'] //Define element into modal was to observed
46
- }
47
- }
48
- ],
49
- style: { // Put here styles for modal like height or width
50
- width: '500px'
51
- },
52
- title: `Title of enable if modal`, //Title of modal
53
- out: action, //Function to receive data from modal
54
- actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
55
- action: { text:'Action', color: 'primary' },
56
- cancel: { text: 'Cancel', color: 'danger' }
57
- }
58
- }
59
- }
60
- }
61
-
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { IModalConfigLoader } from '../src/interfaces/modal'
3
+ import { IOption } from '../src/interfaces/option'
4
+
5
+ type IncomingProps = {
6
+ typeList: Array<IOption>
7
+
8
+ //Define function to receive selected element and formData (if you need to use) make read or select operations and build
9
+ //next select array of elements
10
+ optionReadAction : (typeId: string, formData: any) => Promise<Array<IOption>>
11
+ }
12
+
13
+ type ResultProps = Omit<IncomingProps,'optionReadAction'|'typeList'> & Record<'typeId'|'optionId', string>
14
+
15
+ export interface ILiveDataModal {
16
+ default: IModalConfigLoader<IncomingProps, ResultProps>
17
+ }
18
+
19
+ const liveDataModal: ILiveDataModal = {
20
+ default: (props, action) => {
21
+ return {
22
+ reservedData: {}, //Put here any data that you want store and receive into modal output
23
+ fields: [ //Put here any elements for render into modal
24
+ {
25
+ elementType: 'select',
26
+ label: 'Type',
27
+ options: props.typeList,
28
+ name: 'typeId', //Element to be observed
29
+ validation: {
30
+ required: true,
31
+ message: 'Please select a valid type'
32
+ }
33
+ },
34
+ {
35
+ elementType: 'select',
36
+ label: 'Options',
37
+ options: [],
38
+ name: 'optionId',
39
+ validation: {
40
+ required: true,
41
+ message: 'Please select a valid option'
42
+ },
43
+ liveData: {
44
+ action: props.optionReadAction, //Define live data action (function that receive data selected from other field for execute and build other options)
45
+ condition: ['typeId'] //Define element into modal was to observed
46
+ }
47
+ }
48
+ ],
49
+ style: { // Put here styles for modal like height or width
50
+ width: '500px'
51
+ },
52
+ title: `Title of enable if modal`, //Title of modal
53
+ out: action, //Function to receive data from modal
54
+ actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
55
+ action: { text:'Action', color: 'primary' },
56
+ cancel: { text: 'Cancel', color: 'danger' }
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
62
  export default liveDataModal
@@ -1,129 +1,129 @@
1
-
2
- import { IModalConfigLoader } from '../src/interfaces/modal'
3
-
4
- export type IncomingProps = object
5
-
6
- type ResultProps = Record<'optionId', string> & Partial<Record<'input1ReadOnly' | 'input1WriteValue' | 'input2ReadOnly' | 'input2WriteValue', string>>
7
-
8
- export interface IRenderIfModal {
9
- default: IModalConfigLoader<IncomingProps, ResultProps>
10
- }
11
-
12
- const renderIfModal: IRenderIfModal = {
13
- default: (props, action) => {
14
- return {
15
- reservedData: {}, //Put here any data that you want store and receive into modal output
16
- fields: [ //Put here any elements for render into modal
17
- {
18
- elementType: 'select',
19
- label: 'option',
20
- defaultValue: '0',
21
- options: [
22
- {
23
- id: '0',
24
- name:'Select...'
25
- },
26
- {
27
- id: '1',
28
- name:'Option 1'
29
- },
30
- {
31
- id: '2',
32
- name:'Option 2'
33
- }
34
- ],
35
- name: 'optionId', //Element to be observed
36
- validation: {
37
- required: true,
38
- message: 'Please select a valid option'
39
- }
40
- },
41
- {
42
- elementType: 'group', //Put here groups of element into same line and customize using styles
43
- groups: [
44
- {
45
- elementType: 'input',
46
- label: 'Input 1 (Read)',
47
- name: 'input1ReadOnly',
48
- disabled: true,
49
- styles: {
50
- width: '50%'
51
- },
52
- validation: {
53
- required: false
54
- },
55
- //Define render condition (element will be show when value of element observed match with array condition)
56
- renderIf: {
57
- optionId: ['1']
58
- }
59
- },
60
- {
61
- elementType: 'input',
62
- label: 'Input 1',
63
- name: 'input1WriteValue',
64
- styles: {
65
- width: '50%'
66
- },
67
- validation: {
68
- required: true,
69
- message: `Write a valid input value`
70
- },
71
- //Define render condition (element will be show when value of element observed match with array condition)
72
- renderIf: {
73
- optionId: ['1']
74
- }
75
- },
76
- ]
77
- },
78
- {
79
- elementType: 'group', //Put here groups of element into same line and customize using styles
80
- groups: [
81
- {
82
- elementType: 'input',
83
- label: 'Input 2 (Read)',
84
- name: 'input2ReadOnly',
85
- disabled: true,
86
- styles: {
87
- width: '50%'
88
- },
89
- validation: {
90
- required: false
91
- },
92
- //Define render condition (element will be show when value of element observed match with array condition)
93
- renderIf: {
94
- optionId: ['2']
95
- }
96
- },
97
- {
98
- elementType: 'input',
99
- label: 'Input 2',
100
- name: 'input2WriteValue',
101
- styles: {
102
- width: '50%'
103
- },
104
- validation: {
105
- required: true,
106
- message: `Write a valid input value`
107
- },
108
- //Define render condition (element will be show when value of element observed match with array condition)
109
- renderIf: {
110
- optionId: ['2']
111
- }
112
- },
113
- ]
114
- },
115
- ],
116
- style: { // Put here styles for modal like height or width
117
- width: '500px'
118
- },
119
- title: `Title of enable if modal`, //Title of modal
120
- out: action, //Function to receive data from modal
121
- actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
122
- action: { text:'Action', color: 'Primary' },
123
- cancel: { text: 'Cancel', color: 'Danger' }
124
- }
125
- }
126
- }
127
- }
128
-
1
+
2
+ import { IModalConfigLoader } from '../src/interfaces/modal'
3
+
4
+ export type IncomingProps = object
5
+
6
+ type ResultProps = Record<'optionId', string> & Partial<Record<'input1ReadOnly' | 'input1WriteValue' | 'input2ReadOnly' | 'input2WriteValue', string>>
7
+
8
+ export interface IRenderIfModal {
9
+ default: IModalConfigLoader<IncomingProps, ResultProps>
10
+ }
11
+
12
+ const renderIfModal: IRenderIfModal = {
13
+ default: (props, action) => {
14
+ return {
15
+ reservedData: {}, //Put here any data that you want store and receive into modal output
16
+ fields: [ //Put here any elements for render into modal
17
+ {
18
+ elementType: 'select',
19
+ label: 'option',
20
+ defaultValue: '0',
21
+ options: [
22
+ {
23
+ id: '0',
24
+ name:'Select...'
25
+ },
26
+ {
27
+ id: '1',
28
+ name:'Option 1'
29
+ },
30
+ {
31
+ id: '2',
32
+ name:'Option 2'
33
+ }
34
+ ],
35
+ name: 'optionId', //Element to be observed
36
+ validation: {
37
+ required: true,
38
+ message: 'Please select a valid option'
39
+ }
40
+ },
41
+ {
42
+ elementType: 'group', //Put here groups of element into same line and customize using styles
43
+ groups: [
44
+ {
45
+ elementType: 'input',
46
+ label: 'Input 1 (Read)',
47
+ name: 'input1ReadOnly',
48
+ disabled: true,
49
+ styles: {
50
+ width: '50%'
51
+ },
52
+ validation: {
53
+ required: false
54
+ },
55
+ //Define render condition (element will be show when value of element observed match with array condition)
56
+ renderIf: {
57
+ optionId: ['1']
58
+ }
59
+ },
60
+ {
61
+ elementType: 'input',
62
+ label: 'Input 1',
63
+ name: 'input1WriteValue',
64
+ styles: {
65
+ width: '50%'
66
+ },
67
+ validation: {
68
+ required: true,
69
+ message: `Write a valid input value`
70
+ },
71
+ //Define render condition (element will be show when value of element observed match with array condition)
72
+ renderIf: {
73
+ optionId: ['1']
74
+ }
75
+ },
76
+ ]
77
+ },
78
+ {
79
+ elementType: 'group', //Put here groups of element into same line and customize using styles
80
+ groups: [
81
+ {
82
+ elementType: 'input',
83
+ label: 'Input 2 (Read)',
84
+ name: 'input2ReadOnly',
85
+ disabled: true,
86
+ styles: {
87
+ width: '50%'
88
+ },
89
+ validation: {
90
+ required: false
91
+ },
92
+ //Define render condition (element will be show when value of element observed match with array condition)
93
+ renderIf: {
94
+ optionId: ['2']
95
+ }
96
+ },
97
+ {
98
+ elementType: 'input',
99
+ label: 'Input 2',
100
+ name: 'input2WriteValue',
101
+ styles: {
102
+ width: '50%'
103
+ },
104
+ validation: {
105
+ required: true,
106
+ message: `Write a valid input value`
107
+ },
108
+ //Define render condition (element will be show when value of element observed match with array condition)
109
+ renderIf: {
110
+ optionId: ['2']
111
+ }
112
+ },
113
+ ]
114
+ },
115
+ ],
116
+ style: { // Put here styles for modal like height or width
117
+ width: '500px'
118
+ },
119
+ title: `Title of enable if modal`, //Title of modal
120
+ out: action, //Function to receive data from modal
121
+ actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
122
+ action: { text:'Action', color: 'Primary' },
123
+ cancel: { text: 'Cancel', color: 'Danger' }
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
129
  export default renderIfModal
@@ -1,75 +1,75 @@
1
- import { IModalConfigLoader } from '../src/interfaces/modal'
2
-
3
- type IncomingProps = {
4
- reserved: string
5
- input1: string
6
- store?: boolean
7
- clear?: boolean
8
- }
9
-
10
- type ResultProps = IncomingProps
11
-
12
- export interface ISimpleModal {
13
- default: IModalConfigLoader<IncomingProps, ResultProps> //Define others modals if you want
14
- }
15
-
16
- const simpleModal: ISimpleModal = {
17
- default: (props, action) => {
18
- return {
19
- reservedData: { reserved: props.reserved }, //Put here any data that you want store and receive into modal output
20
- fields: [ //Put here any elements for render into modal
21
- {
22
- elementType: 'input',
23
- label: 'Input 1',
24
- defaultValue: props.input1,
25
- name: 'input1',
26
- validation: {
27
- required: true,
28
- message: 'This field is required',
29
- regex: undefined //Use regex for custom validation
30
- }
31
- },
32
- {
33
- elementType: 'group', //Put here groups of element into same line and customize using styles
34
- groups: [
35
- {
36
- elementType: 'toggle',
37
- label: 'Store',
38
- defaultValue: `${props.store ?? false}`,
39
- name: 'store',
40
- styles: {
41
- width: '50%'
42
- },
43
- validation: {
44
- required: false
45
- }
46
- },
47
- {
48
- elementType: 'toggle',
49
- label: 'Clear',
50
- defaultValue: `${props.clear ?? false}`,
51
- name: 'clear',
52
- styles: {
53
- width: '50%'
54
- },
55
- validation: {
56
- required: false
57
- }
58
- }
59
- ]
60
- },
61
- ],
62
- style: { // Put here styles for modal like height or width
63
- width: '500px'
64
- },
65
- title: `Title of enable if modal`, //Title of modal
66
- out: action, //Function to receive data from modal
67
- actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
68
- action: { text:'Action', color: 'Primary' },
69
- cancel: { text: 'Cancel', color: 'Danger' }
70
- }
71
- }
72
- }
73
- }
74
-
1
+ import { IModalConfigLoader } from '../src/interfaces/modal'
2
+
3
+ type IncomingProps = {
4
+ reserved: string
5
+ input1: string
6
+ store?: boolean
7
+ clear?: boolean
8
+ }
9
+
10
+ type ResultProps = IncomingProps
11
+
12
+ export interface ISimpleModal {
13
+ default: IModalConfigLoader<IncomingProps, ResultProps> //Define others modals if you want
14
+ }
15
+
16
+ const simpleModal: ISimpleModal = {
17
+ default: (props, action) => {
18
+ return {
19
+ reservedData: { reserved: props.reserved }, //Put here any data that you want store and receive into modal output
20
+ fields: [ //Put here any elements for render into modal
21
+ {
22
+ elementType: 'input',
23
+ label: 'Input 1',
24
+ defaultValue: props.input1,
25
+ name: 'input1',
26
+ validation: {
27
+ required: true,
28
+ message: 'This field is required',
29
+ regex: undefined //Use regex for custom validation
30
+ }
31
+ },
32
+ {
33
+ elementType: 'group', //Put here groups of element into same line and customize using styles
34
+ groups: [
35
+ {
36
+ elementType: 'toggle',
37
+ label: 'Store',
38
+ defaultValue: `${props.store ?? false}`,
39
+ name: 'store',
40
+ styles: {
41
+ width: '50%'
42
+ },
43
+ validation: {
44
+ required: false
45
+ }
46
+ },
47
+ {
48
+ elementType: 'toggle',
49
+ label: 'Clear',
50
+ defaultValue: `${props.clear ?? false}`,
51
+ name: 'clear',
52
+ styles: {
53
+ width: '50%'
54
+ },
55
+ validation: {
56
+ required: false
57
+ }
58
+ }
59
+ ]
60
+ },
61
+ ],
62
+ style: { // Put here styles for modal like height or width
63
+ width: '500px'
64
+ },
65
+ title: `Title of enable if modal`, //Title of modal
66
+ out: action, //Function to receive data from modal
67
+ actions: { //Actions of modal, all props that you define here will be pass to ModalButtonCancel and ModalButtonAction components in your ComponentState
68
+ action: { text:'Action', color: 'Primary' },
69
+ cancel: { text: 'Cancel', color: 'Danger' }
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
75
  export default simpleModal
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- 'use client'
2
- export { default as DynamicModal } from './src/modal'
3
- export type { IModalConfigLoader, IModalConfigProps, IModalRenderCondition, IModalField, IModalLiveDataCondition } from './src/interfaces/modal'
4
- export { useModalHandler } from './src/hooks/modal-handler'
5
- export { ComponentState, ComponentStateContext } from './src/context/component/component-state';
1
+ 'use client'
2
+ export { default as DynamicModal } from './src/modal'
3
+ export type { IModalConfigLoader, IModalConfigProps, IModalRenderCondition, IModalField, IModalLiveDataCondition } from './src/interfaces/modal'
4
+ export { useModalHandler } from './src/hooks/modal-handler'
5
+ export { ComponentState, ComponentStateContext } from './src/context/component/component-state'
package/package.json CHANGED
@@ -1,47 +1,46 @@
1
- {
2
- "name": "dynamic-modal",
3
- "version": "1.1.1",
4
- "description": "The dynamic-modal is a solution of creation different modals into project using a json configuration file",
5
- "main": "index.js",
6
- "scripts": {
7
- "build": "tsc",
8
- "lint": "eslint .",
9
- "publish": "npm publish --access public",
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://gitlab.com/f.salazar/dynamic-modal.git"
15
- },
16
- "keywords": [
17
- "modal",
18
- "react",
19
- "next",
20
- "dynamic",
21
- "json"
22
- ],
23
- "author": "Francisco J. Salazar G",
24
- "license": "ISC",
25
- "bugs": {
26
- "url": "https://gitlab.com/f.salazar/dynamic-modal/issues"
27
- },
28
- "homepage": "https://gitlab.com/f.salazar/dynamic-modal#readme",
29
- "devDependencies": {
30
- "@eslint/js": "^9.22.0",
31
- "@types/react": "^19.0.10",
32
- "@types/react-dom": "^19.0.4",
33
- "@typescript-eslint/eslint-plugin": "^8.26.1",
34
- "@typescript-eslint/parser": "^8.26.1",
35
- "eslint": "^9.22.0",
36
- "eslint-plugin-react": "^7.37.4",
37
- "eslint-plugin-react-hooks": "^5.2.0",
38
- "globals": "^16.0.0",
39
- "typescript": "^5.8.2",
40
- "typescript-eslint": "^8.26.1"
41
- },
42
- "dependencies": {
43
- "react": "^19.0.0",
44
- "react-dom": "^19.0.0",
45
- "react-hook-form": "^7.54.2"
46
- }
47
- }
1
+ {
2
+ "name": "dynamic-modal",
3
+ "version": "1.1.7",
4
+ "description": "The dynamic-modal is a solution of creation different modals into project using a json configuration file",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "lint": "eslint .",
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://gitlab.com/f.salazar/dynamic-modal.git"
14
+ },
15
+ "keywords": [
16
+ "modal",
17
+ "react",
18
+ "next",
19
+ "dynamic",
20
+ "json"
21
+ ],
22
+ "author": "Francisco J. Salazar G",
23
+ "license": "ISC",
24
+ "bugs": {
25
+ "url": "https://gitlab.com/f.salazar/dynamic-modal/issues"
26
+ },
27
+ "homepage": "https://gitlab.com/f.salazar/dynamic-modal#readme",
28
+ "devDependencies": {
29
+ "@eslint/js": "^9.22.0",
30
+ "@types/react": "^19.0.10",
31
+ "@types/react-dom": "^19.0.4",
32
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
33
+ "@typescript-eslint/parser": "^8.26.1",
34
+ "eslint": "^9.22.0",
35
+ "eslint-plugin-react": "^7.37.4",
36
+ "eslint-plugin-react-hooks": "^5.2.0",
37
+ "globals": "^16.0.0",
38
+ "typescript": "^5.8.2",
39
+ "typescript-eslint": "^8.26.1"
40
+ },
41
+ "dependencies": {
42
+ "react": "^19.0.0",
43
+ "react-dom": "^19.0.0",
44
+ "react-hook-form": "^7.54.2"
45
+ }
46
+ }