UNPKG

zarm-mobile

Version:
224 lines (192 loc) 8.36 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _classnames3 = require('classnames'); var _classnames4 = _interopRequireDefault(_classnames3); var _events = require('../utils/events'); var _events2 = _interopRequireDefault(_events); var _Mask = require('../Mask'); var _Mask2 = _interopRequireDefault(_Mask); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _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; } function _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; } var Modal = function (_PureComponent) { _inherits(Modal, _PureComponent); function Modal(props) { _classCallCheck(this, Modal); var _this = _possibleConstructorReturn(this, (Modal.__proto__ || Object.getPrototypeOf(Modal)).call(this, props)); _this.state = { isShow: props.visible || false, isPending: false, animationState: 'enter' }; _this.animationEnd = _this.animationEnd.bind(_this); return _this; } _createClass(Modal, [{ key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (!this.props.visible && nextProps.visible) { this.enter(); } else if (this.props.visible && !nextProps.visible) { this.leave(); } } }, { key: 'componentWillUpdate', value: function componentWillUpdate() { _events2.default.on(this.modal, 'webkitAnimationEnd', this.animationEnd); _events2.default.on(this.modal, 'animationend', this.animationEnd); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { _events2.default.off(this.modal, 'webkitAnimationEnd', this.animationEnd); _events2.default.off(this.modal, 'animationend', this.animationEnd); } }, { key: 'animationEnd', value: function animationEnd() { if (this.state.animationState === 'leave') { this.setState({ isShow: false, isPending: false }); } else { this.setState({ isShow: true, isPending: false }); } } }, { key: 'enter', value: function enter() { this.setState({ isShow: true, isPending: true, animationState: 'enter' }); } }, { key: 'leave', value: function leave() { this.setState({ isShow: true, isPending: true, animationState: 'leave' }); } }, { key: 'render', value: function render() { var _classnames, _classnames2, _this2 = this; var _props = this.props, prefixCls = _props.prefixCls, className = _props.className, animationType = _props.animationType, animationDuration = _props.animationDuration, width = _props.width, minWidth = _props.minWidth, radius = _props.radius, onMaskClick = _props.onMaskClick, children = _props.children; var _state = this.state, isShow = _state.isShow, isPending = _state.isPending, animationState = _state.animationState; var cls = { modal: (0, _classnames4.default)((_classnames = {}, _defineProperty(_classnames, '' + prefixCls, true), _defineProperty(_classnames, className, !!className), _defineProperty(_classnames, 'radius', radius), _defineProperty(_classnames, 'fade-' + animationState, isPending), _classnames)), dialog: (0, _classnames4.default)((_classnames2 = {}, _defineProperty(_classnames2, prefixCls + '-dialog', true), _defineProperty(_classnames2, animationType + '-' + animationState, isPending), _defineProperty(_classnames2, 'fade-' + animationState, isPending), _classnames2)) // mask: classnames({ // [`fade-${animationState}`]: isPending, // }), }; var style = { modal: { WebkitAnimationDuration: animationDuration + 'ms', MozAnimationDuration: animationDuration + 'ms', msAnimationDuration: animationDuration + 'ms', OAnimationDuration: animationDuration + 'ms', animationDuration: animationDuration + 'ms' }, dialog: { width: width, minWidth: minWidth, WebkitAnimationDuration: animationDuration + 'ms', MozAnimationDuration: animationDuration + 'ms', msAnimationDuration: animationDuration + 'ms', OAnimationDuration: animationDuration + 'ms', animationDuration: animationDuration + 'ms' } // mask: { // WebkitAnimationDuration: `${animationDuration}ms`, // MozAnimationDuration: `${animationDuration}ms`, // msAnimationDuration: `${animationDuration}ms`, // OAnimationDuration: `${animationDuration}ms`, // animationDuration: `${animationDuration}ms`, // }, }; if (!isShow) { style.modal.display = 'none'; } return _react2.default.createElement( 'div', { className: cls.modal, style: style.modal, ref: function ref(ele) { _this2.modal = ele; } }, _react2.default.createElement( 'div', { className: prefixCls + '-wrapper' }, _react2.default.createElement( 'div', { className: cls.dialog, style: style.dialog, onClick: function onClick(e) { return e.stopPropagation(); } }, children ) ), _react2.default.createElement(_Mask2.default, { visible: isShow // className={cls.mask} // style={style.mask} , onClose: onMaskClick }) ); } }]); return Modal; }(_react.PureComponent); Modal.propTypes = { prefixCls: _propTypes2.default.string, className: _propTypes2.default.string, visible: _propTypes2.default.bool, animationType: _propTypes2.default.oneOf(['fade', 'door', 'flip', 'rotate', 'zoom', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'slideUp', 'slideDown', 'slideLeft', 'slideRight']), animationDuration: _propTypes2.default.number, width: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]), minWidth: _propTypes2.default.number, radius: _propTypes2.default.bool, onMaskClick: _propTypes2.default.func }; Modal.defaultProps = { prefixCls: 'za-modal', className: null, visible: false, animationType: 'zoom', animationDuration: 200, width: '70%', minWidth: 270, radius: false, onMaskClick: function onMaskClick() {} }; exports.default = Modal;