UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

232 lines (221 loc) 9.91 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkQFG6ZOOTjs = require('./chunk-QFG6ZOOT.js'); var _chunk34ST3MKOjs = require('./chunk-34ST3MKO.js'); var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js'); // src/components/Modal/Modal.tsx var _react = require('react'); var _X = require('@phosphor-icons/react/dist/csr/X'); var _jsxruntime = require('react/jsx-runtime'); var SIZE_CLASSES = { xs: "max-w-[360px]", sm: "max-w-[420px]", md: "max-w-[510px]", lg: "max-w-[640px]", xl: "max-w-[970px]" }; var Modal = ({ isOpen, onClose, title, children, size = "md", className = "", closeOnEscape = true, footer, hideCloseButton = false, variant = "default", description, image, imageAlt, actionLink, actionLabel, contentClassName = "" }) => { const titleId = _react.useId.call(void 0, ); _react.useEffect.call(void 0, () => { if (!isOpen || !closeOnEscape) return; const handleEscape = (event) => { if (event.key === "Escape") { onClose(); } }; document.addEventListener("keydown", handleEscape); return () => document.removeEventListener("keydown", handleEscape); }, [isOpen, closeOnEscape, onClose]); _react.useEffect.call(void 0, () => { if (!isOpen) return; const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; const originalOverflow = document.body.style.overflow; const originalPaddingRight = document.body.style.paddingRight; document.body.style.overflow = "hidden"; if (scrollbarWidth > 0) { document.body.style.paddingRight = `${scrollbarWidth}px`; const overlay = document.createElement("div"); overlay.id = "modal-scrollbar-overlay"; overlay.style.cssText = ` position: fixed; top: 0; right: 0; width: ${scrollbarWidth}px; height: 100vh; background-color: rgb(0 0 0 / 0.6); z-index: 40; pointer-events: none; `; document.body.appendChild(overlay); } return () => { document.body.style.overflow = originalOverflow; document.body.style.paddingRight = originalPaddingRight; const overlay = document.getElementById("modal-scrollbar-overlay"); if (overlay) { overlay.remove(); } }; }, [isOpen]); if (!isOpen) return null; const sizeClasses = SIZE_CLASSES[size]; const baseClasses = "bg-secondary-50 rounded-3xl shadow-hard-shadow-2 border border-border-100 w-full mx-4 max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden"; const dialogResetClasses = "p-0 m-0 border-none outline-none static"; const modalClasses = _chunkTN3AYOMVjs.cn.call(void 0, baseClasses, sizeClasses, dialogResetClasses, className ); const normalizeUrl = (href) => /^https?:\/\//i.test(href) ? href : `https://${href}`; const handleActionClick = () => { if (actionLink) { window.open(normalizeUrl(actionLink), "_blank", "noopener,noreferrer"); } }; if (variant === "activity") { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-xs border-none p-0 m-0 w-full cursor-default", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "dialog", { className: modalClasses, "aria-labelledby": titleId, "aria-modal": "true", open: true, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-end p-6 pb-0", children: !hideCloseButton && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { onClick: onClose, className: "p-1 text-text-500 hover:text-text-700 hover:bg-background-50 rounded-md transition-colors focus:outline-none focus:ring-2 focus:ring-indicator-info focus:ring-offset-2", "aria-label": "Fechar modal", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _X.XIcon, { size: 18 }) } ) }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center px-6 pb-6 gap-5 flex-1 min-h-0 overflow-y-auto", children: [ image && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-center", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: image, alt: _nullishCoalesce(imageAlt, () => ( "")), className: "w-[122px] h-[122px] object-contain" } ) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { id: titleId, className: "text-lg font-semibold text-text-950 text-center", children: title } ), description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-sm font-normal text-text-400 text-center max-w-md leading-[21px]", children: description }), actionLink && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "w-full", children: [ (() => { const normalized = normalizeUrl(actionLink); const isYT = _chunkQFG6ZOOTjs.isYouTubeUrl.call(void 0, normalized); if (!isYT) return null; const id = _chunkQFG6ZOOTjs.getYouTubeVideoId.call(void 0, normalized); if (!id) { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "solid", action: "primary", size: "large", className: "w-full", onClick: handleActionClick, children: actionLabel || "Iniciar Atividade" } ); } return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "iframe", { src: _chunkQFG6ZOOTjs.getYouTubeEmbedUrl.call(void 0, id), className: "w-full aspect-video rounded-lg", allowFullScreen: true, allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture", title: "V\xEDdeo YouTube" } ); })(), !_chunkQFG6ZOOTjs.isYouTubeUrl.call(void 0, normalizeUrl(actionLink)) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "solid", action: "primary", size: "large", className: "w-full", onClick: handleActionClick, children: actionLabel || "Iniciar Atividade" } ) ] }) ] }) ] } ) }); } return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-xs border-none p-0 m-0 w-full cursor-default", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "dialog", { className: modalClasses, "aria-labelledby": titleId, "aria-modal": "true", open: true, children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center justify-between px-6 py-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { id: titleId, className: "text-lg font-semibold text-text-950", children: title }), !hideCloseButton && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { onClick: onClose, className: "p-1 text-text-500 hover:text-text-700 hover:bg-background-50 rounded-md transition-colors focus:outline-none focus:ring-2 focus:ring-indicator-info focus:ring-offset-2", "aria-label": "Fechar modal", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _X.XIcon, { size: 18 }) } ) ] }), children && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _chunkTN3AYOMVjs.cn.call(void 0, "px-6 pb-6 flex-1 min-h-0 overflow-y-auto", contentClassName ), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: _chunkTN3AYOMVjs.cn.call(void 0, "text-text-500 font-normal text-sm leading-6", _optionalChain([contentClassName, 'optionalAccess', _ => _.includes, 'call', _2 => _2("flex")]) && "flex flex-col flex-1 min-h-0" ), children } ) } ), footer && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-end gap-3 px-6 pb-6", children: footer }) ] } ) }); }; var Modal_default = Modal; exports.Modal_default = Modal_default; //# sourceMappingURL=chunk-TCLRDUMF.js.map