mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 21:19:37 +08:00
80 lines
1.5 KiB
TypeScript
80 lines
1.5 KiB
TypeScript
import { Card } from 'antd';
|
|
import React, { useState } from 'react';
|
|
|
|
const tabList = [
|
|
{
|
|
key: 'tab1',
|
|
tab: 'tab1',
|
|
},
|
|
{
|
|
key: 'tab2',
|
|
tab: 'tab2',
|
|
},
|
|
];
|
|
|
|
const contentList: Record<string, React.ReactNode> = {
|
|
tab1: <p>content1</p>,
|
|
tab2: <p>content2</p>,
|
|
};
|
|
|
|
const tabListNoTitle = [
|
|
{
|
|
key: 'article',
|
|
tab: 'article',
|
|
},
|
|
{
|
|
key: 'app',
|
|
tab: 'app',
|
|
},
|
|
{
|
|
key: 'project',
|
|
tab: 'project',
|
|
},
|
|
];
|
|
|
|
const contentListNoTitle: Record<string, React.ReactNode> = {
|
|
article: <p>article content</p>,
|
|
app: <p>app content</p>,
|
|
project: <p>project content</p>,
|
|
};
|
|
|
|
const App: React.FC = () => {
|
|
const [activeTabKey1, setActiveTabKey1] = useState<string>('tab1');
|
|
const [activeTabKey2, setActiveTabKey2] = useState<string>('app');
|
|
|
|
const onTab1Change = (key: string) => {
|
|
setActiveTabKey1(key);
|
|
};
|
|
const onTab2Change = (key: string) => {
|
|
setActiveTabKey2(key);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Card
|
|
style={{ width: '100%' }}
|
|
title="Card title"
|
|
extra={<a href="#">More</a>}
|
|
tabList={tabList}
|
|
activeTabKey={activeTabKey1}
|
|
onTabChange={onTab1Change}
|
|
>
|
|
{contentList[activeTabKey1]}
|
|
</Card>
|
|
<br />
|
|
<br />
|
|
<Card
|
|
style={{ width: '100%' }}
|
|
tabList={tabListNoTitle}
|
|
activeTabKey={activeTabKey2}
|
|
tabBarExtraContent={<a href="#">More</a>}
|
|
onTabChange={onTab2Change}
|
|
>
|
|
{contentListNoTitle[activeTabKey2]}
|
|
</Card>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|