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.
Files changed (48) hide show
  1. package/README-ES.md +217 -217
  2. package/README.md +216 -216
  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 +7 -17
  6. package/dist/components/make-select/make-select.js +7 -17
  7. package/dist/components/make-textarea/make-textarea.js +7 -17
  8. package/dist/components/make-toggle/make-toggle.js +7 -17
  9. package/dist/components/portal/portal.js +7 -17
  10. package/dist/context/component/component-state.js +7 -17
  11. package/dist/interfaces/modal.d.ts +1 -0
  12. package/dist/modal.js +38 -19
  13. package/eslint.config.mjs +14 -14
  14. package/examples/enable-if.ts +127 -127
  15. package/examples/live-data.ts +61 -61
  16. package/examples/render-if.ts +128 -128
  17. package/examples/simple.ts +74 -74
  18. package/index.ts +5 -5
  19. package/package.json +46 -47
  20. package/src/components/input-upload/input-upload.tsx +67 -67
  21. package/src/components/make-button/make-button.tsx +18 -18
  22. package/src/components/make-description/make-description.tsx +15 -15
  23. package/src/components/make-input/make-input.tsx +53 -53
  24. package/src/components/make-select/make-select.tsx +55 -55
  25. package/src/components/make-textarea/make-textarea.tsx +53 -53
  26. package/src/components/make-toggle/make-toggle.tsx +53 -53
  27. package/src/components/make-upload/make-upload.tsx +40 -40
  28. package/src/components/portal/portal.tsx +37 -37
  29. package/src/context/component/component-state.tsx +17 -17
  30. package/src/hooks/field-render.ts +109 -109
  31. package/src/hooks/modal-handler.ts +38 -38
  32. package/src/interfaces/component-state.ts +33 -33
  33. package/src/interfaces/field.ts +37 -37
  34. package/src/interfaces/input-upload.ts +21 -21
  35. package/src/interfaces/make-button.ts +19 -19
  36. package/src/interfaces/make-description.ts +14 -14
  37. package/src/interfaces/make-field-group.ts +14 -14
  38. package/src/interfaces/make-input.ts +14 -14
  39. package/src/interfaces/make-select.ts +15 -15
  40. package/src/interfaces/make-textarea.ts +11 -11
  41. package/src/interfaces/make-toggle.ts +9 -9
  42. package/src/interfaces/make-upload.ts +14 -14
  43. package/src/interfaces/modal.ts +47 -46
  44. package/src/interfaces/option.ts +3 -3
  45. package/src/interfaces/portal.ts +8 -8
  46. package/src/modal.tsx +196 -164
  47. package/src/tools/general.ts +8 -8
  48. package/tsconfig.json +13 -13
package/README-ES.md CHANGED
@@ -1,217 +1,217 @@
1
- # dynamic-modal
2
-
3
- `dynamic-modal` es una librería construida en typescript para crear modales reutilizables en aplicaciones React y Next.js, utilizando JSON para configurar su estructura sin necesidad de escribir HTML. Esto facilita su construcción y personalización, permitiendo abrir y cerrar modales mediante un custom hook.
4
-
5
- ## Requisitos
6
-
7
- Para que `dynamic-modal` funcione correctamente, debes instalar las siguientes dependencias:
8
-
9
- - React
10
-
11
- Además, es compatible con **Next.js**.
12
-
13
- ## Instalación
14
-
15
- Puedes instalar la librería a través de npm:
16
-
17
- ```bash
18
- npm install dynamic-modal
19
- ```
20
-
21
- ## Configuración para Next.js (14 o 15)
22
- Define los componentes que seran usados por el modal, crea el archivo y configura todos los componentes del modal. Aqui un ejemplo utilizando HeroUI (anteriormente NextUI):
23
-
24
- ```jsx
25
- 'use client'
26
- import { Autocomplete, AutocompleteItem, Button, Input, Select, SelectItem, Switch, Textarea } from "@heroui/react";
27
- import { IComponentState } from "dynamic-modal/src/interfaces/component-state";
28
-
29
- export const ModalComponents: IComponentState = {
30
- ModalButtonCancel: (props) => {
31
- return (
32
- <Button
33
- {...props}
34
- color={props.color as "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined}
35
- variant={'bordered'}
36
- >
37
- {props.text}
38
- </Button>
39
- )
40
- },
41
- ModalButtonAction: (props) => {
42
- return (
43
- <Button
44
- {...props}
45
- color={props.color as "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined}
46
- variant={'solid'}
47
- >
48
- {props.text}
49
- </Button>)
50
- },
51
- Button: ({ text, ...props }) => {
52
- return (
53
- <Button
54
- {...props}
55
- color={props.color as "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined}
56
- variant={props.variant as "flat" | "bordered" | "solid" | "light" | "faded" | "shadow" | "ghost" | undefined}
57
- >
58
- {text}
59
- </Button>)
60
- },
61
- Input: ({ invalid, error, disabled, onChange, ...props }) => {
62
- return (
63
- <Input
64
- {...props}
65
- onValueChange={onChange}
66
- errorMessage={error?.message}
67
- isInvalid={invalid}
68
- isDisabled={disabled}
69
- />
70
- )
71
- },
72
- Select: ({ options, invalid, error, isMulti, isSearch, disabled, onChange, value, ...props }) => {
73
- return (
74
- !isSearch ?
75
- <Select
76
- {...props}
77
- selectedKeys={isMulti ? value : [value]}
78
- onSelectionChange={onChange}
79
- selectionMode={isMulti ? 'multiple' : 'single'}
80
- errorMessage={error?.message}
81
- isInvalid={invalid}
82
- isDisabled={disabled}
83
- >
84
- {options.map((option) => (
85
- <SelectItem key={option.id}>{option.name}</SelectItem>
86
- ))}
87
- </Select> :
88
- <Autocomplete
89
- {...props}
90
- selectedKey={value}
91
- onSelectionChange={onChange}
92
- errorMessage={error?.message}
93
- isInvalid={invalid}
94
- isDisabled={disabled}
95
- >
96
- {options.map((item) => (
97
- <AutocompleteItem key={item.id}>{item.name}</AutocompleteItem>
98
- ))}
99
- </Autocomplete>
100
- )
101
- },
102
- Textarea: ({ invalid, error, disabled, ...props }) => {
103
- return (
104
- <Textarea
105
- {...props}
106
- errorMessage={error?.message}
107
- isInvalid={invalid}
108
- isDisabled={disabled}
109
- />
110
- )
111
- },
112
- Toggle: ({ value, onChange, label, invalid, ...props }) => {
113
- return(
114
- <Switch {...props} isSelected={value} onValueChange={onChange}>
115
- {label}
116
- </Switch>
117
- )
118
- }
119
- }
120
- ```
121
-
122
- En el provider principal de tu aplicación Next.js, importa tus componentes del modal (definidos anteriormente) y envuelve tu aplicación con el componente `ComponentState` para que `dynamic-modal` funcione adecuadamente. Aquí un ejemplo:
123
-
124
- ```jsx
125
- import { ComponentState } from 'dynamic-modal'
126
- import { ModalComponents } from "@data/modal-component/modal-component";
127
-
128
- function Provider({ children }: Readonly<{ children: ReactNode }>) {
129
- return (
130
- <ComponentState components={ModalComponents}>
131
- <Component {...pageProps} />
132
- </ComponentState>
133
- );
134
- }
135
-
136
- export default Provider;
137
-
138
- ```
139
- En el layout principal crea el `portal` para el modal (este componente utiliza react portal)
140
-
141
- ```jsx
142
- //imports...
143
-
144
- export default function RootLayout ({
145
- children
146
- }: Readonly<{
147
- children: ReactNode;
148
- }>) {
149
- return (
150
- <html lang="en">
151
- <body className={inter.className}>
152
- <Provider>
153
- {children}
154
- </Provider>
155
- <div id='modal-portal'/>
156
- </body>
157
- </html>
158
- )
159
- }
160
- ```
161
-
162
- ## Setup for Next.js 13 o mas antiguo
163
- Edita el archivo llamado `_document.tsx` y crea el `portal` para el modal (este componente utiliza react portal)
164
-
165
- ```jsx
166
- import { Html, Head, Main, NextScript } from 'next/document'
167
-
168
- export default function Document () {
169
- return (
170
- <Html>
171
- <Head />
172
- <body>
173
- <Main />
174
- <div id='modal-portal'/>
175
- <NextScript />
176
- </body>
177
- </Html>
178
- )
179
- }
180
- ```
181
-
182
- ## Uso
183
- Para controlar la apertura y cierre del modal, obtén el custom hook `useModalHandler` y llama a `openModal` cuando necesites mostrar el modal.
184
-
185
- ```jsx
186
- import { useModalHandler, DynamicModal } from 'dynamic-modal';
187
- import { Button } from '@nextui-org/react';
188
- //Crea el modal, importa y usa
189
- import testModal from '@modal-config/test';
190
-
191
- function ExampleComponent() {
192
- const { openModal, modalProps } = useModalHandler();
193
-
194
- return (
195
- <>
196
- <Button
197
- onClick={() => {
198
- openModal(testModal.default({}, (data) => {
199
- console.log('modal data', data);
200
- }));
201
- }}
202
- >
203
- Open modal
204
- </Button>
205
-
206
- <DynamicModal {...modalProps} />
207
- </>
208
- );
209
- }
210
-
211
- export default ExampleComponent;
212
-
213
- ```
214
-
215
- ## Ejemplos
216
- La carpeta `examples` en el repositorio contiene distintos modos de configuración para ayudarte a personalizar tu modal.
217
-
1
+ # dynamic-modal
2
+
3
+ `dynamic-modal` es una librería construida en typescript para crear modales reutilizables en aplicaciones React y Next.js, utilizando JSON para configurar su estructura sin necesidad de escribir HTML. Esto facilita su construcción y personalización, permitiendo abrir y cerrar modales mediante un custom hook.
4
+
5
+ ## Requisitos
6
+
7
+ Para que `dynamic-modal` funcione correctamente, debes instalar las siguientes dependencias:
8
+
9
+ - React
10
+
11
+ Además, es compatible con **Next.js**.
12
+
13
+ ## Instalación
14
+
15
+ Puedes instalar la librería a través de npm:
16
+
17
+ ```bash
18
+ npm install dynamic-modal
19
+ ```
20
+
21
+ ## Configuración para Next.js (14 o 15)
22
+ Define los componentes que seran usados por el modal, crea el archivo y configura todos los componentes del modal. Aqui un ejemplo utilizando HeroUI (anteriormente NextUI):
23
+
24
+ ```jsx
25
+ 'use client'
26
+ import { Autocomplete, AutocompleteItem, Button, Input, Select, SelectItem, Switch, Textarea } from "@heroui/react"
27
+ import { IComponentState } from "dynamic-modal/src/interfaces/component-state"
28
+
29
+ export const ModalComponents: IComponentState = {
30
+ ModalButtonCancel: (props) => {
31
+ return (
32
+ <Button
33
+ {...props}
34
+ color={props.color as "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined}
35
+ variant={'bordered'}
36
+ >
37
+ {props.text}
38
+ </Button>
39
+ )
40
+ },
41
+ ModalButtonAction: (props) => {
42
+ return (
43
+ <Button
44
+ {...props}
45
+ color={props.color as "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined}
46
+ variant={'solid'}
47
+ >
48
+ {props.text}
49
+ </Button>)
50
+ },
51
+ Button: ({ text, ...props }) => {
52
+ return (
53
+ <Button
54
+ {...props}
55
+ color={props.color as "default" | "primary" | "secondary" | "success" | "warning" | "danger" | undefined}
56
+ variant={props.variant as "flat" | "bordered" | "solid" | "light" | "faded" | "shadow" | "ghost" | undefined}
57
+ >
58
+ {text}
59
+ </Button>)
60
+ },
61
+ Input: ({ invalid, error, disabled, onChange, ...props }) => {
62
+ return (
63
+ <Input
64
+ {...props}
65
+ onValueChange={onChange}
66
+ errorMessage={error?.message}
67
+ isInvalid={invalid}
68
+ isDisabled={disabled}
69
+ />
70
+ )
71
+ },
72
+ Select: ({ options, invalid, error, isMulti, isSearch, disabled, onChange, value, ...props }) => {
73
+ return (
74
+ !isSearch ?
75
+ <Select
76
+ {...props}
77
+ selectedKeys={isMulti ? value : [value]}
78
+ onSelectionChange={onChange}
79
+ selectionMode={isMulti ? 'multiple' : 'single'}
80
+ errorMessage={error?.message}
81
+ isInvalid={invalid}
82
+ isDisabled={disabled}
83
+ >
84
+ {options.map((option) => (
85
+ <SelectItem key={option.id}>{option.name}</SelectItem>
86
+ ))}
87
+ </Select> :
88
+ <Autocomplete
89
+ {...props}
90
+ selectedKey={value}
91
+ onSelectionChange={onChange}
92
+ errorMessage={error?.message}
93
+ isInvalid={invalid}
94
+ isDisabled={disabled}
95
+ >
96
+ {options.map((item) => (
97
+ <AutocompleteItem key={item.id}>{item.name}</AutocompleteItem>
98
+ ))}
99
+ </Autocomplete>
100
+ )
101
+ },
102
+ Textarea: ({ invalid, error, disabled, ...props }) => {
103
+ return (
104
+ <Textarea
105
+ {...props}
106
+ errorMessage={error?.message}
107
+ isInvalid={invalid}
108
+ isDisabled={disabled}
109
+ />
110
+ )
111
+ },
112
+ Toggle: ({ value, onChange, label, invalid, ...props }) => {
113
+ return(
114
+ <Switch {...props} isSelected={value} onValueChange={onChange}>
115
+ {label}
116
+ </Switch>
117
+ )
118
+ }
119
+ }
120
+ ```
121
+
122
+ En el provider principal de tu aplicación Next.js, importa tus componentes del modal (definidos anteriormente) y envuelve tu aplicación con el componente `ComponentState` para que `dynamic-modal` funcione adecuadamente. Aquí un ejemplo:
123
+
124
+ ```jsx
125
+ import { ComponentState } from 'dynamic-modal'
126
+ import { ModalComponents } from "@data/modal-component/modal-component"
127
+
128
+ function Provider({ children }: Readonly<{ children: ReactNode }>) {
129
+ return (
130
+ <ComponentState components={ModalComponents}>
131
+ <Component {...pageProps} />
132
+ </ComponentState>
133
+ )
134
+ }
135
+
136
+ export default Provider
137
+
138
+ ```
139
+ En el layout principal crea el `portal` para el modal (este componente utiliza react portal)
140
+
141
+ ```jsx
142
+ //imports...
143
+
144
+ export default function RootLayout ({
145
+ children
146
+ }: Readonly<{
147
+ children: ReactNode
148
+ }>) {
149
+ return (
150
+ <html lang="en">
151
+ <body className={inter.className}>
152
+ <Provider>
153
+ {children}
154
+ </Provider>
155
+ <div id='modal-portal'/>
156
+ </body>
157
+ </html>
158
+ )
159
+ }
160
+ ```
161
+
162
+ ## Setup for Next.js 13 o mas antiguo
163
+ Edita el archivo llamado `_document.tsx` y crea el `portal` para el modal (este componente utiliza react portal)
164
+
165
+ ```jsx
166
+ import { Html, Head, Main, NextScript } from 'next/document'
167
+
168
+ export default function Document () {
169
+ return (
170
+ <Html>
171
+ <Head />
172
+ <body>
173
+ <Main />
174
+ <div id='modal-portal'/>
175
+ <NextScript />
176
+ </body>
177
+ </Html>
178
+ )
179
+ }
180
+ ```
181
+
182
+ ## Uso
183
+ Para controlar la apertura y cierre del modal, obtén el custom hook `useModalHandler` y llama a `openModal` cuando necesites mostrar el modal.
184
+
185
+ ```jsx
186
+ import { useModalHandler, DynamicModal } from 'dynamic-modal'
187
+ import { Button } from '@nextui-org/react'
188
+ //Crea el modal, importa y usa
189
+ import testModal from '@modal-config/test'
190
+
191
+ function ExampleComponent() {
192
+ const { openModal, modalProps } = useModalHandler()
193
+
194
+ return (
195
+ <>
196
+ <Button
197
+ onClick={() => {
198
+ openModal(testModal.default({}, (data) => {
199
+ console.log('modal data', data)
200
+ }))
201
+ }}
202
+ >
203
+ Open modal
204
+ </Button>
205
+
206
+ <DynamicModal {...modalProps} />
207
+ </>
208
+ )
209
+ }
210
+
211
+ export default ExampleComponent
212
+
213
+ ```
214
+
215
+ ## Ejemplos
216
+ La carpeta `examples` en el repositorio contiene distintos modos de configuración para ayudarte a personalizar tu modal.
217
+