From d375942e4b9f248ca1cdffe0e89e933481ea2149 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 29 Oct 2015 15:23:58 +0800 Subject: [PATCH] update tabs demo --- components/tabs/demo/add.md | 100 +++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/components/tabs/demo/add.md b/components/tabs/demo/add.md index 705de2cce2..d4bb5464cf 100644 --- a/components/tabs/demo/add.md +++ b/components/tabs/demo/add.md @@ -1,85 +1,101 @@ -# 添加 +# 动态的页签 - order: 4 -演示添加删除功能。 +演示添加删除和附加操作。 --- ````jsx -import { Tabs, Button, Icon } from 'antd'; +import { Tabs, Button, Icon, message } from 'antd'; const TabPane = Tabs.TabPane; -var index = 0; +let index = 0; const closeStyle = { position: 'absolute', - top: 0, - right: -10, -}; -var addStyle = { - pointerEvents: 'auto', - color: 'black', + top: 8, + right: -9, }; -var Test = React.createClass({ +const addStyle = { + pointerEvents: 'auto', + color: '#2db7f5', +}; + +const Test = React.createClass({ getInitialState() { return { tabs: [{ title: 'title ' + index, content: 'content ' + index, + index: index }], - activeKey: 'title ' + index + activeKey: index.toString() }; }, - remove(title, e) { + remove(index, e) { e.stopPropagation(); - if(this.state.tabs.length === 1) { - antd.message.error('仅剩一个,不能删除'); + let tabs = this.state.tabs; + let activeKey = this.state.activeKey; + let foundIndex = 0; + + if(tabs.length === 1) { + message.error('仅剩一个,不能删除'); return; } - var foundIndex = 0; - var tabs = this.state.tabs.filter(function (t, index) { - if (t.title !== title) { + + const newTabs = tabs.filter(tab => { + if (tab.index !== index) { return true; } else { foundIndex = index; return false; } }); - var activeKey = this.state.activeKey; - if (activeKey === title) { - if (foundIndex) { - foundIndex--; - } - activeKey = tabs[foundIndex].title; + + if (activeKey === index) { + activeKey = tabs[foundIndex - 1].index; } - this.setState({tabs, activeKey}) + + this.setState({ + tabs: newTabs, activeKey + }); }, add() { - index++; + index += 1; this.setState({ tabs: this.state.tabs.concat({ - title: 'title '+index, - content: 'content '+index, - }) + title: 'title ' + index, + content: 'content ' + index, + index: index, + }), + activeKey: index.toString(), }); }, onChange(activeKey) { - this.setState({activeKey}); + console.log(activeKey); + this.setState({ activeKey }); }, render() { - return 其它操作}> - { - this.state.tabs.map((t)=>{ - return {t.title} }> - {t.content} - ; - }).concat(} />) - } - + const addBtn = ; + const operations = ; + return ( + + { + this.state.tabs.map(tab => ( + + {tab.title} + + + }>{tab.content} + )) + } + + + ); } })