UNPKG

choerodon-ui

Version:

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

145 lines (120 loc) 3.72 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } 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 = 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 && React.createElement(Button, { disabled: loading, onClick: function onClick() { _this2.onClick(cancelProps); } }, cancelProps.text); return React.createElement("div", null, cancelButton, React.createElement(Button, { loading: loading, type: okProps.type, onClick: function onClick() { _this2.onClick(okProps); } }, okProps.text)); } }]); return ActionButton; }(Component); export { ActionButton as default }; //# sourceMappingURL=ActionButton.js.map