@jdcfe/yep-react
Version:
一套移动端的React组件库
94 lines (78 loc) • 3.44 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import * as React from 'react';
import classNames from 'classnames';
import { CSSTransition } from 'react-transition-group';
import Mask from '../mask';
import { createPortal } from 'react-dom';
var Popup = /*#__PURE__*/function (_React$PureComponent) {
_inherits(Popup, _React$PureComponent);
var _super = _createSuper(Popup);
function Popup() {
var _this;
_classCallCheck(this, Popup);
_this = _super.apply(this, arguments);
_this.onMaskClick = function (e) {
var _this$props = _this.props,
maskCloseable = _this$props.maskCloseable,
onCancel = _this$props.onCancel;
if (e.target === e.currentTarget && maskCloseable && onCancel) {
onCancel(e);
}
};
return _this;
}
_createClass(Popup, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
show = _this$props2.show,
popupTransition = _this$props2.popupTransition,
maskTransition = _this$props2.maskTransition,
prefixCls = _this$props2.prefixCls,
className = _this$props2.className,
style = _this$props2.style,
usePortal = _this$props2.usePortal,
children = _this$props2.children;
var cls = classNames(prefixCls, className);
var content = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(CSSTransition, {
in: show,
timeout: 300,
classNames: maskTransition,
unmountOnExit: true
}, /*#__PURE__*/React.createElement(Mask, {
onClick: this.onMaskClick
})), /*#__PURE__*/React.createElement(CSSTransition, {
in: show,
timeout: 300,
classNames: popupTransition,
unmountOnExit: true
}, /*#__PURE__*/React.createElement("div", {
className: cls,
style: style,
onClick: this.onMaskClick
}, children)));
if (usePortal) {
return /*#__PURE__*/createPortal(content, document.body);
}
return content;
}
}]);
return Popup;
}(React.PureComponent);
export { Popup as default };
Popup.defaultProps = {
prefixCls: 'Yep-popup',
style: {},
show: false,
popupTransition: 'slide-up',
maskTransition: 'fade',
maskCloseable: true,
onCancel: function onCancel() {},
usePortal: false
};