Merge pull request #84 from wangxueliang/master

fix: support card description and title slot
pull/165/head
三点包子 2018-07-27 18:35:40 +08:00 committed by GitHub
commit 94b507b6da
11 changed files with 111 additions and 46 deletions

View File

@ -12,7 +12,7 @@ export default {
mixins: [BaseMixin], mixins: [BaseMixin],
props: { props: {
prefixCls: PropTypes.string.def('ant-card'), prefixCls: PropTypes.string.def('ant-card'),
title: PropTypes.string, title: PropTypes.any,
extra: PropTypes.any, extra: PropTypes.any,
bordered: PropTypes.bool.def(true), bordered: PropTypes.bool.def(true),
bodyStyle: PropTypes.object, bodyStyle: PropTypes.object,

View File

@ -7,12 +7,12 @@ export default {
prefixCls: PropTypes.string.def('ant-card'), prefixCls: PropTypes.string.def('ant-card'),
}, },
render () { render () {
const { prefixCls = 'ant-card', ...others } = this.$props const { prefixCls = 'ant-card' } = this.$props
const classString = { const classString = {
[`${prefixCls}-grid`]: true, [`${prefixCls}-grid`]: true,
} }
return ( return (
<div {...others} class={classString}>{this.$slots.default}</div> <div {...{ on: this.$listeners }} class={classString}>{this.$slots.default}</div>
) )
}, },
} }

View File

@ -6,16 +6,19 @@ export default {
name: 'ACardMeta', name: 'ACardMeta',
props: { props: {
prefixCls: PropTypes.string.def('ant-card'), prefixCls: PropTypes.string.def('ant-card'),
title: PropTypes.string, title: PropTypes.any,
description: PropTypes.string, description: PropTypes.any,
}, },
render () { render () {
const { prefixCls = 'ant-card', title, description, ...others } = this.$props const { prefixCls = 'ant-card' } = this.$props
const classString = { const classString = {
[`${prefixCls}-meta`]: true, [`${prefixCls}-meta`]: true,
} }
const avatar = getComponentFromProp(this, 'avatar') const avatar = getComponentFromProp(this, 'avatar')
const title = getComponentFromProp(this, 'title')
const description = getComponentFromProp(this, 'description')
const avatarDom = avatar ? <div class={`${prefixCls}-meta-avatar`}>{avatar}</div> : null const avatarDom = avatar ? <div class={`${prefixCls}-meta-avatar`}>{avatar}</div> : null
const titleDom = title ? <div class={`${prefixCls}-meta-title`}>{title}</div> : null const titleDom = title ? <div class={`${prefixCls}-meta-title`}>{title}</div> : null
const descriptionDom = description const descriptionDom = description
@ -26,7 +29,7 @@ export default {
{descriptionDom} {descriptionDom}
</div> : null </div> : null
return ( return (
<div {...others} class={classString}> <div {...{ on: this.$listeners }} class={classString}>
{avatarDom} {avatarDom}
{MetaDetail} {MetaDetail}
</div> </div>

View File

@ -71,6 +71,22 @@ exports[`renders ./components/card/demo/concise.md correctly 1`] = `
</div> </div>
`; `;
exports[`renders ./components/card/demo/flexible-content.md correctly 1`] = `
<div class="ant-card ant-card-bordered ant-card-hoverable" style="width: 240px;">
<div class="ant-card-cover">
<img alt="example" src="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png">
</div>
<div class="ant-card-body">
<div class="ant-card-meta">
<div class="ant-card-meta-detail">
<div class="ant-card-meta-title">Europe Street beat</div>
<div class="ant-card-meta-description">www.instagram.com</div>
</div>
</div>
</div>
</div>
`;
exports[`renders ./components/card/demo/grid.md correctly 1`] = ` exports[`renders ./components/card/demo/grid.md correctly 1`] = `
<div class="ant-card ant-card-bordered"> <div class="ant-card ant-card-bordered">
<div class="ant-card-head"> <div class="ant-card-head">
@ -130,7 +146,8 @@ exports[`renders ./components/card/demo/inline.md correctly 1`] = `
`; `;
exports[`renders ./components/card/demo/loading.md correctly 1`] = ` exports[`renders ./components/card/demo/loading.md correctly 1`] = `
<div class="ant-card ant-card-loading ant-card-bordered" style="width: 34%;"> <div>
<div class="ant-card ant-card-loading ant-card-bordered">
<div class="ant-card-head"> <div class="ant-card-head">
<div class="ant-card-head-wrapper"> <div class="ant-card-head-wrapper">
<div class="ant-card-head-title">Card title</div> <div class="ant-card-head-title">Card title</div>
@ -146,6 +163,8 @@ exports[`renders ./components/card/demo/loading.md correctly 1`] = `
</div> </div>
</div> </div>
</div> </div>
<button type="button" class="ant-btn ant-btn-default" style="margin-top: 16px;"><span>Toggle loading</span></button>
</div>
`; `;
exports[`renders ./components/card/demo/moreConfigs.md correctly 1`] = ` exports[`renders ./components/card/demo/moreConfigs.md correctly 1`] = `

View File

@ -0,0 +1,28 @@
<cn>
#### 更灵活的内容展示
可以利用 `Card.Meta` 支持更灵活的内容
</cn>
<us>
#### Customized content
You can use `Card.Meta` to support more flexible content.
</us>
```html
<template>
<a-card
hoverable
style="width: 240px"
>
<img
alt="example"
src="https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png"
slot="cover"
/>
<a-card-meta
title="Europe Street beat">
<template slot="description">www.instagram.com</template>
</a-card-meta>
</a-card>
</template>
```

View File

@ -8,6 +8,7 @@ import Grid from './grid'
import Inline from './inline' import Inline from './inline'
import TabsCard from './tabsCard' import TabsCard from './tabsCard'
import MoreConfigs from './moreConfigs' import MoreConfigs from './moreConfigs'
import FlexibleContent from './flexible-content'
import CN from './../index.zh-CN.md' import CN from './../index.zh-CN.md'
import US from './../index.en-US.md' import US from './../index.en-US.md'
@ -41,6 +42,7 @@ export default {
<Basic /> <Basic />
<NoBorder /> <NoBorder />
<Concise /> <Concise />
<FlexibleContent />
<ColRowCard /> <ColRowCard />
<Loading /> <Loading />
<Grid /> <Grid />

View File

@ -10,10 +10,27 @@
```html ```html
<template> <template>
<a-card loading title="Card title" style="width: 34%;"> <div>
<a-card :loading="loading" title="Card title">
whatever content whatever content
</a-card> </a-card>
<a-button @click="handleClick" style="marginTop: 16px">Toggle loading</a-button>
</div>
</template> </template>
<script>
export default {
data() {
return {
loading: true,
}
},
methods: {
handleClick() {
this.loading = !this.loading
}
},
}
</script>
``` ```

View File

@ -1,11 +1,11 @@
<cn> <cn>
#### 更灵活的内容展示 #### 支持更多内容配置
可以利用 `Card.Meta` 支持更灵活的内容 一种支持封面、头像、标题和描述信息的卡片。
</cn> </cn>
<us> <us>
#### Customized content #### Support more content configuration
You can use `Card.Meta` to support more flexible content. A Card that supports `cover`, `avatar`, `title` and `description`.
</us> </us>
```html ```html

View File

@ -18,19 +18,17 @@
| type | Card style type, can be set to `inner` or not set | string | - | | type | Card style type, can be set to `inner` or not set | string | - |
| onTabChange | Callback when tab is switched | (key) => void | - | | onTabChange | Callback when tab is switched | (key) => void | - |
### Card.Grid ### events
| Events Name | Description | Arguments |
| --- | --- | --- |
| tabChange | Callback when tab is switched | (key) => void | - |
| Property | Description | Type | Default | ### Card.Grid
| -------- | ----------- | ---- | ------- |
| className | className of container | string | - |
| style | style object of container | object | - |
### Card.Meta ### Card.Meta
| Property | Description | Type | Default | | Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- | | -------- | ----------- | ---- | ------- |
| avatar | avatar or icon | slot | - | | avatar | avatar or icon | slot | - |
| className | className of container | string | - | | description | description content | string\|slot | - |
| description | description content | slot | - | | title | title content | string\|slot | - |
| style | style object of container | object | - |
| title | title content | slot | - |

View File

@ -19,19 +19,17 @@
| type | 卡片类型,可设置为 `inner` 或 不设置 | string | - | | type | 卡片类型,可设置为 `inner` 或 不设置 | string | - |
| onTabChange | 页签切换的回调 | (key) => void | - | | onTabChange | 页签切换的回调 | (key) => void | - |
### Card.Grid ### 事件
| 事件名称 | 说明 | 回调参数 |
| --- | --- | --- |
| tabChange | 页签切换的回调 | (key) => void | - |
| Property | Description | Type | Default | ### Card.Grid
| -------- | ----------- | ---- | ------- |
| className | 网格容器类名 | string | - |
| style | 定义网格容器类名的样式 | object | - |
### Card.Meta ### Card.Meta
| Property | Description | Type | Default | | Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- | | -------- | ----------- | ---- | ------- |
| avatar | 头像/图标 | slot | - | | avatar | 头像/图标 | slot | - |
| className | 容器类名 | string | - | | description | 描述内容 | string\|slot | - |
| description | 描述内容 | slot | - | | title | 标题内容 | string\|slot | - |
| style | 定义容器类名的样式 | object | - |
| title | 标题内容 | slot | - |

View File

@ -10,7 +10,7 @@ import Api from './components/api'
import './components' import './components'
import demoBox from './components/demoBox' import demoBox from './components/demoBox'
import demoContainer from './components/demoContainer' import demoContainer from './components/demoContainer'
import Test from '../components/test/index' import Test from '../components/card/demo/index'
Vue.use(VueClipboard) Vue.use(VueClipboard)
Vue.use(VueRouter) Vue.use(VueRouter)