UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

113 lines (95 loc) 3.06 kB
import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import React, { Component } from 'react'; import { findDOMNode } from 'react-dom'; import Button from '../button'; var ActionButton = /*#__PURE__*/function (_Component) { _inherits(ActionButton, _Component); var _super = _createSuper(ActionButton); function ActionButton(props) { var _this; _classCallCheck(this, ActionButton); _this = _super.call(this, props); _this.onClick = function (props) { var actionFn = props.actionFn, closeModal = props.closeModal; if (actionFn) { var ret; if (actionFn.length) { ret = actionFn(closeModal); } else { ret = actionFn(); if (!ret) { closeModal(); } } if (ret && ret.then) { _this.setState({ loading: true }); ret.then(function () { // It's unnecessary to set loading=false, for the Modal will be unmounted after close. // this.setState({ loading: false }); closeModal.apply(void 0, arguments); }, function () { _this.setState({ loading: false }); }); } } else { closeModal(); } }; _this.state = { loading: false }; return _this; } _createClass(ActionButton, [{ key: "componentDidMount", value: function componentDidMount() { var autoFocus = this.props.autoFocus; if (autoFocus) { var $this = findDOMNode(this); this.timeoutId = window.setTimeout(function () { return $this.focus(); }); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { clearTimeout(this.timeoutId); } }, { key: "render", value: function render() { var _this2 = this; var _this$props = this.props, okProps = _this$props.okProps, cancelProps = _this$props.cancelProps; var loading = this.state.loading; var cancelButton = cancelProps && /*#__PURE__*/React.createElement(Button, _extends({}, cancelProps.buttonProps, { type: cancelProps.type, disabled: loading, onClick: function onClick() { _this2.onClick(cancelProps); } }), cancelProps.text); return /*#__PURE__*/React.createElement(React.Fragment, null, cancelButton, /*#__PURE__*/React.createElement(Button, _extends({}, okProps.buttonProps, { loading: loading, type: okProps.type, onClick: function onClick() { _this2.onClick(okProps); } }), okProps.text)); } }]); return ActionButton; }(Component); export { ActionButton as default }; //# sourceMappingURL=ActionButton.js.map