Add tag control demo

This commit is contained in:
afc163 2016-01-27 01:20:05 +08:00
parent 5719a83f36
commit a75dfe8fd6
3 changed files with 61 additions and 6 deletions

View File

@ -0,0 +1,50 @@
# 数据生成标签
- order: 2
用数组生成一组标签。
> 使用 `afterClose` 而不是 `onClose`,删除时有动画效果。
---
````jsx
import { Tag, Button } from 'antd';
let index = 2;
const App = React.createClass({
getInitialState() {
return {
tags: [
{ key: 1, name: '标签一'},
{ key: 2, name: '标签二'},
],
};
},
handleClose(key) {
const tags = [...this.state.tags].filter(tag => (tag.key !== key) && tag);
console.log(tags);
this.setState({ tags });
},
addTag() {
const tags = [...this.state.tags];
index += 1;
tags.push({ key: index, name: '新标签' + index });
this.setState({ tags });
},
render() {
return (
<div>
{this.state.tags.map(tag =>
<Tag key={tag.key} closable afterClose={this.handleClose.bind(this, tag.key)}>{tag.name}</Tag>
)}
<div>
<Button onClick={this.addTag}>添加标签</Button>
</div>
</div>
);
}
});
ReactDOM.render(<App />, mountNode);
````

View File

@ -24,11 +24,14 @@ class AntTag extends React.Component {
this.props.onClose(e);
}
animationEnd() {
this.setState({
closed: true,
closing: false,
});
animationEnd(key, existed) {
if (!existed) {
this.setState({
closed: true,
closing: false,
});
this.props.afterClose();
}
}
render() {
@ -56,6 +59,7 @@ AntTag.defaultProps = {
prefixCls: 'ant-tag',
closable: false,
onClose() {},
afterClose() {},
};
export default AntTag;

View File

@ -18,5 +18,6 @@
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|----------------|--------------------------------|------------|---------|--------|
| closable | 标签是否可以关闭 | boolean | | false |
| onClose | 组合时根据此项判定checked | function | | 无 |
| onClose | 关闭时的回调 | function | | 无 |
| afterClose | 动画关闭后的回调 | function | | 无 |
| color | 标签的色彩 | string | blue green yellow red | 无 |