@rubenpazch/modal 0.0.0-stage → 0.1.0

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 CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # @rubenpazch/modal
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <!-- catalogo:inicio (generado por pnpm catalogo, no editar) -->
4
+
5
+ Ventana modal accesible: portal, foco retenido, Escape y clic fuera para cerrar, bloqueo del scroll, título y descripción anunciados.
6
+
7
+ - **Usar cuando:** Formularios cortos o detalles que requieren atención sin cambiar de página (editar un registro, ver un detalle).
8
+ - **Evitar cuando:** Confirmar una acción: usa ConfirmationDialog. Formularios largos o navegación lateral: usa Drawer.
9
+
10
+ Se recomienda instalar el paquete completo `@rubenpazch/ui` (incluye este). Por separado:
11
+
12
+ ```bash
13
+ npm install @rubenpazch/modal
14
+ ```
15
+
16
+ ## Modal
17
+
18
+ Ventana modal accesible: se monta en un portal, retiene el foco, bloquea el scroll de la
19
+ página y se cierra con Escape. Para confirmar acciones usa ConfirmationDialog.
20
+
21
+ | Prop | Tipo | Req. | Por defecto | Descripción |
22
+ | --------------------- | ---------------------------------------- | ---- | ----------- | --------------------------------------------------------------------------------- |
23
+ | `onClose` | `() => void` | sí | | Se llama al pedir cierre: botón ×, Escape o clic en el fondo. |
24
+ | `open` | `boolean` | sí | | Si el modal está abierto. |
25
+ | `children` | `ReactNode` | | | Contenido del modal. |
26
+ | `className` | `string` | | | Clase extra para la caja del modal. |
27
+ | `closeLabel` | `string` | | `Cerrar` | Texto accesible del botón ×. |
28
+ | `closeOnEscape` | `boolean` | | `true` | Cerrar con Escape (por defecto sí). |
29
+ | `closeOnOverlayClick` | `boolean` | | `true` | Cerrar al hacer clic en el fondo (por defecto sí). |
30
+ | `description` | `ReactNode` | | | Texto bajo el título (se anuncia como descripción). |
31
+ | `footer` | `ReactNode` | | | Pie: normalmente los botones de acción. |
32
+ | `role` | `"dialog" \| "alertdialog"` | | `dialog` | Rol del diálogo: `alertdialog` para confirmaciones que exigen respuesta. |
33
+ | `showCloseButton` | `boolean` | | `true` | Mostrar el botón × (por defecto sí). |
34
+ | `size` | `"sm" \| "md" \| "lg" \| "xl" \| "full"` | | `md` | Ancho máximo: sm (400px), md (520px, por defecto), lg (720px), xl (960px) o full. |
35
+ | `title` | `ReactNode` | | | Título (se anuncia como nombre del diálogo). |
36
+
37
+ Tipos: `ModalProps`, `ModalSize`.
38
+
39
+ <!-- catalogo:fin -->
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ export type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
3
+ export interface ModalProps {
4
+ /** Si el modal está abierto. */
5
+ open: boolean;
6
+ /** Se llama al pedir cierre: botón ×, Escape o clic en el fondo. */
7
+ onClose: () => void;
8
+ /** Título (se anuncia como nombre del diálogo). */
9
+ title?: React.ReactNode;
10
+ /** Texto bajo el título (se anuncia como descripción). */
11
+ description?: React.ReactNode;
12
+ /** Contenido del modal. */
13
+ children?: React.ReactNode;
14
+ /** Pie: normalmente los botones de acción. */
15
+ footer?: React.ReactNode;
16
+ /** Ancho máximo: sm (400px), md (520px, por defecto), lg (720px), xl (960px) o full. */
17
+ size?: ModalSize;
18
+ /** Cerrar al hacer clic en el fondo (por defecto sí). */
19
+ closeOnOverlayClick?: boolean;
20
+ /** Cerrar con Escape (por defecto sí). */
21
+ closeOnEscape?: boolean;
22
+ /** Mostrar el botón × (por defecto sí). */
23
+ showCloseButton?: boolean;
24
+ /** Rol del diálogo: `alertdialog` para confirmaciones que exigen respuesta. */
25
+ role?: "dialog" | "alertdialog";
26
+ /** Clase extra para la caja del modal. */
27
+ className?: string;
28
+ /** Texto accesible del botón ×. */
29
+ closeLabel?: string;
30
+ }
31
+ /**
32
+ * Ventana modal accesible: se monta en un portal, retiene el foco, bloquea el scroll de la
33
+ * página y se cierra con Escape. Para confirmar acciones usa ConfirmationDialog.
34
+ */
35
+ export default function Modal({ open, onClose, title, description, children, footer, size, closeOnOverlayClick, closeOnEscape, showCloseButton, role, className, closeLabel, }: ModalProps): React.ReactPortal | null;
36
+ //# sourceMappingURL=Modal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../src/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AASlE,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,oEAAoE;IACpE,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,mDAAmD;IACnD,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,wFAAwF;IACxF,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,yDAAyD;IACzD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,0CAA0C;IAC1C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2CAA2C;IAC3C,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,+EAA+E;IAC/E,IAAI,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;IAChC,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,IAAI,EACJ,OAAO,EACP,KAAK,EACL,WAAW,EACX,QAAQ,EACR,MAAM,EACN,IAAW,EACX,mBAA0B,EAC1B,aAAoB,EACpB,eAAsB,EACtB,IAAe,EACf,SAAS,EACT,UAAqB,GACtB,EAAE,UAAU,4BAoEZ"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),o=require("react"),l=require("react-dom"),n=require("@rubenpazch/shared");var a={overlay:"Modal-module_overlay__dvxvu",fade:"Modal-module_fade__bVLaB",dialog:"Modal-module_dialog__6Ubx3",rise:"Modal-module_rise__KydxI","size-sm":"Modal-module_size-sm__XUgUL","size-md":"Modal-module_size-md__ouRGU","size-lg":"Modal-module_size-lg__Q8JLj","size-xl":"Modal-module_size-xl__wDJYY","size-full":"Modal-module_size-full__2rRMt",header:"Modal-module_header__9lFoY",headings:"Modal-module_headings__HSZ1c",title:"Modal-module_title__oV44T",description:"Modal-module_description__Xsa-v",close:"Modal-module_close__o1bPa",body:"Modal-module_body__nopNs",footer:"Modal-module_footer__vHqz8"};!function(e,o){void 0===o&&(o={});var l=o.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===l&&n.firstChild?n.insertBefore(a,n.firstChild):n.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}(".Modal-module_overlay__dvxvu {\n position: fixed;\n inset: 0;\n z-index: 1000;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: var(--lb-space-4);\n background: var(--lb-color-overlay);\n animation: Modal-module_fade__bVLaB 140ms ease-out;\n}\n\n.Modal-module_dialog__6Ubx3 {\n display: flex;\n flex-direction: column;\n width: 100%;\n max-height: calc(100dvh - 2 * var(--lb-space-4));\n background: var(--lb-color-background);\n color: var(--lb-color-foreground);\n border: 1px solid var(--lb-color-border);\n border-radius: var(--lb-radius-xl);\n box-shadow: var(--lb-shadow-lg);\n font-family: var(--lb-font-sans);\n outline: none;\n animation: Modal-module_rise__KydxI 160ms ease-out;\n}\n\n.Modal-module_size-sm__XUgUL { max-width: 25rem; }\n.Modal-module_size-md__ouRGU { max-width: 32.5rem; }\n.Modal-module_size-lg__Q8JLj { max-width: 45rem; }\n.Modal-module_size-xl__wDJYY { max-width: 60rem; }\n.Modal-module_size-full__2rRMt { max-width: none; height: 100%; }\n\n.Modal-module_header__9lFoY {\n display: flex;\n align-items: flex-start;\n gap: var(--lb-space-3);\n padding: var(--lb-space-5) var(--lb-space-5) var(--lb-space-3);\n}\n\n.Modal-module_headings__HSZ1c {\n flex: 1;\n min-width: 0;\n}\n\n.Modal-module_title__oV44T {\n margin: 0;\n font-size: var(--lb-font-size-lg);\n font-weight: var(--lb-font-weight-semibold);\n line-height: var(--lb-line-height-snug);\n}\n\n.Modal-module_description__Xsa-v {\n margin: var(--lb-space-1) 0 0;\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-muted-foreground);\n}\n\n.Modal-module_close__o1bPa {\n flex: none;\n display: inline-flex;\n width: 2rem;\n height: 2rem;\n align-items: center;\n justify-content: center;\n padding: 0;\n border: 0;\n border-radius: var(--lb-radius-md);\n background: transparent;\n color: var(--lb-color-muted-foreground);\n cursor: pointer;\n}\n\n.Modal-module_close__o1bPa svg {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n.Modal-module_close__o1bPa:hover {\n background: var(--lb-color-muted);\n color: var(--lb-color-foreground);\n}\n\n.Modal-module_close__o1bPa:focus-visible {\n outline: 2px solid var(--lb-color-ring);\n outline-offset: 2px;\n}\n\n.Modal-module_body__nopNs {\n flex: 1;\n overflow-y: auto;\n padding: 0 var(--lb-space-5) var(--lb-space-5);\n font-size: var(--lb-font-size-sm);\n line-height: var(--lb-line-height-normal);\n}\n\n.Modal-module_footer__vHqz8 {\n display: flex;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: var(--lb-space-2);\n padding: var(--lb-space-4) var(--lb-space-5);\n border-top: 1px solid var(--lb-color-border);\n background: var(--lb-color-muted);\n border-radius: 0 0 var(--lb-radius-xl) var(--lb-radius-xl);\n}\n\n@keyframes Modal-module_fade__bVLaB {\n from { opacity: 0; }\n}\n\n@keyframes Modal-module_rise__KydxI {\n from { opacity: 0; transform: translateY(8px) scale(0.98); }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .Modal-module_overlay__dvxvu,\n .Modal-module_dialog__6Ubx3 {\n animation: none;\n }\n}\n\n@media (max-width: 480px) {\n .Modal-module_overlay__dvxvu {\n align-items: flex-end;\n padding: 0;\n }\n .Modal-module_dialog__6Ubx3 {\n max-width: none;\n border-radius: var(--lb-radius-xl) var(--lb-radius-xl) 0 0;\n max-height: 90dvh;\n }\n}\n");const d=(...e)=>e.filter(Boolean).join(" ");module.exports=function({open:r,onClose:i,title:s,description:t,children:u,footer:_,size:c="md",closeOnOverlayClick:m=!0,closeOnEscape:b=!0,showCloseButton:v=!0,role:h="dialog",className:f,closeLabel:x="Cerrar"}){const p=o.useId(),g=`${p}-titulo`,M=`${p}-descripcion`,y=o.useRef(null),[z,w]=o.useState(!1);return o.useEffect(()=>w(!0),[]),n.useEscapeKey(i,r&&b),n.useFocusTrap(y,r&&z),n.useLockBodyScroll(r),r&&z?l.createPortal(e.jsx("div",{className:a.overlay,"data-testid":"modal-overlay",onMouseDown:e=>{m&&e.target===e.currentTarget&&i()},children:e.jsxs("div",{ref:y,role:h,"aria-modal":"true","aria-labelledby":s?g:void 0,"aria-describedby":t?M:void 0,tabIndex:-1,className:d(a.dialog,a[`size-${c}`],f),children:[(s||v)&&e.jsxs("div",{className:a.header,children:[e.jsxs("div",{className:a.headings,children:[s&&e.jsx("h2",{id:g,className:a.title,children:s}),t&&e.jsx("p",{id:M,className:a.description,children:t})]}),v&&e.jsx("button",{type:"button",className:a.close,onClick:i,"aria-label":x,children:e.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z"})})})]}),void 0!==u&&e.jsx("div",{className:a.body,children:u}),_&&e.jsx("div",{className:a.footer,children:_})]})}),document.body):null};
2
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/Modal.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React, { useEffect, useId, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n useEscapeKey,\n useFocusTrap,\n useLockBodyScroll,\n} from \"@rubenpazch/shared\";\nimport styles from \"./Modal.module.css\";\n\nexport type ModalSize = \"sm\" | \"md\" | \"lg\" | \"xl\" | \"full\";\n\nexport interface ModalProps {\n /** Si el modal está abierto. */\n open: boolean;\n /** Se llama al pedir cierre: botón ×, Escape o clic en el fondo. */\n onClose: () => void;\n /** Título (se anuncia como nombre del diálogo). */\n title?: React.ReactNode;\n /** Texto bajo el título (se anuncia como descripción). */\n description?: React.ReactNode;\n /** Contenido del modal. */\n children?: React.ReactNode;\n /** Pie: normalmente los botones de acción. */\n footer?: React.ReactNode;\n /** Ancho máximo: sm (400px), md (520px, por defecto), lg (720px), xl (960px) o full. */\n size?: ModalSize;\n /** Cerrar al hacer clic en el fondo (por defecto sí). */\n closeOnOverlayClick?: boolean;\n /** Cerrar con Escape (por defecto sí). */\n closeOnEscape?: boolean;\n /** Mostrar el botón × (por defecto sí). */\n showCloseButton?: boolean;\n /** Rol del diálogo: `alertdialog` para confirmaciones que exigen respuesta. */\n role?: \"dialog\" | \"alertdialog\";\n /** Clase extra para la caja del modal. */\n className?: string;\n /** Texto accesible del botón ×. */\n closeLabel?: string;\n}\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/**\n * Ventana modal accesible: se monta en un portal, retiene el foco, bloquea el scroll de la\n * página y se cierra con Escape. Para confirmar acciones usa ConfirmationDialog.\n */\nexport default function Modal({\n open,\n onClose,\n title,\n description,\n children,\n footer,\n size = \"md\",\n closeOnOverlayClick = true,\n closeOnEscape = true,\n showCloseButton = true,\n role = \"dialog\",\n className,\n closeLabel = \"Cerrar\",\n}: ModalProps) {\n const id = useId();\n const titleId = `${id}-titulo`;\n const descId = `${id}-descripcion`;\n const dialogRef = useRef<HTMLDivElement>(null);\n // El portal necesita document: se monta después del primer render (seguro con SSR).\n const [mounted, setMounted] = useState(false);\n useEffect(() => setMounted(true), []);\n\n useEscapeKey(onClose, open && closeOnEscape);\n useFocusTrap(dialogRef, open && mounted);\n useLockBodyScroll(open);\n\n if (!open || !mounted) return null;\n\n return createPortal(\n <div\n className={styles.overlay}\n data-testid=\"modal-overlay\"\n onMouseDown={(e) => {\n if (closeOnOverlayClick && e.target === e.currentTarget) onClose();\n }}\n >\n <div\n ref={dialogRef}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descId : undefined}\n tabIndex={-1}\n className={cx(styles.dialog, styles[`size-${size}`], className)}\n >\n {(title || showCloseButton) && (\n <div className={styles.header}>\n <div className={styles.headings}>\n {title && (\n <h2 id={titleId} className={styles.title}>\n {title}\n </h2>\n )}\n {description && (\n <p id={descId} className={styles.description}>\n {description}\n </p>\n )}\n </div>\n {showCloseButton && (\n <button\n type=\"button\"\n className={styles.close}\n onClick={onClose}\n aria-label={closeLabel}\n >\n <svg viewBox=\"0 0 20 20\" fill=\"currentColor\" aria-hidden=\"true\">\n <path d=\"M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z\" />\n </svg>\n </button>\n )}\n </div>\n )}\n {children !== undefined && (\n <div className={styles.body}>{children}</div>\n )}\n {footer && <div className={styles.footer}>{footer}</div>}\n </div>\n </div>,\n document.body,\n );\n}\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","open","onClose","title","description","children","footer","size","closeOnOverlayClick","closeOnEscape","showCloseButton","role","className","closeLabel","id","useId","titleId","descId","dialogRef","useRef","mounted","setMounted","useState","useEffect","useEscapeKey","useFocusTrap","useLockBodyScroll","createPortal","_jsx","styles","overlay","onMouseDown","e","target","currentTarget","_jsxs","undefined","tabIndex","dialog","header","headings","close","onClick","viewBox","fill","d","body"],"mappings":"2tBAAA,SAAqBA,EAAKC,YACnBA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,2xGCeA,MAAMe,EAAK,IAAIC,IACbA,EAAEC,OAAOC,SAASC,KAAK,oBAMX,UAAgBC,KAC5BA,EAAIC,QACJA,EA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K,eAAc,cAAa,OAAMvC,SAC7DuB,EAAAA,IAAA,OAAA,CAAMiB,EAAE,mMAMJT,IAAb/B,GACCuB,EAAAA,WAAKhB,UAAWiB,EAAOiB,cAAOzC,IAE/BC,GAAUsB,EAAAA,IAAA,MAAA,CAAKhB,UAAWiB,EAAOvB,OAAMD,SAAGC,SAG/CtB,SAAS8D,MArDmB,IAuDhC","x_google_ignoreList":[0]}
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+
3
+ type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
4
+ interface ModalProps {
5
+ /** Si el modal está abierto. */
6
+ open: boolean;
7
+ /** Se llama al pedir cierre: botón ×, Escape o clic en el fondo. */
8
+ onClose: () => void;
9
+ /** Título (se anuncia como nombre del diálogo). */
10
+ title?: React.ReactNode;
11
+ /** Texto bajo el título (se anuncia como descripción). */
12
+ description?: React.ReactNode;
13
+ /** Contenido del modal. */
14
+ children?: React.ReactNode;
15
+ /** Pie: normalmente los botones de acción. */
16
+ footer?: React.ReactNode;
17
+ /** Ancho máximo: sm (400px), md (520px, por defecto), lg (720px), xl (960px) o full. */
18
+ size?: ModalSize;
19
+ /** Cerrar al hacer clic en el fondo (por defecto sí). */
20
+ closeOnOverlayClick?: boolean;
21
+ /** Cerrar con Escape (por defecto sí). */
22
+ closeOnEscape?: boolean;
23
+ /** Mostrar el botón × (por defecto sí). */
24
+ showCloseButton?: boolean;
25
+ /** Rol del diálogo: `alertdialog` para confirmaciones que exigen respuesta. */
26
+ role?: "dialog" | "alertdialog";
27
+ /** Clase extra para la caja del modal. */
28
+ className?: string;
29
+ /** Texto accesible del botón ×. */
30
+ closeLabel?: string;
31
+ }
32
+ /**
33
+ * Ventana modal accesible: se monta en un portal, retiene el foco, bloquea el scroll de la
34
+ * página y se cierra con Escape. Para confirmar acciones usa ConfirmationDialog.
35
+ */
36
+ declare function Modal({ open, onClose, title, description, children, footer, size, closeOnOverlayClick, closeOnEscape, showCloseButton, role, className, closeLabel, }: ModalProps): React.ReactPortal | null;
37
+
38
+ export { Modal as default };
39
+ export type { ModalProps, ModalSize };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{useId as l,useRef as n,useState as a,useEffect as d}from"react";import{createPortal as r}from"react-dom";import{useEscapeKey as i,useFocusTrap as t,useLockBodyScroll as s}from"@rubenpazch/shared";var m={overlay:"Modal-module_overlay__dvxvu",fade:"Modal-module_fade__bVLaB",dialog:"Modal-module_dialog__6Ubx3",rise:"Modal-module_rise__KydxI","size-sm":"Modal-module_size-sm__XUgUL","size-md":"Modal-module_size-md__ouRGU","size-lg":"Modal-module_size-lg__Q8JLj","size-xl":"Modal-module_size-xl__wDJYY","size-full":"Modal-module_size-full__2rRMt",header:"Modal-module_header__9lFoY",headings:"Modal-module_headings__HSZ1c",title:"Modal-module_title__oV44T",description:"Modal-module_description__Xsa-v",close:"Modal-module_close__o1bPa",body:"Modal-module_body__nopNs",footer:"Modal-module_footer__vHqz8"};!function(e,o){void 0===o&&(o={});var l=o.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===l&&n.firstChild?n.insertBefore(a,n.firstChild):n.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}(".Modal-module_overlay__dvxvu {\n position: fixed;\n inset: 0;\n z-index: 1000;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: var(--lb-space-4);\n background: var(--lb-color-overlay);\n animation: Modal-module_fade__bVLaB 140ms ease-out;\n}\n\n.Modal-module_dialog__6Ubx3 {\n display: flex;\n flex-direction: column;\n width: 100%;\n max-height: calc(100dvh - 2 * var(--lb-space-4));\n background: var(--lb-color-background);\n color: var(--lb-color-foreground);\n border: 1px solid var(--lb-color-border);\n border-radius: var(--lb-radius-xl);\n box-shadow: var(--lb-shadow-lg);\n font-family: var(--lb-font-sans);\n outline: none;\n animation: Modal-module_rise__KydxI 160ms ease-out;\n}\n\n.Modal-module_size-sm__XUgUL { max-width: 25rem; }\n.Modal-module_size-md__ouRGU { max-width: 32.5rem; }\n.Modal-module_size-lg__Q8JLj { max-width: 45rem; }\n.Modal-module_size-xl__wDJYY { max-width: 60rem; }\n.Modal-module_size-full__2rRMt { max-width: none; height: 100%; }\n\n.Modal-module_header__9lFoY {\n display: flex;\n align-items: flex-start;\n gap: var(--lb-space-3);\n padding: var(--lb-space-5) var(--lb-space-5) var(--lb-space-3);\n}\n\n.Modal-module_headings__HSZ1c {\n flex: 1;\n min-width: 0;\n}\n\n.Modal-module_title__oV44T {\n margin: 0;\n font-size: var(--lb-font-size-lg);\n font-weight: var(--lb-font-weight-semibold);\n line-height: var(--lb-line-height-snug);\n}\n\n.Modal-module_description__Xsa-v {\n margin: var(--lb-space-1) 0 0;\n font-size: var(--lb-font-size-sm);\n color: var(--lb-color-muted-foreground);\n}\n\n.Modal-module_close__o1bPa {\n flex: none;\n display: inline-flex;\n width: 2rem;\n height: 2rem;\n align-items: center;\n justify-content: center;\n padding: 0;\n border: 0;\n border-radius: var(--lb-radius-md);\n background: transparent;\n color: var(--lb-color-muted-foreground);\n cursor: pointer;\n}\n\n.Modal-module_close__o1bPa svg {\n width: 1.25rem;\n height: 1.25rem;\n}\n\n.Modal-module_close__o1bPa:hover {\n background: var(--lb-color-muted);\n color: var(--lb-color-foreground);\n}\n\n.Modal-module_close__o1bPa:focus-visible {\n outline: 2px solid var(--lb-color-ring);\n outline-offset: 2px;\n}\n\n.Modal-module_body__nopNs {\n flex: 1;\n overflow-y: auto;\n padding: 0 var(--lb-space-5) var(--lb-space-5);\n font-size: var(--lb-font-size-sm);\n line-height: var(--lb-line-height-normal);\n}\n\n.Modal-module_footer__vHqz8 {\n display: flex;\n flex-wrap: wrap;\n justify-content: flex-end;\n gap: var(--lb-space-2);\n padding: var(--lb-space-4) var(--lb-space-5);\n border-top: 1px solid var(--lb-color-border);\n background: var(--lb-color-muted);\n border-radius: 0 0 var(--lb-radius-xl) var(--lb-radius-xl);\n}\n\n@keyframes Modal-module_fade__bVLaB {\n from { opacity: 0; }\n}\n\n@keyframes Modal-module_rise__KydxI {\n from { opacity: 0; transform: translateY(8px) scale(0.98); }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .Modal-module_overlay__dvxvu,\n .Modal-module_dialog__6Ubx3 {\n animation: none;\n }\n}\n\n@media (max-width: 480px) {\n .Modal-module_overlay__dvxvu {\n align-items: flex-end;\n padding: 0;\n }\n .Modal-module_dialog__6Ubx3 {\n max-width: none;\n border-radius: var(--lb-radius-xl) var(--lb-radius-xl) 0 0;\n max-height: 90dvh;\n }\n}\n");const _=(...e)=>e.filter(Boolean).join(" ");function c({open:c,onClose:u,title:b,description:v,children:f,footer:h,size:p="md",closeOnOverlayClick:g=!0,closeOnEscape:x=!0,showCloseButton:M=!0,role:y="dialog",className:z,closeLabel:w="Cerrar"}){const N=l(),L=`${N}-titulo`,k=`${N}-descripcion`,C=n(null),[U,B]=a(!1);return d(()=>B(!0),[]),i(u,c&&x),t(C,c&&U),s(c),c&&U?r(e("div",{className:m.overlay,"data-testid":"modal-overlay",onMouseDown:e=>{g&&e.target===e.currentTarget&&u()},children:o("div",{ref:C,role:y,"aria-modal":"true","aria-labelledby":b?L:void 0,"aria-describedby":v?k:void 0,tabIndex:-1,className:_(m.dialog,m[`size-${p}`],z),children:[(b||M)&&o("div",{className:m.header,children:[o("div",{className:m.headings,children:[b&&e("h2",{id:L,className:m.title,children:b}),v&&e("p",{id:k,className:m.description,children:v})]}),M&&e("button",{type:"button",className:m.close,onClick:u,"aria-label":w,children:e("svg",{viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e("path",{d:"M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z"})})})]}),void 0!==f&&e("div",{className:m.body,children:f}),h&&e("div",{className:m.footer,children:h})]})}),document.body):null}export{c as default};
2
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/Modal.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React, { useEffect, useId, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n useEscapeKey,\n useFocusTrap,\n useLockBodyScroll,\n} from \"@rubenpazch/shared\";\nimport styles from \"./Modal.module.css\";\n\nexport type ModalSize = \"sm\" | \"md\" | \"lg\" | \"xl\" | \"full\";\n\nexport interface ModalProps {\n /** Si el modal está abierto. */\n open: boolean;\n /** Se llama al pedir cierre: botón ×, Escape o clic en el fondo. */\n onClose: () => void;\n /** Título (se anuncia como nombre del diálogo). */\n title?: React.ReactNode;\n /** Texto bajo el título (se anuncia como descripción). */\n description?: React.ReactNode;\n /** Contenido del modal. */\n children?: React.ReactNode;\n /** Pie: normalmente los botones de acción. */\n footer?: React.ReactNode;\n /** Ancho máximo: sm (400px), md (520px, por defecto), lg (720px), xl (960px) o full. */\n size?: ModalSize;\n /** Cerrar al hacer clic en el fondo (por defecto sí). */\n closeOnOverlayClick?: boolean;\n /** Cerrar con Escape (por defecto sí). */\n closeOnEscape?: boolean;\n /** Mostrar el botón × (por defecto sí). */\n showCloseButton?: boolean;\n /** Rol del diálogo: `alertdialog` para confirmaciones que exigen respuesta. */\n role?: \"dialog\" | \"alertdialog\";\n /** Clase extra para la caja del modal. */\n className?: string;\n /** Texto accesible del botón ×. */\n closeLabel?: string;\n}\n\nconst cx = (...c: Array<string | false | undefined>) =>\n c.filter(Boolean).join(\" \");\n\n/**\n * Ventana modal accesible: se monta en un portal, retiene el foco, bloquea el scroll de la\n * página y se cierra con Escape. Para confirmar acciones usa ConfirmationDialog.\n */\nexport default function Modal({\n open,\n onClose,\n title,\n description,\n children,\n footer,\n size = \"md\",\n closeOnOverlayClick = true,\n closeOnEscape = true,\n showCloseButton = true,\n role = \"dialog\",\n className,\n closeLabel = \"Cerrar\",\n}: ModalProps) {\n const id = useId();\n const titleId = `${id}-titulo`;\n const descId = `${id}-descripcion`;\n const dialogRef = useRef<HTMLDivElement>(null);\n // El portal necesita document: se monta después del primer render (seguro con SSR).\n const [mounted, setMounted] = useState(false);\n useEffect(() => setMounted(true), []);\n\n useEscapeKey(onClose, open && closeOnEscape);\n useFocusTrap(dialogRef, open && mounted);\n useLockBodyScroll(open);\n\n if (!open || !mounted) return null;\n\n return createPortal(\n <div\n className={styles.overlay}\n data-testid=\"modal-overlay\"\n onMouseDown={(e) => {\n if (closeOnOverlayClick && e.target === e.currentTarget) onClose();\n }}\n >\n <div\n ref={dialogRef}\n role={role}\n aria-modal=\"true\"\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descId : undefined}\n tabIndex={-1}\n className={cx(styles.dialog, styles[`size-${size}`], className)}\n >\n {(title || showCloseButton) && (\n <div className={styles.header}>\n <div className={styles.headings}>\n {title && (\n <h2 id={titleId} className={styles.title}>\n {title}\n </h2>\n )}\n {description && (\n <p id={descId} className={styles.description}>\n {description}\n </p>\n )}\n </div>\n {showCloseButton && (\n <button\n type=\"button\"\n className={styles.close}\n onClick={onClose}\n aria-label={closeLabel}\n >\n <svg viewBox=\"0 0 20 20\" fill=\"currentColor\" aria-hidden=\"true\">\n <path d=\"M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z\" />\n </svg>\n </button>\n )}\n </div>\n )}\n {children !== undefined && (\n <div className={styles.body}>{children}</div>\n )}\n {footer && <div className={styles.footer}>{footer}</div>}\n </div>\n </div>,\n document.body,\n );\n}\n"],"names":["css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","cx","c","filter","Boolean","join","Modal","open","onClose","title","description","children","footer","size","closeOnOverlayClick","closeOnEscape","showCloseButton","role","className","closeLabel","id","useId","titleId","descId","dialogRef","useRef","mounted","setMounted","useState","useEffect","useEscapeKey","useFocusTrap","useLockBodyScroll","createPortal","_jsx","styles","overlay","onMouseDown","e","target","currentTarget","_jsxs","undefined","tabIndex","dialog","header","headings","close","onClick","viewBox","fill","d","body"],"mappings":"81BAAA,SAAqBA,EAAKC,YACnBA,IAAiBA,EAAM,CAAA,GAC5B,IAAIC,EAAWD,EAAIC,SAEnB,GAAgC,oBAAbC,SAAnB,CAEA,IAAIC,EAAOD,SAASC,MAAQD,SAASE,qBAAqB,QAAQ,GAC9DC,EAAQH,SAASI,cAAc,SACnCD,EAAME,KAAO,WAEI,QAAbN,GACEE,EAAKK,WACPL,EAAKM,aAAaJ,EAAOF,EAAKK,YAKhCL,EAAKO,YAAYL,GAGfA,EAAMM,WACRN,EAAMM,WAAWC,QAAUb,EAE3BM,EAAMK,YAAYR,SAASW,eAAed,GAnBW,CAqBzD,2xGCeA,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AAK,eAAc,cAAa,OAAMvC,SAC7DuB,EAAA,OAAA,CAAMiB,EAAE,mMAMJT,IAAb/B,GACCuB,SAAKhB,UAAWiB,EAAOiB,cAAOzC,IAE/BC,GAAUsB,EAAA,MAAA,CAAKhB,UAAWiB,EAAOvB,OAAMD,SAAGC,SAG/CvB,SAAS+D,MArDmB,IAuDhC","x_google_ignoreList":[0]}
package/package.json CHANGED
@@ -1,6 +1,78 @@
1
1
  {
2
2
  "name": "@rubenpazch/modal",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Ventana modal accesible (portal, foco retenido, Escape, bloqueo de scroll)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/rubenpazch/lbyte-ui-library.git",
8
+ "directory": "packages/modal"
9
+ },
10
+ "license": "MIT",
11
+ "main": "dist/index.cjs.js",
12
+ "module": "dist/index.esm.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.esm.js",
18
+ "require": "./dist/index.cjs.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "sideEffects": [
25
+ "**/*.css"
26
+ ],
27
+ "peerDependencies": {
28
+ "react": "^19.2.3",
29
+ "react-dom": "^19.2.3",
30
+ "@rubenpazch/tokens": "0.4.0"
31
+ },
32
+ "dependencies": {
33
+ "@rubenpazch/shared": "5.2.0"
34
+ },
35
+ "devDependencies": {
36
+ "@rollup/plugin-commonjs": "^29.0.3",
37
+ "@rollup/plugin-node-resolve": "^16.0.3",
38
+ "@rollup/plugin-terser": "^1.0.0",
39
+ "@rollup/plugin-typescript": "^12.3.0",
40
+ "@testing-library/react": "^16.3.3",
41
+ "@types/jest": "^30.0.0",
42
+ "@types/react": "^19.2.18",
43
+ "@types/react-dom": "^19.2.5",
44
+ "autoprefixer": "^10.5.4",
45
+ "eslint": "^9.39.5",
46
+ "identity-obj-proxy": "^3.0.0",
47
+ "jest": "^30.5.0",
48
+ "jest-environment-jsdom": "^30.5.0",
49
+ "postcss": "^8.5.26",
50
+ "prettier": "^3.9.6",
51
+ "react": "^19.2.8",
52
+ "react-dom": "^19.2.8",
53
+ "rollup": "^4.63.1",
54
+ "rollup-plugin-dts": "^6.5.1",
55
+ "rollup-plugin-postcss": "^4.0.2",
56
+ "rollup-plugin-typescript2": "^0.37.0",
57
+ "tslib": "^2.8.1",
58
+ "typescript": "^6.0.3",
59
+ "@rubenpazch/eslint-config": "4.0.0",
60
+ "@rubenpazch/typescript-config": "3.0.0"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "lbyte": {
66
+ "categoria": "retroalimentacion",
67
+ "resumen": "Ventana modal accesible: portal, foco retenido, Escape y clic fuera para cerrar, bloqueo del scroll, título y descripción anunciados.",
68
+ "usarCuando": "Formularios cortos o detalles que requieren atención sin cambiar de página (editar un registro, ver un detalle).",
69
+ "evitarCuando": "Confirmar una acción: usa ConfirmationDialog. Formularios largos o navegación lateral: usa Drawer."
70
+ },
71
+ "scripts": {
72
+ "build": "rollup -c",
73
+ "test": "jest --passWithNoTests",
74
+ "test:watch": "jest --watch",
75
+ "lint": "eslint src",
76
+ "clean": "rm -rf dist"
77
+ }
6
78
  }