Skip to content

Commit 94b507b

Browse files
authored
Merge pull request #84 from wangxueliang/master
fix: support card description and title slot
2 parents b6da432 + b7396dc commit 94b507b

File tree

11 files changed

+110
-45
lines changed

11 files changed

+110
-45
lines changed

components/card/Card.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
mixins: [BaseMixin],
1313
props: {
1414
prefixCls: PropTypes.string.def('ant-card'),
15-
title: PropTypes.string,
15+
title: PropTypes.any,
1616
extra: PropTypes.any,
1717
bordered: PropTypes.bool.def(true),
1818
bodyStyle: PropTypes.object,

components/card/Grid.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export default {
77
prefixCls: PropTypes.string.def('ant-card'),
88
},
99
render () {
10-
const { prefixCls = 'ant-card', ...others } = this.$props
10+
const { prefixCls = 'ant-card' } = this.$props
1111
const classString = {
1212
[`${prefixCls}-grid`]: true,
1313
}
1414
return (
15-
<div {...others} class={classString}>{this.$slots.default}</div>
15+
<div {...{ on: this.$listeners }} class={classString}>{this.$slots.default}</div>
1616
)
1717
},
1818
}

components/card/Meta.jsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ export default {
66
name: 'ACardMeta',
77
props: {
88
prefixCls: PropTypes.string.def('ant-card'),
9-
title: PropTypes.string,
10-
description: PropTypes.string,
9+
title: PropTypes.any,
10+
description: PropTypes.any,
1111
},
1212
render () {
13-
const { prefixCls = 'ant-card', title, description, ...others } = this.$props
13+
const { prefixCls = 'ant-card' } = this.$props
1414
const classString = {
1515
[`${prefixCls}-meta`]: true,
1616
}
1717

1818
const avatar = getComponentFromProp(this, 'avatar')
19+
const title = getComponentFromProp(this, 'title')
20+
const description = getComponentFromProp(this, 'description')
21+
1922
const avatarDom = avatar ? <div class={`${prefixCls}-meta-avatar`}>{avatar}</div> : null
2023
const titleDom = title ? <div class={`${prefixCls}-meta-title`}>{title}</div> : null
2124
const descriptionDom = description
@@ -26,7 +29,7 @@ export default {
2629
{descriptionDom}
2730
</div> : null
2831
return (
29-
<div {...others} class={classString}>
32+
<div {...{ on: this.$listeners }} class={classString}>
3033
{avatarDom}
3134
{MetaDetail}
3235
</div>

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

+31-12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ exports[`renders ./components/card/demo/concise.md correctly 1`] = `
7171
</div>
7272
`;
7373

74+
exports[`renders ./components/card/demo/flexible-content.md correctly 1`] = `
75+
<div class="ant-card ant-card-bordered ant-card-hoverable" style="width: 240px;">
76+
<div class="ant-card-cover">
77+
<img alt="example" src="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png">
78+
</div>
79+
<div class="ant-card-body">
80+
<div class="ant-card-meta">
81+
<div class="ant-card-meta-detail">
82+
<div class="ant-card-meta-title">Europe Street beat</div>
83+
<div class="ant-card-meta-description">www.instagram.com</div>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
`;
89+
7490
exports[`renders ./components/card/demo/grid.md correctly 1`] = `
7591
<div class="ant-card ant-card-bordered">
7692
<div class="ant-card-head">
@@ -130,21 +146,24 @@ exports[`renders ./components/card/demo/inline.md correctly 1`] = `
130146
`;
131147
132148
exports[`renders ./components/card/demo/loading.md correctly 1`] = `
133-
<div class="ant-card ant-card-loading ant-card-bordered" style="width: 34%;">
134-
<div class="ant-card-head">
135-
<div class="ant-card-head-wrapper">
136-
<div class="ant-card-head-title">Card title</div>
149+
<div>
150+
<div class="ant-card ant-card-loading ant-card-bordered">
151+
<div class="ant-card-head">
152+
<div class="ant-card-head-wrapper">
153+
<div class="ant-card-head-title">Card title</div>
154+
</div>
137155
</div>
138-
</div>
139-
<div class="ant-card-body">
140-
<div class="ant-card-loading-content">
141-
<p class="ant-card-loading-block" style="width: 94%;"></p>
142-
<p><span class="ant-card-loading-block" style="width: 28%;"></span><span class="ant-card-loading-block" style="width: 62%;"></span></p>
143-
<p><span class="ant-card-loading-block" style="width: 22%;"></span><span class="ant-card-loading-block" style="width: 66%;"></span></p>
144-
<p><span class="ant-card-loading-block" style="width: 56%;"></span><span class="ant-card-loading-block" style="width: 39%;"></span></p>
145-
<p><span class="ant-card-loading-block" style="width: 21%;"></span><span class="ant-card-loading-block" style="width: 15%;"></span><span class="ant-card-loading-block" style="width: 40%;"></span></p>
156+
<div class="ant-card-body">
157+
<div class="ant-card-loading-content">
158+
<p class="ant-card-loading-block" style="width: 94%;"></p>
159+
<p><span class="ant-card-loading-block" style="width: 28%;"></span><span class="ant-card-loading-block" style="width: 62%;"></span></p>
160+
<p><span class="ant-card-loading-block" style="width: 22%;"></span><span class="ant-card-loading-block" style="width: 66%;"></span></p>
161+
<p><span class="ant-card-loading-block" style="width: 56%;"></span><span class="ant-card-loading-block" style="width: 39%;"></span></p>
162+
<p><span class="ant-card-loading-block" style="width: 21%;"></span><span class="ant-card-loading-block" style="width: 15%;"></span><span class="ant-card-loading-block" style="width: 40%;"></span></p>
163+
</div>
146164
</div>
147165
</div>
166+
<button type="button" class="ant-btn ant-btn-default" style="margin-top: 16px;"><span>Toggle loading</span></button>
148167
</div>
149168
`;
150169
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<cn>
2+
#### 更灵活的内容展示
3+
可以利用 `Card.Meta` 支持更灵活的内容
4+
</cn>
5+
6+
<us>
7+
#### Customized content
8+
You can use `Card.Meta` to support more flexible content.
9+
</us>
10+
11+
```html
12+
<template>
13+
<a-card
14+
hoverable
15+
style="width: 240px"
16+
>
17+
<img
18+
alt="example"
19+
src="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png"
20+
slot="cover"
21+
/>
22+
<a-card-meta
23+
title="Europe Street beat">
24+
<template slot="description">www.instagram.com</template>
25+
</a-card-meta>
26+
</a-card>
27+
</template>
28+
```

components/card/demo/index.vue

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Grid from './grid'
88
import Inline from './inline'
99
import TabsCard from './tabsCard'
1010
import MoreConfigs from './moreConfigs'
11+
import FlexibleContent from './flexible-content'
1112
1213
import CN from './../index.zh-CN.md'
1314
import US from './../index.en-US.md'
@@ -41,6 +42,7 @@ export default {
4142
<Basic />
4243
<NoBorder />
4344
<Concise />
45+
<FlexibleContent />
4446
<ColRowCard />
4547
<Loading />
4648
<Grid />

components/card/demo/loading.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,27 @@
1010

1111
```html
1212
<template>
13-
<a-card loading title="Card title" style="width: 34%;">
14-
whatever content
15-
</a-card>
13+
<div>
14+
<a-card :loading="loading" title="Card title">
15+
whatever content
16+
</a-card>
17+
<a-button @click="handleClick" style="marginTop: 16px">Toggle loading</a-button>
18+
</div>
1619
</template>
20+
<script>
21+
export default {
22+
data() {
23+
return {
24+
loading: true,
25+
}
26+
},
27+
methods: {
28+
handleClick() {
29+
this.loading = !this.loading
30+
}
31+
},
32+
}
33+
</script>
1734
```
1835

1936

components/card/demo/moreConfigs.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<cn>
2-
#### 更灵活的内容展示
3-
可以利用 `Card.Meta` 支持更灵活的内容
2+
#### 支持更多内容配置
3+
一种支持封面、头像、标题和描述信息的卡片。
44
</cn>
55

66
<us>
7-
#### Customized content
8-
You can use `Card.Meta` to support more flexible content.
7+
#### Support more content configuration
8+
A Card that supports `cover`, `avatar`, `title` and `description`.
99
</us>
1010

1111
```html

components/card/index.en-US.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@
1818
| type | Card style type, can be set to `inner` or not set | string | - |
1919
| onTabChange | Callback when tab is switched | (key) => void | - |
2020

21-
### Card.Grid
21+
### events
22+
| Events Name | Description | Arguments |
23+
| --- | --- | --- |
24+
| tabChange | Callback when tab is switched | (key) => void | - |
2225

23-
| Property | Description | Type | Default |
24-
| -------- | ----------- | ---- | ------- |
25-
| className | className of container | string | - |
26-
| style | style object of container | object | - |
26+
### Card.Grid
2727

2828
### Card.Meta
2929

3030
| Property | Description | Type | Default |
3131
| -------- | ----------- | ---- | ------- |
3232
| avatar | avatar or icon | slot | - |
33-
| className | className of container | string | - |
34-
| description | description content | slot | - |
35-
| style | style object of container | object | - |
36-
| title | title content | slot | - |
33+
| description | description content | string\|slot | - |
34+
| title | title content | string\|slot | - |

components/card/index.zh-CN.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919
| type | 卡片类型,可设置为 `inner` 或 不设置 | string | - |
2020
| onTabChange | 页签切换的回调 | (key) => void | - |
2121

22-
### Card.Grid
22+
### 事件
23+
| 事件名称 | 说明 | 回调参数 |
24+
| --- | --- | --- |
25+
| tabChange | 页签切换的回调 | (key) => void | - |
2326

24-
| Property | Description | Type | Default |
25-
| -------- | ----------- | ---- | ------- |
26-
| className | 网格容器类名 | string | - |
27-
| style | 定义网格容器类名的样式 | object | - |
27+
### Card.Grid
2828

2929
### Card.Meta
3030

3131
| Property | Description | Type | Default |
3232
| -------- | ----------- | ---- | ------- |
3333
| avatar | 头像/图标 | slot | - |
34-
| className | 容器类名 | string | - |
35-
| description | 描述内容 | slot | - |
36-
| style | 定义容器类名的样式 | object | - |
37-
| title | 标题内容 | slot | - |
34+
| description | 描述内容 | string\|slot | - |
35+
| title | 标题内容 | string\|slot | - |

site/dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Api from './components/api'
1010
import './components'
1111
import demoBox from './components/demoBox'
1212
import demoContainer from './components/demoContainer'
13-
import Test from '../components/test/index'
13+
import Test from '../components/card/demo/index'
1414

1515
Vue.use(VueClipboard)
1616
Vue.use(VueRouter)

0 commit comments

Comments
 (0)