deps: upgrade antd-tools, close: #4208

This commit is contained in:
Benjy Cui 2016-12-19 14:01:52 +08:00
parent ca8e88971a
commit 4758302ad5
4 changed files with 70 additions and 66 deletions

View File

@ -0,0 +1,62 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Button from '../button';
export interface ActionButtonProps {
type: 'primary' | 'ghost' | 'dashed';
actionFn: Function;
closeModal: Function;
autoFocus?: Boolean;
}
export default class ActionButton extends React.Component<ActionButtonProps, any> {
timeoutId: number;
constructor(props) {
super(props);
this.state = {
loading: false,
};
}
componentDidMount() {
if (this.props.autoFocus) {
const $this = ReactDOM.findDOMNode(this) as HTMLInputElement;
this.timeoutId = setTimeout(() => $this.focus());
}
}
componentWillUnmount() {
clearTimeout(this.timeoutId);
}
onClick = () => {
const { actionFn, closeModal } = this.props;
if (actionFn) {
let ret;
if (actionFn.length) {
ret = actionFn(closeModal);
} else {
ret = actionFn();
if (!ret) {
closeModal();
}
}
if (ret && ret.then) {
this.setState({ loading: true });
ret.then((...args) => {
// It's unnecessary to set loading=false, for the Modal will be unmounted after close.
// this.setState({ loading: false });
closeModal(...args);
});
}
} else {
closeModal();
}
}
render() {
const { type, children } = this.props;
const loading = this.state.loading;
return (
<Button type={type} size="large" onClick={this.onClick} loading={loading}>
{children}
</Button>
);
}
}

View File

@ -1,70 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Dialog from './Modal';
import Icon from '../icon';
import Button from '../button';
import classNames from 'classnames';
import { getConfirmLocale } from './locale';
import assign from 'object-assign';
export interface ActionButtonProps {
type: 'primary' | 'ghost' | 'dashed';
actionFn: Function;
closeModal: Function;
autoFocus?: Boolean;
}
class ActionButton extends React.Component<ActionButtonProps, any> {
timeoutId: number;
constructor(props) {
super(props);
this.state = {
loading: false,
};
}
componentDidMount() {
if (this.props.autoFocus) {
const $this = ReactDOM.findDOMNode(this) as HTMLInputElement;
this.timeoutId = setTimeout(() => $this.focus());
}
}
componentWillUnmount() {
clearTimeout(this.timeoutId);
}
onClick = () => {
const { actionFn, closeModal } = this.props;
if (actionFn) {
let ret;
if (actionFn.length) {
ret = actionFn(closeModal);
} else {
ret = actionFn();
if (!ret) {
closeModal();
}
}
if (ret && ret.then) {
this.setState({ loading: true });
ret.then((...args) => {
// It's unnecessary to set loading=false, for the Modal will be unmounted after close.
// this.setState({ loading: false });
closeModal(...args);
});
}
} else {
closeModal();
}
}
render() {
const { type, children } = this.props;
const loading = this.state.loading;
return (
<Button type={type} size="large" onClick={this.onClick} loading={loading}>
{children}
</Button>
);
}
}
import Icon from '../icon';
import Dialog from './Modal';
import ActionButton from './ActionButton';
import { getConfirmLocale } from './locale';
export default function confirm(config) {
const props = assign({ iconType: 'question-circle' }, config);
@ -88,7 +29,7 @@ export default function confirm(config) {
function close() {
const unmountResult = ReactDOM.unmountComponentAtNode(div);
if (unmountResult) {
if (unmountResult && div.parentNode) {
div.parentNode.removeChild(div);
}
}

View File

@ -117,7 +117,8 @@ export default class Tooltip extends React.Component<TooltipProps, any> {
render() {
const { props, state } = this;
const { prefixCls, title, overlay, openClassName, children } = props;
const { prefixCls, title, overlay, openClassName } = props;
const children = props.children as React.ReactElement<any>;
let visible = state.visible;
// Hide tooltip when there is no title
if (!('visible' in props) && !title && !overlay) {

View File

@ -77,7 +77,7 @@
"@types/react": "~0.14.41",
"@types/react-dom": "~0.14.18",
"antd-demo-jest": "^1.0.5",
"antd-tools": "~0.14.6",
"antd-tools": "~0.16.0",
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.0",
"babel-jest": "^17.0.0",