UNPKG

calcite-react

Version:
155 lines (120 loc) 7.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _propTypes = _interopRequireDefault(require("prop-types")); var _react = _interopRequireDefault(require("react")); var _Transition = _interopRequireDefault(require("react-transition-group/Transition")); var _reactModal = _interopRequireDefault(require("react-modal")); var _ModalStyled = require("./Modal-styled"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var Modal = function Modal(_ref) { var children = _ref.children, open = _ref.open, contentLabel = _ref.contentLabel, title = _ref.title, overlayStyle = _ref.overlayStyle, dialogStyle = _ref.dialogStyle, showClose = _ref.showClose, onCloseClicked = _ref.onCloseClicked, actions = _ref.actions, secondaryActions = _ref.secondaryActions, color = _ref.color, noPadding = _ref.noPadding, headerStyles = _ref.headerStyles, titleStyles = _ref.titleStyles, contentStyles = _ref.contentStyles, actionStyles = _ref.actionStyles, secondaryActionStyles = _ref.secondaryActionStyles, onRequestClose = _ref.onRequestClose, other = _objectWithoutProperties(_ref, ["children", "open", "contentLabel", "title", "overlayStyle", "dialogStyle", "showClose", "onCloseClicked", "actions", "secondaryActions", "color", "noPadding", "headerStyles", "titleStyles", "contentStyles", "actionStyles", "secondaryActionStyles", "onRequestClose"]); return _react.default.createElement(_Transition.default, { in: open, timeout: 0 }, function (state) { return _react.default.createElement(_reactModal.default, _extends({ isOpen: open, closeTimeoutMS: 300, style: { overlay: _objectSpread({}, _ModalStyled.reactModalOverlayStyles, overlayStyle, _ModalStyled.overlayTransition[state]), content: _objectSpread({}, (0, _ModalStyled.reactModalContentStyles)(color), dialogStyle, _ModalStyled.dialogTransition[state]) }, contentLabel: contentLabel, role: "dialog", onRequestClose: onRequestClose }, other), title && _react.default.createElement(_ModalStyled.StyledModalHeader, { style: headerStyles }, _react.default.createElement(_ModalStyled.StyledModalTitle, { style: titleStyles }, title), showClose && _react.default.createElement(_ModalStyled.StyledModalCloseButton, { onClick: onRequestClose })), _react.default.createElement(_ModalStyled.StyledModalContent, { style: contentStyles, noPadding: noPadding }, children), (actions || secondaryActions) && _react.default.createElement(_ModalStyled.StyledModalActions, { style: actionStyles }, actions, secondaryActions && _react.default.createElement(_ModalStyled.StyledSecondaryActions, { style: secondaryActionStyles }, secondaryActions))); }); }; Modal.propTypes = { /** The content of the component. */ children: _propTypes.default.node, /** Boolean describing if the Modal should be shown or not. */ open: _propTypes.default.bool, /** Node to be rendered as the modal title in the header */ title: _propTypes.default.node, /** String indicating how the content container should be announced to screenreaders. */ contentLabel: _propTypes.default.string, /** Buttons or links to be placed in the Modal actions footer. */ actions: _propTypes.default.node, /** Buttons or links to be placed in the footer, opposite your primary actions. */ secondaryActions: _propTypes.default.node, /** Adds a colored bar to the top of the Modal */ color: _propTypes.default.oneOf(['blue', 'red']), /** Remove pading from content wrapper. */ noPadding: _propTypes.default.bool, /** Function that will be run after the Modal has opened. */ onAfterOpen: _propTypes.default.func, /** Function that will be run when the Modal is requested to be closed (either by clicking on overlay or pressing ESC). */ onRequestClose: _propTypes.default.func, /** Boolean indicating if clicking the overlay should call the onRequestClose prop. */ shouldCloseOnOverlayClick: _propTypes.default.bool, /** Boolean indicating if pressing the esc key should call the onRequestClose prop. */ shouldCloseOnEsc: _propTypes.default.bool, /** Function that will be called to get the parent element to which the Modal will be attached. */ parentSelector: _propTypes.default.func, /** Styles applied to the overlay div. */ overlayStyle: _propTypes.default.object, /** Styles applied to the container dialog div. */ dialogStyle: _propTypes.default.object, /** Styles applied to the header div. */ headerStyles: _propTypes.default.object, /** Styles applied to the title div. */ titleStyles: _propTypes.default.object, /** Styles applied to the content div. */ contentStyles: _propTypes.default.object, /** Styles applied to the footer actions div. */ actionStyles: _propTypes.default.object, /** Styles applied to the footer secondary actions div. */ secondaryActionStyles: _propTypes.default.object, /** Toggles visiblity of the close icon button. */ showClose: _propTypes.default.bool }; Modal.defaultProps = { onAfterOpen: function onAfterOpen() {}, onRequestClose: function onRequestClose() {}, shouldCloseOnOverlayClick: true, shouldCloseOnEsc: true, showClose: true }; Modal.displayName = 'Modal'; var _default = Modal; exports.default = _default;