{"size": 3005, "ext": "js", "max_stars_repo_path": "temp/components/Modal/ActionButton.js", "max_stars_repo_name": "bushuai/ppfish-components", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "temp/components/Modal/ActionButton.js", "max_issues_repo_name": "bushuai/ppfish-components", "max_issues_repo_issues_event_min_datetime": "2020-12-23T06:54:25.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-24T02:12:50.000Z", "max_forks_repo_path": "temp/components/Modal/ActionButton.js", "max_forks_repo_name": "bushuai/ppfish-components", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 39.5394736842, "max_line_length": 112, "alphanum_fraction": 0.4885191348}
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Button from '../Button';
var ActionButton = /** @class */ (function (_super) {
    __extends(ActionButton, _super);
    function ActionButton(props) {
        var _this = _super.call(this, props) || this;
        _this.onClick = function () {
            var _a = _this.props, actionFn = _a.actionFn, closeModal = _a.closeModal;
            if (actionFn) {
                var ret = void 0;
                if (actionFn.length) {
                    ret = actionFn(closeModal);
                }
                else {
                    ret = actionFn();
                    if (!ret) {
                        closeModal();
                    }
                }
                if (ret && ret.then) {
                    _this.setState({ loading: true });
                    ret.then(function () {
                        var args = [];
                        for (var _i = 0; _i < arguments.length; _i++) {
                            args[_i] = arguments[_i];
                        }
                        // It's unnecessary to set loading=false, for the Modal will be unmounted after close.
                        // this.setState({ loading: false });
                        closeModal.apply(void 0, args);
                    }, function () {
                        // See: https://github.com/ant-design/ant-design/issues/6183
                        _this.setState({ loading: false });
                    });
                }
            }
            else {
                closeModal();
            }
        };
        _this.state = {
            loading: false
        };
        return _this;
    }
    ActionButton.prototype.componentDidMount = function () {
        if (this.props.autoFocus) {
            var $this_1 = ReactDOM.findDOMNode(this);
            this.timeoutId = setTimeout(function () { return $this_1.focus(); });
        }
    };
    ActionButton.prototype.componentWillUnmount = function () {
        clearTimeout(this.timeoutId);
    };
    ActionButton.prototype.render = function () {
        var _a = this.props, type = _a.type, children = _a.children;
        var loading = this.state.loading;
        return (React.createElement(Button, { type: type, onClick: this.onClick, loading: loading }, children));
    };
    return ActionButton;
}(React.Component));
export default ActionButton;
