UNPKG

glide-design-system

Version:

Glide design system is an open-source React component library. It offers numerous benefits that make them essential tools for design and development teams.

82 lines (79 loc) 4.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Modal = void 0; require("core-js/modules/es.symbol.description.js"); var _react = _interopRequireDefault(require("react")); require("./Modal.css"); var _propTypes = _interopRequireDefault(require("prop-types")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // /** // * Modal Layout // * @param {*} onClose A callback function that will be called when the user clicks the close icon or outside the modal to close it. // * @param {*} style allows you to apply custom styles to the modal container. // * @param {*} headerLabel string to set the label or title for the modal header. // * @param {*} headerStyle allows you to apply custom styles to the modal header. // * @param {*} cancelIcon boolean value indicating whether to show the close icon in the modal header.The default value is true. // * @param {*} open A boolean value indicating whether the modal is open or closed. // * @param {*} children The content to be displayed inside the modal. It can be any valid React component, HTML element, or a fragment of elements. // */ /** * The modal component provides a solid foundation for creating dialogs, popovers, lightboxes, or whatever else. */ const Modal = _ref => { let { open, onClose, children, containerClass, containerStyle, className, style, id, name } = _ref; if (!open) { return null; } const handleModalClick = e => { // Check if the clicked element is the modal content itself or its children if (e.target.classList.contains("modal-container")) { // Clicked outside the modal, trigger the onClose function onClose && onClose(); } else { // Clicked inside the modal, prevent event propagation to avoid closing e.stopPropagation(); } }; return /*#__PURE__*/_react.default.createElement("div", { className: "modal-container ".concat(containerClass ? containerClass : ""), style: _objectSpread({}, containerStyle), onClick: handleModalClick }, /*#__PURE__*/_react.default.createElement("div", { "data-testid": id, id: id, name: name, className: "modal ".concat(className ? className : ""), style: _objectSpread({}, style) }, children)); }; exports.Modal = Modal; Modal.propTypes = { /** * Close Modal */ onClose: _propTypes.default.func, /** * open Modal */ open: _propTypes.default.bool }; Modal.defaultProps = { open: false };