dtd
Version:
根据数梦工场视觉规范打造的组件库,感谢react-components和ant design
1 lines • 1.31 kB
JavaScript
import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import*as React from"react";import*as ReactDOM from"react-dom";import Button from"../button";var ActionButton=function(t){function e(t){_classCallCheck(this,e);var o=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return o.onClick=function(){var t=o.props,e=t.actionFn,n=t.closeModal;if(e){var i=void 0;e.length?i=e(n):(i=e())||n(),i&&i.then&&(o.setState({loading:!0}),i.then(function(){n.apply(void 0,arguments)},function(){o.setState({loading:!1})}))}else n()},o.state={loading:!1},o}return _inherits(e,t),_createClass(e,[{key:"componentDidMount",value:function(){if(this.props.autoFocus){var t=ReactDOM.findDOMNode(this);this.timeoutId=setTimeout(function(){return t.focus()})}}},{key:"componentWillUnmount",value:function(){clearTimeout(this.timeoutId)}},{key:"render",value:function(){var t=this.props,e=t.type,o=t.children,n=t.disabled,i=this.state.loading;return React.createElement(Button,{type:e,onClick:this.onClick,loading:i,disabled:n},o)}}]),e}(React.Component);export default ActionButton;