@momentum-ui/react-collaboration
Version:
Cisco Momentum UI Framework for React Collaboration Applications
143 lines • 7.03 kB
JavaScript
/** @component modal */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React from 'react';
import PropTypes from 'prop-types';
// Library that manages Tabbing and Accessibility for Modal https://github.com/davidtheclark/react-aria-modal
import AriaModal from 'react-aria-modal';
/**
* @deprecated - Components in the legacy folder (/src/legacy) are deprecated. Please use a component from the components folder (/src/components) instead. Legacy components may not follow accessibility standards.
**/
var Modal = /** @class */ (function (_super) {
__extends(Modal, _super);
function Modal() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
animationClass: _this.props.show ? 'in' : '',
};
_this.getChildContext = function () {
return {
handleClose: function (e) { return _this.closeModal(e); },
};
};
_this.closeModal = function (e) {
_this.setAnimationState();
_this.hideTimerId && clearTimeout(_this.hideTimerId);
_this.hideTimerId = setTimeout(function () {
_this.props.onHide(e);
}, 300);
};
_this.setAnimationState = function (isOpen) {
_this.setState({ animationClass: isOpen ? 'in' : '' });
};
return _this;
}
Modal.prototype.componentDidUpdate = function (prevProps) {
prevProps.show !== this.props.show && this.props.show && this.setAnimationState(true);
};
Modal.prototype.componentWillUnmount = function () {
this.hideTimerId && clearTimeout(this.hideTimerId);
this.hideTimerId = null;
};
Modal.prototype.render = function () {
var _this = this;
var _a = this.props, applicationId = _a.applicationId, backdrop = _a.backdrop, backdropClickExit = _a.backdropClickExit, children = _a.children, className = _a.className, ContentWrapper = _a.ContentWrapper, escapeExits = _a.escapeExits, focusDialog = _a.focusDialog, htmlId = _a.htmlId, renderTo = _a.renderTo, show = _a.show, size = _a.size, props = __rest(_a, ["applicationId", "backdrop", "backdropClickExit", "children", "className", "ContentWrapper", "escapeExits", "focusDialog", "htmlId", "renderTo", "show", "size"]);
var modalContent = (React.createElement("div", { className: "md-modal__content" },
React.createElement("div", { className: "md-modal__flex-container" }, children)));
if (ContentWrapper) {
modalContent = React.createElement(ContentWrapper, null, modalContent);
}
var RenderModal = renderTo ? AriaModal.renderTo("#".concat(renderTo)) : AriaModal;
var getModal = function () {
return (show && (React.createElement(RenderModal, __assign({ onExit: _this.closeModal, getApplicationNode: function () { return document.querySelector("#".concat(applicationId)); }, dialogClass: "md-modal" +
" md-modal--".concat(size) +
" ".concat(_this.state.animationClass) +
"".concat((className && " ".concat(className)) || ''), includeDefaultStyles: false, titleId: htmlId, underlayClass: backdrop ? "md-modal__backdrop fade" + " ".concat(_this.state.animationClass) : '', underlayClickExits: backdropClickExit, escapeExits: escapeExits, focusDialog: focusDialog }, props), modalContent)));
};
return getModal();
};
Modal.childContextTypes = {
handleClose: PropTypes.func,
};
return Modal;
}(React.Component));
Modal.propTypes = {
/** @prop application DOM id, used to set aria-hidden to true when modal is open */
applicationId: PropTypes.string.isRequired,
/** @prop Determines the visibility and ability to edit the backdrop of the Modal | true */
backdrop: PropTypes.bool,
/** @prop To enable/disable clicking on underlay to exit modal | false */
backdropClickExit: PropTypes.bool,
/** @prop Children nodes to render inside the Modal | null */
children: PropTypes.node,
/** @prop Optional css class names | '' */
className: PropTypes.string,
/** @prop Optional component for wrapping content */
ContentWrapper: PropTypes.func,
/** @prop To enable/disable escape to exit modal | true */
escapeExits: PropTypes.bool,
/** @prop To set focus to the entire modal rather than elements within modal | true */
focusDialog: PropTypes.bool,
/** @prop Unique HTML ID used for tying label to HTML input for automated testing */
htmlId: PropTypes.string.isRequired,
/** @prop Icon node to be rendered for Dialog | null */
icon: PropTypes.element,
/** @prop Callback function invoked when user clicks on cross button or esc key */
onHide: PropTypes.func.isRequired,
/** @prop To render to an element other than the browser window | null */
renderTo: PropTypes.string,
/** @prop Show/hide modal */
show: PropTypes.bool.isRequired,
/** @prop Size of the modal | 'default' */
size: PropTypes.oneOf(['large', 'medium', 'default', 'small', 'full', 'dialog']),
};
Modal.defaultProps = {
backdrop: true,
backdropClickExit: false,
children: null,
className: '',
escapeExits: true,
focusDialog: true,
icon: null,
renderTo: null,
show: false,
size: 'default',
};
Modal.displayName = 'Modal';
export default Modal;
//# sourceMappingURL=index.js.map