zent
Version:
一套前端设计语言和基于React的实现
48 lines (47 loc) • 1.73 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { Component } from 'react';
import Button from '../button';
import isPromise from '../utils/isPromise';
var ActionButton = (function (_super) {
__extends(ActionButton, _super);
function ActionButton() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
loading: false,
};
_this.onClick = function () {
var _a = _this.props, callback = _a.onClick, getClose = _a.getClose;
var close = getClose();
if (!callback) {
return close();
}
var callbackHasArgs = callback.length > 0;
var value = callbackHasArgs ? callback(close) : callback();
if (isPromise(value)) {
_this.setState({
loading: true,
});
value.then(function () {
close();
}, function () {
_this.setState({
loading: false,
});
});
return;
}
if (!callbackHasArgs && value !== false) {
close();
}
};
return _this;
}
ActionButton.prototype.render = function () {
var _a = this.props, className = _a.className, type = _a.type, text = _a.text;
var loading = this.state.loading;
return (_jsx(Button, __assign({ type: type, className: className, loading: loading, onClick: this.onClick }, { children: text }), void 0));
};
return ActionButton;
}(Component));
export default ActionButton;