UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

113 lines 6.24 kB
define(["require", "exports", "tslib", "react", "../../Utilities", "../FocusTrapZone/index", "./Modal.styles", "../../Overlay", "../../Layer", "../Popup/index", "../../utilities/decorators/withResponsiveMode"], function (require, exports, tslib_1, React, Utilities_1, index_1, Modal_styles_1, Overlay_1, Layer_1, index_2, withResponsiveMode_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var getClassNames = Utilities_1.classNamesFunction(); var ModalBase = /** @class */ (function (_super) { tslib_1.__extends(ModalBase, _super); function ModalBase(props) { var _this = _super.call(this, props) || this; _this._focusTrapZone = Utilities_1.createRef(); // Allow the user to scroll within the modal but not on the body _this._allowScrollOnModal = function (elt) { if (elt) { Utilities_1.allowScrollOnElement(elt, _this._events); } else { _this._events.off(_this._scrollableContent); } _this._scrollableContent = elt; }; _this.state = { id: Utilities_1.getId('Modal'), isOpen: props.isOpen, isVisible: props.isOpen }; return _this; } ModalBase.prototype.componentWillReceiveProps = function (newProps) { clearTimeout(this._onModalCloseTimer); // Opening the dialog if (newProps.isOpen) { if (!this.state.isOpen) { // First Open this.setState({ isOpen: true }); } else { // Reopen during closing this.setState({ isVisible: true }); } } // Closing the dialog if (!newProps.isOpen && this.state.isOpen) { this._onModalCloseTimer = this._async.setTimeout(this._onModalClose, parseFloat(Modal_styles_1.animationDuration) * 1000); this.setState({ isVisible: false }); } }; ModalBase.prototype.componentDidUpdate = function (prevProps, prevState) { if (!prevProps.isOpen && !prevState.isVisible) { this.setState({ isVisible: true }); } }; ModalBase.prototype.render = function () { var _a = this.props, className = _a.className, containerClassName = _a.containerClassName, scrollableContentClassName = _a.scrollableContentClassName, elementToFocusOnDismiss = _a.elementToFocusOnDismiss, firstFocusableSelector = _a.firstFocusableSelector, forceFocusInsideTrap = _a.forceFocusInsideTrap, ignoreExternalFocusing = _a.ignoreExternalFocusing, isBlocking = _a.isBlocking, isClickableOutsideFocusTrap = _a.isClickableOutsideFocusTrap, isDarkOverlay = _a.isDarkOverlay, onDismiss = _a.onDismiss, onLayerDidMount = _a.onLayerDidMount, responsiveMode = _a.responsiveMode, titleAriaId = _a.titleAriaId, styles = _a.styles, subtitleAriaId = _a.subtitleAriaId, theme = _a.theme; var _b = this.state, isOpen = _b.isOpen, isVisible = _b.isVisible; if (!isOpen) { return null; } var classNames = getClassNames(styles, { theme: theme, className: className, containerClassName: containerClassName, scrollableContentClassName: scrollableContentClassName, isOpen: isOpen, isVisible: isVisible }); // @temp tuatology - Will adjust this to be a panel at certain breakpoints if (responsiveMode >= withResponsiveMode_1.ResponsiveMode.small) { return (React.createElement(Layer_1.Layer, { onLayerDidMount: onLayerDidMount }, React.createElement(index_2.Popup, { role: isBlocking ? 'alertdialog' : 'dialog', ariaLabelledBy: titleAriaId, ariaDescribedBy: subtitleAriaId, onDismiss: onDismiss }, React.createElement("div", { className: classNames.root }, React.createElement(Overlay_1.Overlay, { isDarkThemed: isDarkOverlay, onClick: isBlocking ? undefined : onDismiss, styles: Modal_styles_1.getOverlayStyles }), React.createElement(index_1.FocusTrapZone, { componentRef: this._focusTrapZone, className: classNames.main, elementToFocusOnDismiss: elementToFocusOnDismiss, isClickableOutsideFocusTrap: isClickableOutsideFocusTrap ? isClickableOutsideFocusTrap : !isBlocking, ignoreExternalFocusing: ignoreExternalFocusing, forceFocusInsideTrap: forceFocusInsideTrap, firstFocusableSelector: firstFocusableSelector }, React.createElement("div", { ref: this._allowScrollOnModal, className: classNames.scrollableContent }, this.props.children)))))); } return null; }; ModalBase.prototype.focus = function () { if (this._focusTrapZone.current) { this._focusTrapZone.current.focus(); } }; // Watch for completed animations and set the state ModalBase.prototype._onModalClose = function () { this.setState({ isOpen: false }); // Call the onDismiss callback if (this.props.onDismissed) { this.props.onDismissed(); } }; ModalBase.defaultProps = { isOpen: false, isDarkOverlay: true, isBlocking: false, className: '', containerClassName: '' }; ModalBase = tslib_1.__decorate([ withResponsiveMode_1.withResponsiveMode ], ModalBase); return ModalBase; }(Utilities_1.BaseComponent)); exports.ModalBase = ModalBase; }); //# sourceMappingURL=Modal.base.js.map