UNPKG

3.04 kBJavaScriptView Raw
1var _class, _temp;
2
3function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
5function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6
7function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
8
9import React, { Component } from 'react';
10import PropTypes from 'prop-types';
11import { createPortal } from 'react-dom';
12
13var Popover = (_temp = _class = function (_Component) {
14 _inherits(Popover, _Component);
15
16 function Popover(props) {
17 _classCallCheck(this, Popover);
18
19 var _this = _possibleConstructorReturn(this, _Component.call(this, props));
20
21 _this.componentDidMount = function () {};
22
23 _this.onClickMask = function (e) {
24 if (_this.props.onClickMask) _this.props.onClickMask(Object.getArgs(e, _this.props.args));
25 e.stopPropagation();
26 };
27
28 return _this;
29 }
30
31 Popover.prototype.render = function render() {
32 var _this2 = this;
33
34 var _props = this.props,
35 show = _props.show,
36 maskClassName = _props.maskClassName,
37 maskStyle = _props.maskStyle,
38 className = _props.className,
39 style = _props.style,
40 animation = _props.animation,
41 children = _props.children;
42
43 return createPortal(React.createElement(
44 'div',
45 { ref: function ref(el) {
46 _this2.$el = el;
47 }, className: 'mask popover-mask' + (maskClassName ? ' ' + maskClassName : '') + (show ? ' active' : ''), style: maskStyle, onClick: this.onClickMask },
48 React.createElement(
49 'div',
50 { style: style, className: 'popover' + (className ? ' ' + className : '') + (show ? ' active' : ''), 'data-animation': animation },
51 children && children
52 )
53 ), this.props.portal || document.getElementById('root'));
54 };
55
56 return Popover;
57}(Component), _class.defaultProps = {
58 isClickMaskHide: true,
59 animation: 'zoom'
60}, _temp);
61export { Popover as default };
62Popover.propTypes = process.env.NODE_ENV !== "production" ? {
63 args: PropTypes.any,
64 portal: PropTypes.object,
65 show: PropTypes.bool,
66
67 animation: PropTypes.string, // slideLeft | slideRight | slideUp | slideDown | zoom | fade
68 isClickMaskHide: PropTypes.bool,
69
70 maskClassName: PropTypes.string,
71 maskStyle: PropTypes.object,
72 onClickMask: PropTypes.func,
73
74 className: PropTypes.string,
75 style: PropTypes.object,
76
77 children: PropTypes.node
78} : {};
\No newline at end of file