refactor(Tag): rewrite Tag

This commit is contained in:
bang88 2016-06-26 23:57:13 +07:00
parent 893eec74dd
commit c198beef85
2 changed files with 25 additions and 9 deletions

View File

@ -1,3 +1,6 @@
export { default as Affix } from './affix';
export { default as Tabs } from './Tabs';
export { default as Tag } from './Tag';

View File

@ -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<TagProps, any> {
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 ? <Icon type="cross" onClick={this.close} /> : '';
const classString = classNames({
[prefixCls]: true,
@ -68,7 +81,7 @@ export default class Tag extends React.Component {
<span className={`${prefixCls}-text`}>{children}</span>
{close}
</div>
)}
) }
</Animate>
);
}