1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _defineProperty from 'babel-runtime/helpers/defineProperty';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _createClass from 'babel-runtime/helpers/createClass';
|
5 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
6 | import _inherits from 'babel-runtime/helpers/inherits';
|
7 | var __rest = this && this.__rest || function (s, e) {
|
8 | var t = {};
|
9 | for (var p in s) {
|
10 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
11 | }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
12 | if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
|
13 | }return t;
|
14 | };
|
15 | import classnames from 'classnames';
|
16 | import React from 'react';
|
17 | import Dialog from 'rmc-dialog';
|
18 | import TouchFeedback from 'rmc-feedback';
|
19 | import { ModalComponent } from './PropsType';
|
20 |
|
21 | var Modal = function (_ModalComponent) {
|
22 | _inherits(Modal, _ModalComponent);
|
23 |
|
24 | function Modal() {
|
25 | _classCallCheck(this, Modal);
|
26 |
|
27 | return _possibleConstructorReturn(this, (Modal.__proto__ || Object.getPrototypeOf(Modal)).apply(this, arguments));
|
28 | }
|
29 |
|
30 | _createClass(Modal, [{
|
31 | key: 'renderFooterButton',
|
32 | value: function renderFooterButton(button, prefixCls, i) {
|
33 | var buttonStyle = {};
|
34 | if (button.style) {
|
35 | buttonStyle = button.style;
|
36 | if (typeof buttonStyle === 'string') {
|
37 | var styleMap = {
|
38 | cancel: {},
|
39 | 'default': {},
|
40 | destructive: { color: 'red' }
|
41 | };
|
42 | buttonStyle = styleMap[buttonStyle] || {};
|
43 | }
|
44 | }
|
45 | var onClickFn = function onClickFn(e) {
|
46 | e.preventDefault();
|
47 | if (button.onPress) {
|
48 | button.onPress();
|
49 | }
|
50 | };
|
51 | return React.createElement(
|
52 | TouchFeedback,
|
53 | { activeClassName: prefixCls + '-button-active', key: i },
|
54 | React.createElement(
|
55 | 'a',
|
56 | { className: prefixCls + '-button', role: 'button', style: buttonStyle, onClick: onClickFn },
|
57 | button.text || 'Button'
|
58 | )
|
59 | );
|
60 | }
|
61 | }, {
|
62 | key: 'render',
|
63 | value: function render() {
|
64 | var _this2 = this,
|
65 | _classnames2;
|
66 |
|
67 | var _a = this.props,
|
68 | prefixCls = _a.prefixCls,
|
69 | className = _a.className,
|
70 | wrapClassName = _a.wrapClassName,
|
71 | transitionName = _a.transitionName,
|
72 | maskTransitionName = _a.maskTransitionName,
|
73 | style = _a.style,
|
74 | platform = _a.platform,
|
75 | _a$footer = _a.footer,
|
76 | footer = _a$footer === undefined ? [] : _a$footer,
|
77 | operation = _a.operation,
|
78 | animated = _a.animated,
|
79 | transparent = _a.transparent,
|
80 | popup = _a.popup,
|
81 | animationType = _a.animationType,
|
82 | restProps = __rest(_a, ["prefixCls", "className", "wrapClassName", "transitionName", "maskTransitionName", "style", "platform", "footer", "operation", "animated", "transparent", "popup", "animationType"]);
|
83 | var btnGroupClass = classnames(prefixCls + '-button-group-' + (footer.length === 2 && !operation ? 'h' : 'v'), prefixCls + '-button-group-' + (operation ? 'operation' : 'normal'));
|
84 | var footerDom = footer.length ? React.createElement(
|
85 | 'div',
|
86 | { className: btnGroupClass, role: 'group' },
|
87 | footer.map(function (button, i) {
|
88 | return (
|
89 |
|
90 | _this2.renderFooterButton(button, prefixCls, i)
|
91 | );
|
92 | })
|
93 | ) : null;
|
94 | var transName = void 0;
|
95 | var maskTransName = void 0;
|
96 | if (animated) {
|
97 |
|
98 | if (transparent) {
|
99 | transName = maskTransName = 'am-fade';
|
100 | } else {
|
101 | transName = maskTransName = 'am-slide-up';
|
102 | }
|
103 | if (popup) {
|
104 | transName = animationType === 'slide-up' ? 'am-slide-up' : 'am-slide-down';
|
105 | maskTransName = 'am-fade';
|
106 | }
|
107 | }
|
108 | var wrapCls = classnames(wrapClassName, _defineProperty({}, prefixCls + '-wrap-popup', popup));
|
109 | var cls = classnames(className, (_classnames2 = {}, _defineProperty(_classnames2, prefixCls + '-transparent', transparent), _defineProperty(_classnames2, prefixCls + '-popup', popup), _defineProperty(_classnames2, prefixCls + '-popup-' + animationType, popup && animationType), _defineProperty(_classnames2, prefixCls + '-android', platform === 'android'), _classnames2));
|
110 | return React.createElement(Dialog, _extends({}, restProps, { prefixCls: prefixCls, className: cls, wrapClassName: wrapCls, transitionName: transitionName || transName, maskTransitionName: maskTransitionName || maskTransName, style: style, footer: footerDom }));
|
111 | }
|
112 | }]);
|
113 |
|
114 | return Modal;
|
115 | }(ModalComponent);
|
116 |
|
117 | export default Modal;
|
118 |
|
119 | Modal.defaultProps = {
|
120 | prefixCls: 'am-modal',
|
121 | transparent: false,
|
122 | popup: false,
|
123 | animationType: 'slide-down',
|
124 | animated: true,
|
125 | style: {},
|
126 | onShow: function onShow() {},
|
127 |
|
128 | footer: [],
|
129 | closable: false,
|
130 | operation: false,
|
131 | platform: 'ios'
|
132 | }; |
\ | No newline at end of file |