-
Notifications
You must be signed in to change notification settings - Fork 71
/
ButtonsSpace.react.js
149 lines (118 loc) · 7.02 KB
/
ButtonsSpace.react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ActionButton = _interopRequireDefault(require("./ActionButton.react"));
var _Bem = require("./Bem");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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; }
var PopupFooterButtons = /*#__PURE__*/function (_React$Component) {
_inherits(PopupFooterButtons, _React$Component);
var _super = _createSuper(PopupFooterButtons);
function PopupFooterButtons() {
_classCallCheck(this, PopupFooterButtons);
return _super.apply(this, arguments);
}
_createClass(PopupFooterButtons, [{
key: "onOk",
value: function onOk() {
return this.props.onOk();
}
}, {
key: "onClose",
value: function onClose() {
return this.props.onClose();
}
}, {
key: "buttonClick",
value: function buttonClick(action) {
return this.props.buttonClick(action);
}
}, {
key: "render",
value: function render() {
var _this = this;
if (!this.props.buttons) {
return null;
}
var btns = [];
this.props.buttons.forEach(function (btn, i) {
var url = btn.url ? btn.url : null;
var key = i;
if (typeof btn === 'string') {
if (btn === 'ok') {
btns.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton["default"], {
className: "".concat(_this.props.btnClass, " ").concat(_this.props.btnClass, "--ok"),
onClick: function onClick() {
return _this.onOk();
},
children: _this.props.defaultOk
}, key));
} else if (btn === 'cancel') {
btns.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton["default"], {
className: "".concat(_this.props.btnClass, " ").concat(_this.props.btnClass, "--cancel"),
onClick: function onClick() {
return _this.onClose();
},
children: _this.props.defaultCancel
}, key));
}
} else if ( /*#__PURE__*/_react["default"].isValidElement(btn)) {
btns.push(btn);
} else {
var className = "".concat(_this.props.btnClass, " ").concat((0, _Bem.modifier)(btn.className, _this.props.btnClass));
var btnComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton["default"], {
className: className,
url: url,
onClick: function onClick() {
return _this.buttonClick(btn.action);
},
children: btn.text
}, key);
btns.push(btnComponent);
}
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: this.props.className,
children: btns
});
}
}]);
return PopupFooterButtons;
}(_react["default"].Component);
exports["default"] = PopupFooterButtons;
_defineProperty(PopupFooterButtons, "defaultProps", {
buttons: null,
className: null,
onOk: function onOk() {},
onClose: function onClose() {},
buttonClick: function buttonClick() {},
btnClass: null,
defaultOk: null,
defaultCancel: null
});
PopupFooterButtons.propTypes = {
buttons: _propTypes["default"].arrayOf(_propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object])),
className: _propTypes["default"].string,
onOk: _propTypes["default"].func,
onClose: _propTypes["default"].func,
buttonClick: _propTypes["default"].func,
btnClass: _propTypes["default"].string,
defaultOk: _propTypes["default"].string,
defaultCancel: _propTypes["default"].string
};