UNPKG

@gem-mine/rmc-dialog

Version:

mobile dialog ui component for react

77 lines (66 loc) 2.64 kB
import _extends from 'babel-runtime/helpers/extends'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React from 'react'; import Portal from 'rc-util/es/PortalWrapper'; import Dialog from './Dialog'; function noop() {} var DialogWrap = function (_React$Component) { _inherits(DialogWrap, _React$Component); function DialogWrap() { _classCallCheck(this, DialogWrap); var _this = _possibleConstructorReturn(this, (DialogWrap.__proto__ || Object.getPrototypeOf(DialogWrap)).apply(this, arguments)); _this.saveRef = function (node) { _this._component = node; }; _this.getComponent = function (visible, childProps) { var props = _extends({}, _this.props); ['visible', 'onAnimateLeave'].forEach(function (key) { if (props.hasOwnProperty(key)) { delete props[key]; } }); return React.createElement(Dialog, _extends({}, props, { visible: visible }, childProps, { onAnimateLeave: _this.removeContainer, ref: _this.saveRef })); }; _this.removeContainer = function () { if (_this.container) { _this.container.parentNode.removeChild(_this.container); _this.container = null; } }; return _this; } _createClass(DialogWrap, [{ key: 'shouldComponentUpdate', value: function shouldComponentUpdate(_ref) { var visible = _ref.visible; return !!(this.props.visible || visible); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { this.removeContainer(); } }, { key: 'render', value: function render() { var _this2 = this; var _props = this.props, visible = _props.visible, getContainer = _props.getContainer, forceRender = _props.forceRender; return React.createElement(Portal, { visible: visible, forceRender: forceRender, getContainer: getContainer }, function (childProps) { return _this2.getComponent(visible, childProps); }); } }]); return DialogWrap; }(React.Component); export default DialogWrap; DialogWrap.defaultProps = { visible: false, prefixCls: 'rmc-dialog', onClose: noop };