From 7ab93543ef9012b6b06e90facbba8af5d37ecb01 Mon Sep 17 00:00:00 2001 From: ztplz Date: Thu, 1 Nov 2018 06:37:14 +0800 Subject: [PATCH] Improve Alert --- components/alert/index.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/components/alert/index.tsx b/components/alert/index.tsx index f7c61353c2..5e96ac2fa1 100755 --- a/components/alert/index.tsx +++ b/components/alert/index.tsx @@ -34,17 +34,20 @@ export interface AlertProps { icon?: React.ReactNode; } -export default class Alert extends React.Component { - constructor(props: AlertProps) { - super(props); - this.state = { - closing: true, - closed: false, - }; - } +export interface AlertState { + closing: boolean, + closed: boolean +} + +export default class Alert extends React.Component { + state: AlertState = { + closing: true, + closed: false, + }; + handleClose = (e: React.MouseEvent) => { e.preventDefault(); - let dom = ReactDOM.findDOMNode(this) as HTMLElement; + const dom = ReactDOM.findDOMNode(this) as HTMLElement; dom.style.height = `${dom.offsetHeight}px`; // Magic code // 重复一次后才能正确设置 height @@ -55,6 +58,7 @@ export default class Alert extends React.Component { }); (this.props.onClose || noop)(e); } + animationEnd = () => { this.setState({ closed: true, @@ -62,6 +66,7 @@ export default class Alert extends React.Component { }); (this.props.afterClose || noop)(); } + render() { let { closable, description, type, prefixCls = 'ant-alert', message, closeText, showIcon, banner, @@ -126,7 +131,7 @@ export default class Alert extends React.Component { icon, { className: classNames({ - [icon.props.className!]: icon.props.className, + [icon.props.className as string]: icon.props.className, [`${prefixCls}-icon`]: true, }), },