UNPKG

analytica-frontend-lib

Version:

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

138 lines (128 loc) 4.97 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunk34ST3MKOjs = require('./chunk-34ST3MKO.js'); var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js'); // src/components/AlertDialog/AlertDialog.tsx var _react = require('react'); var _jsxruntime = require('react/jsx-runtime'); var SIZE_CLASSES = { "extra-small": "w-screen max-w-[324px]", small: "w-screen max-w-[378px]", medium: "w-screen max-w-[459px]", large: "w-screen max-w-[578px]", "extra-large": "w-screen max-w-[912px]" }; var AlertDialog = _react.forwardRef.call(void 0, ({ description, cancelButtonLabel = "Cancelar", submitButtonLabel = "Deletar", title, isOpen, closeOnBackdropClick = true, closeOnEscape = true, className = "", onSubmit, onChangeOpen, submitValue, onCancel, cancelValue, size = "medium", submitAction = "negative", ...props }, ref) => { _react.useEffect.call(void 0, () => { if (!isOpen || !closeOnEscape) return; const handleEscape = (event) => { if (event.key === "Escape") { onChangeOpen(false); } }; document.addEventListener("keydown", handleEscape); return () => document.removeEventListener("keydown", handleEscape); }, [isOpen, closeOnEscape]); _react.useEffect.call(void 0, () => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = "unset"; } return () => { document.body.style.overflow = "unset"; }; }, [isOpen]); const handleBackdropClick = (event) => { if (event.target === event.currentTarget && closeOnBackdropClick) { onChangeOpen(false); } }; const handleBackdropKeyDown = (event) => { if (event.key === "Escape" && closeOnEscape) { onChangeOpen(false); } }; const handleSubmit = () => { onChangeOpen(false); _optionalChain([onSubmit, 'optionalCall', _ => _(submitValue)]); }; const handleCancel = () => { onChangeOpen(false); _optionalChain([onCancel, 'optionalCall', _2 => _2(cancelValue)]); }; const sizeClasses = SIZE_CLASSES[size]; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: isOpen && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm", onClick: handleBackdropClick, onKeyDown: handleBackdropKeyDown, "data-testid": "alert-dialog-overlay", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { ref, className: _chunkTN3AYOMVjs.cn.call(void 0, "bg-background border border-border-100 rounded-lg shadow-lg p-6 m-3", sizeClasses, className ), ...props, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { id: "alert-dialog-title", className: "pb-3 text-xl font-semibold text-text-950", children: title } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { id: "alert-dialog-description", className: "text-text-700 text-sm", children: description } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-row items-center justify-end pt-4 gap-3", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "outline", size: "small", onClick: handleCancel, children: cancelButtonLabel }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "solid", size: "small", action: submitAction, onClick: handleSubmit, children: submitButtonLabel } ) ] }) ] } ) } ) }); } ); AlertDialog.displayName = "AlertDialog"; exports.AlertDialog = AlertDialog; //# sourceMappingURL=chunk-Q7THVSHR.js.map