infinity-forge
Version:
79 lines • 5.17 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Modal = Modal;
var jsx_runtime_1 = require("react/jsx-runtime");
var overlay_1 = require("../overlay/index.js");
var icons_1 = require("../../../ui/icons/index.js");
var hooks_1 = require("../../../ui/hooks/index.js");
var S = __importStar(require("./styles.js"));
var react_1 = require("react");
function Modal(_a) {
var open = _a.open, onClose = _a.onClose, title = _a.title, children = _a.children, actions = _a.actions, message = _a.message, _b = _a.confirmText, confirmText = _b === void 0 ? 'Confirmar' : _b, onConfirm = _a.onConfirm, _c = _a.cancelText, cancelText = _c === void 0 ? 'Cancelar' : _c, onCancel = _a.onCancel, styles = _a.styles, _d = _a.className, className = _d === void 0 ? '' : _d, ModalStyles = _a.ModalStyles, stylesContent = _a.stylesContent, onCloseElement = _a.onCloseElement, hideCloseButton = _a.hideCloseButton, disabledClickOverlay = _a.disabledClickOverlay;
var shouldRender = (0, hooks_1.useMountTransition)(open, 300);
var keyboardOpenRef = (0, react_1.useRef)(false);
(0, react_1.useEffect)(function () {
var vv = window.visualViewport;
var update = function () {
var opened = vv && window.outerHeight - vv.height > 100;
keyboardOpenRef.current = opened;
};
vv === null || vv === void 0 ? void 0 : vv.addEventListener('resize', update);
window.addEventListener('resize', update);
update();
return function () {
vv === null || vv === void 0 ? void 0 : vv.removeEventListener('resize', update);
window.removeEventListener('resize', update);
};
}, []);
function handleConfirm() {
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm();
}
function handleCancel() {
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
onClose();
}
var onClick = disabledClickOverlay ? undefined : onClose;
var Wrapper = ModalStyles !== null && ModalStyles !== void 0 ? ModalStyles : (function (_a) {
var children = _a.children;
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
});
if (!shouldRender)
return null;
return ((0, jsx_runtime_1.jsx)(overlay_1.Overlay, { isExiting: !open, onClick: onClick, children: (0, jsx_runtime_1.jsx)(Wrapper, { children: (0, jsx_runtime_1.jsxs)(S.Modal, { style: styles, "$isExiting": !open, className: "modal-content ".concat(className), onClick: function (e) {
e.stopPropagation();
}, children: [(title || !hideCloseButton) && ((0, jsx_runtime_1.jsxs)("h2", { className: 'title', children: [(0, jsx_runtime_1.jsx)("span", { className: 'title_content', children: title && title }), !hideCloseButton && onCloseElement && onCloseElement({ onClose: onClose }), !hideCloseButton && !onCloseElement && ((0, jsx_runtime_1.jsx)("button", { className: 'close-button', type: 'button', onClick: onClose, children: (0, jsx_runtime_1.jsx)(icons_1.Icon, { name: 'IconClose' }) }))] })), (0, jsx_runtime_1.jsxs)("div", { style: stylesContent, className: 'content_modal_infinity_forge', children: [message && (0, jsx_runtime_1.jsx)("p", { className: 'message', children: message }), children, (actions || onCancel || onConfirm) && ((0, jsx_runtime_1.jsxs)("div", { className: 'actions_modal_infinity_forge', children: [onCancel && (0, jsx_runtime_1.jsx)("button", { onClick: handleCancel, children: cancelText }), onConfirm && (0, jsx_runtime_1.jsx)("button", { onClick: handleConfirm, children: confirmText }), actions && (0, jsx_runtime_1.jsx)("div", { className: 'custom_actions_modal_infinity_forge', children: actions })] }))] })] }) }) }));
}
//# sourceMappingURL=component.js.map