From 4758302ad5d903e88bb4087d3fd4c2e7ef6d72f3 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Mon, 19 Dec 2016 14:01:52 +0800 Subject: [PATCH] deps: upgrade antd-tools, close: #4208 --- components/modal/ActionButton.tsx | 62 +++++++++++++++++++++++++++ components/modal/confirm.tsx | 69 +++---------------------------- components/tooltip/index.tsx | 3 +- package.json | 2 +- 4 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 components/modal/ActionButton.tsx diff --git a/components/modal/ActionButton.tsx b/components/modal/ActionButton.tsx new file mode 100644 index 0000000000..79d3d725ae --- /dev/null +++ b/components/modal/ActionButton.tsx @@ -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 { + 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 ( + + ); + } +} diff --git a/components/modal/confirm.tsx b/components/modal/confirm.tsx index 4e30f208ac..538f38ff3f 100644 --- a/components/modal/confirm.tsx +++ b/components/modal/confirm.tsx @@ -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 { - 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 ( - - ); - } -} +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); } } diff --git a/components/tooltip/index.tsx b/components/tooltip/index.tsx index e94f771f11..40710bca2a 100644 --- a/components/tooltip/index.tsx +++ b/components/tooltip/index.tsx @@ -117,7 +117,8 @@ export default class Tooltip extends React.Component { 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; let visible = state.visible; // Hide tooltip when there is no title if (!('visible' in props) && !title && !overlay) { diff --git a/package.json b/package.json index f2b154bef8..f2bfb4a9c4 100644 --- a/package.json +++ b/package.json @@ -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",