Skip to content

Commit 0a5dd6f

Browse files
committed
feat: add card tablist support custom tab
1 parent a4cc00b commit 0a5dd6f

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

components/card/Card.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ export default {
8181
},
8282
render () {
8383
const {
84-
prefixCls = 'ant-card', extra, bodyStyle, title, loading,
84+
prefixCls = 'ant-card', bodyStyle, loading,
8585
bordered = true, type, tabList, hoverable, activeTabKey, defaultActiveTabKey,
8686
} = this.$props
8787

88-
const { $slots } = this
88+
const { $slots, $scopedSlots } = this
8989

9090
const classString = {
9191
[`${prefixCls}`]: true,
@@ -139,11 +139,16 @@ export default {
139139
let head
140140
const tabs = tabList && tabList.length ? (
141141
<Tabs {...tabsProps}>
142-
{tabList.map(item => <TabPane tab={item.tab} key={item.key} />)}
142+
{tabList.map(item => {
143+
const { tab: temp, scopedSlots = {}} = item
144+
const name = scopedSlots.tab
145+
const tab = temp !== undefined ? temp : ($scopedSlots[name] ? $scopedSlots[name](item) : null)
146+
return <TabPane tab={tab} key={item.key} />
147+
})}
143148
</Tabs>
144149
) : null
145-
const titleDom = title || getComponentFromProp(this, 'title')
146-
const extraDom = extra || getComponentFromProp(this, 'extra')
150+
const titleDom = getComponentFromProp(this, 'title')
151+
const extraDom = getComponentFromProp(this, 'extra')
147152
if (titleDom || extraDom || tabs) {
148153
head = (
149154
<div class={`${prefixCls}-head`}>

components/card/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ exports[`renders ./components/card/demo/tabsCard.md correctly 1`] = `
212212
<div class="ant-tabs-nav-scroll">
213213
<div class="ant-tabs-nav ant-tabs-nav-animated">
214214
<div class="ant-tabs-ink-bar ant-tabs-ink-bar-animated" style="display: block; transform: translate3d(0px,0,0); -webkit-transform: translate3d(0px,0,0); width: 0px;"></div>
215-
<div role="tab" aria-disabled="false" aria-selected="true" class="ant-tabs-tab-active ant-tabs-tab">tab1</div>
215+
<div role="tab" aria-disabled="false" aria-selected="true" class="ant-tabs-tab-active ant-tabs-tab"><span><i class="anticon anticon-home"></i>tab1
216+
</span></div>
216217
<div role="tab" aria-disabled="false" aria-selected="false" class=" ant-tabs-tab">tab2</div>
217218
</div>
218219
</div>

components/card/demo/tabsCard.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
:tabList="tabList"
1818
@tabChange="key => onTabChange(key, 'key')"
1919
>
20+
<span slot="customRender" slot-scope="item">
21+
<a-icon type="home"/>{{item.key}}
22+
</span>
2023
<a href="#" slot="extra">More</a>
2124
{{contentList[key]}}
2225
</a-card>
@@ -40,7 +43,8 @@ export default {
4043
return {
4144
tabList: [{
4245
key: 'tab1',
43-
tab: 'tab1',
46+
// tab: 'tab1',
47+
scopedSlots: { tab: 'customRender'}
4448
}, {
4549
key: 'tab2',
4650
tab: 'tab2',

components/card/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| extra | Content to render in the top-right corner of the card | string\|slot | - |
1212
| hoverable | Lift up when hovering card | boolean | false |
1313
| loading | Shows a loading indicator while the contents of the card are being fetched | boolean | false |
14-
| tabList | List of TabPane's head. | Array<{key: string, tab: ReactNode}> | - |
14+
| tabList | List of TabPane's head, Custom tabs can be created with the scopedSlots property | Array<{key: string, tab: any, scopedSlots: {tab: 'XXX'}}> | - |
1515
| activeTabKey | Current TabPane's key | string | - |
1616
| defaultActiveTabKey | Initial active TabPane's key, if `activeTabKey` is not set. | string | - |
1717
| title | Card title | string\|slot | - |

components/card/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| extra | 卡片右上角的操作区域 | string\|slot | - |
1313
| hoverable | 鼠标移过时可浮起 | boolean | false |
1414
| loading | 当卡片内容还在加载中时,可以用 loading 展示一个占位 | boolean | false |
15-
| tabList | 页签标题列表 | Array<{key: string, tab: ReactNode}> | - |
15+
| tabList | 页签标题列表, 可以通过scopedSlots属性自定义tab | Array<{key: string, tab: any, scopedSlots: {tab: 'XXX'}}> | - |
1616
| activeTabKey | 当前激活页签的 key | string | - |
1717
| defaultActiveTabKey | 初始化选中页签的 key,如果没有设置 activeTabKey | string | 第一个页签 |
1818
| title | 卡片标题 | string\|slot | - |

0 commit comments

Comments
 (0)