From c198beef85ea98588eee9b24c0c6605e0f778e13 Mon Sep 17 00:00:00 2001 From: bang88 Date: Sun, 26 Jun 2016 23:57:13 +0700 Subject: [PATCH] refactor(Tag): rewrite Tag --- components/index.tsx | 3 +++ components/tag/index.tsx | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/components/index.tsx b/components/index.tsx index 5db2da34d1..0b813ffeca 100644 --- a/components/index.tsx +++ b/components/index.tsx @@ -1,3 +1,6 @@ export { default as Affix } from './affix'; export { default as Tabs } from './Tabs'; + +export { default as Tag } from './Tag'; + diff --git a/components/tag/index.tsx b/components/tag/index.tsx index 70d7a05fa1..f5cff50cbd 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -1,15 +1,28 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; import Animate from 'rc-animate'; import Icon from '../icon'; import classNames from 'classnames'; import splitObject from '../_util/splitObject'; -export default class Tag extends React.Component { + +export interface TagProps { + /** 标签是否可以关闭*/ + closable?: boolean, + /** 关闭时的回调*/ + onClose?: Function, + /** 动画关闭后的回调*/ + afterClose?: Function, + /** 标签的色彩*/ + color?: string, + + style?: React.CSSProperties +} +export default class Tag extends React.Component { static defaultProps = { prefixCls: 'ant-tag', closable: false, - onClose() {}, - afterClose() {}, + onClose() { }, + afterClose() { }, } constructor(props) { @@ -47,8 +60,8 @@ export default class Tag extends React.Component { render() { const [{ prefixCls, closable, color, className, children - },restProps] = splitObject(this.props, - ['prefixCls', 'closable', 'color','className','children']); + }, restProps] = splitObject(this.props, + ['prefixCls', 'closable', 'color', 'className', 'children']); const close = closable ? : ''; const classString = classNames({ [prefixCls]: true, @@ -62,13 +75,13 @@ export default class Tag extends React.Component { transitionName={`${prefixCls}-zoom`} transitionAppear onEnd={this.animationEnd} - > + > {this.state.closed ? null : (
{children} {close}
- )} + ) } ); }