UNPKG

@kbfront/kb-ui

Version:

KB React UI Library

79 lines 4.97 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EModalAnimation = exports.EModalSize = void 0; var react_1 = __importStar(require("react")); var enum_1 = require("enum"); var Button_1 = __importStar(require("components/Button")); var Icon_1 = __importDefault(require("components/Icon")); var global_1 = require("utils/global"); require("./index.scss"); var classnames_1 = require("utils/classnames"); var EModalSize; (function (EModalSize) { EModalSize["XS"] = "xs"; EModalSize["S"] = "s"; EModalSize["M"] = "m"; EModalSize["L"] = "l"; EModalSize["XL"] = "xl"; })(EModalSize = exports.EModalSize || (exports.EModalSize = {})); var EModalAnimation; (function (EModalAnimation) { EModalAnimation["LEFT"] = "left"; EModalAnimation["TOP"] = "top"; EModalAnimation["RIGHT"] = "right"; EModalAnimation["BOTTOM"] = "bottom"; })(EModalAnimation = exports.EModalAnimation || (exports.EModalAnimation = {})); var Modal = function (_a) { var open = _a.open, children = _a.children, secondaryAction = _a.secondaryAction, primaryAction = _a.primaryAction, closeHandler = _a.closeHandler, _b = _a.animation, animation = _b === void 0 ? "" : _b, _c = _a.title, title = _c === void 0 ? "" : _c, _d = _a.className, className = _d === void 0 ? "" : _d, _e = _a.size, size = _e === void 0 ? "" : _e, _f = _a.header, header = _f === void 0 ? true : _f, _g = _a.headerBorder, headerBorder = _g === void 0 ? true : _g, _h = _a.outSideClick, outSideClick = _h === void 0 ? true : _h; react_1.useEffect(function () { if (open) { document.body.classList.add("scroll-disable"); document.body.style.paddingRight = global_1.getScrollbarWidth() + "px"; } else { document.body.style.paddingRight = "0px"; document.body.classList.remove("scroll-disable"); } }, [open]); var closeModalHandler = function (e) { if (e.target.classList.contains("kb-modal")) { closeHandler(); } }; return (open && (react_1.default.createElement("div", { onMouseDown: outSideClick && closeModalHandler, className: "kb-modal" }, react_1.default.createElement("div", { className: "kb-modal__content kb-modal__" + size + " slide-" + animation + " " + className }, header && (react_1.default.createElement("div", { className: classnames_1.classNames("kb-modal__content-header", { border: headerBorder, }) }, title && (react_1.default.createElement("span", { className: "kb-modal__content-header__title" }, title)), react_1.default.createElement("div", { className: "close-btn", onClick: closeHandler }, react_1.default.createElement(Icon_1.default, { path: ["far", "times"] })))), react_1.default.createElement("div", { className: "kb-modal__content-body" }, children), (secondaryAction || primaryAction) && (react_1.default.createElement("div", { className: "kb-modal__content-footer" }, secondaryAction && (react_1.default.createElement(Button_1.default, { size: Button_1.EButtonSize.SMALL, color: (secondaryAction === null || secondaryAction === void 0 ? void 0 : secondaryAction.color) || enum_1.EColor.DANGER, onClick: secondaryAction === null || secondaryAction === void 0 ? void 0 : secondaryAction.action }, secondaryAction === null || secondaryAction === void 0 ? void 0 : secondaryAction.title)), primaryAction && (react_1.default.createElement(Button_1.default, { size: Button_1.EButtonSize.SMALL, color: (primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction.color) || enum_1.EColor.SUCCESS, onClick: primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction.action }, primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction.title)))))))); }; exports.default = Modal; //# sourceMappingURL=index.js.map