2017-08-09 14:34:10 +08:00
|
|
|
---
|
|
|
|
order: 8
|
|
|
|
title:
|
|
|
|
zh-CN: 带页签的卡片
|
|
|
|
en-US: With tabs
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
可承载更多内容。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
More content can be hosted.
|
|
|
|
|
|
|
|
````jsx
|
|
|
|
import { Card } from 'antd';
|
|
|
|
|
|
|
|
const tabList = [{
|
|
|
|
key: 'tab1',
|
|
|
|
tab: 'tab1',
|
|
|
|
}, {
|
|
|
|
key: 'tab2',
|
|
|
|
tab: 'tab2',
|
|
|
|
}];
|
|
|
|
|
|
|
|
const contentList = {
|
|
|
|
tab1: <p>content1</p>,
|
|
|
|
tab2: <p>content2</p>,
|
|
|
|
};
|
|
|
|
|
2017-08-14 21:43:32 +08:00
|
|
|
const tabListNoTitle = [{
|
|
|
|
key: 'article',
|
|
|
|
tab: 'article',
|
|
|
|
}, {
|
|
|
|
key: 'app',
|
|
|
|
tab: 'app',
|
|
|
|
}, {
|
|
|
|
key: 'project',
|
|
|
|
tab: 'project',
|
|
|
|
}];
|
|
|
|
|
|
|
|
const contentListNoTitle = {
|
|
|
|
article: <p>article content</p>,
|
|
|
|
app: <p>app content</p>,
|
|
|
|
project: <p>project content</p>,
|
|
|
|
};
|
|
|
|
|
2017-08-09 14:34:10 +08:00
|
|
|
class TabsCard extends React.Component {
|
|
|
|
state = {
|
|
|
|
key: 'tab1',
|
2017-08-14 21:43:32 +08:00
|
|
|
noTitleKey: 'article',
|
2017-08-09 14:34:10 +08:00
|
|
|
}
|
2017-08-14 21:43:32 +08:00
|
|
|
onTabChange = (key, type) => {
|
|
|
|
console.log(key, type);
|
|
|
|
this.setState({ [type]: key });
|
2017-08-09 14:34:10 +08:00
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return (
|
2017-08-14 21:43:32 +08:00
|
|
|
<div>
|
|
|
|
<Card
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
title="Card title"
|
|
|
|
extra={<a href="#">More</a>}
|
|
|
|
tabList={tabList}
|
|
|
|
onTabChange={(key) => { this.onTabChange(key, 'key'); }}
|
|
|
|
>
|
|
|
|
{contentList[this.state.key]}
|
|
|
|
</Card>
|
|
|
|
<br /><br />
|
|
|
|
<Card
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
tabList={tabListNoTitle}
|
|
|
|
onTabChange={(key) => { this.onTabChange(key, 'noTitleKey'); }}
|
|
|
|
>
|
|
|
|
{contentListNoTitle[this.state.noTitleKey]}
|
|
|
|
</Card>
|
|
|
|
</div>
|
2017-08-09 14:34:10 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<TabsCard />
|
|
|
|
, mountNode);
|
|
|
|
````
|