@molejs/mole-components-web
Version:
React组件库
74 lines (62 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports['default'] = operation;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _reactDom = require('react-dom');
var _reactDom2 = _interopRequireDefault(_reactDom);
var _closest = require('../_util/closest');
var _closest2 = _interopRequireDefault(_closest);
var _Modal = require('./Modal');
var _Modal2 = _interopRequireDefault(_Modal);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function operation() {
var actions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [{ text: '确定' }];
var platform = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ios';
var closed = false;
var prefixCls = 'am-modal';
var div = document.createElement('div');
document.body.appendChild(div);
function close() {
_reactDom2['default'].unmountComponentAtNode(div);
if (div && div.parentNode) {
div.parentNode.removeChild(div);
}
}
var footer = actions.map(function (button) {
// tslint:disable-next-line:only-arrow-functions
var orginPress = button.onPress || function () {};
button.onPress = function () {
if (closed) {
return;
}
var res = orginPress();
if (res && res.then) {
res.then(function () {
closed = true;
close();
})['catch'](function () {});
} else {
closed = true;
close();
}
};
return button;
});
function onWrapTouchStart(e) {
if (!/iPhone|iPod|iPad/i.test(navigator.userAgent)) {
return;
}
var pNode = (0, _closest2['default'])(e.currentTarget, '.am-modal-footer');
if (!pNode) {
e.preventDefault();
}
}
_reactDom2['default'].render(_react2['default'].createElement(_Modal2['default'], { visible: true, operation: true, transparent: true, prefixCls: prefixCls, transitionName: 'am-zoom', closable: false, maskClosable: true, onClose: close, footer: footer, maskTransitionName: 'am-fade', className: 'am-modal-operation', platform: platform, wrapProps: { onTouchStart: onWrapTouchStart } }), div);
return {
close: close
};
}
module.exports = exports['default'];