feat: update card

pull/666/head
wangxueliang 2019-03-13 21:32:14 +08:00
parent 5f09422d87
commit 9bcb12e611
6 changed files with 49 additions and 21 deletions

View File

@ -7,13 +7,14 @@ import addEventListener from '../_util/Dom/addEventListener';
import { getComponentFromProp, getSlotOptions, filterEmpty } from '../_util/props-util'; import { getComponentFromProp, getSlotOptions, filterEmpty } from '../_util/props-util';
import throttleByAnimationFrame from '../_util/throttleByAnimationFrame'; import throttleByAnimationFrame from '../_util/throttleByAnimationFrame';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import { ConfigConsumerProps } from '../config-provider';
const { TabPane } = Tabs; const { TabPane } = Tabs;
export default { export default {
name: 'ACard', name: 'ACard',
mixins: [BaseMixin], mixins: [BaseMixin],
props: { props: {
prefixCls: PropTypes.string.def('ant-card'), prefixCls: PropTypes.string,
title: PropTypes.any, title: PropTypes.any,
extra: PropTypes.any, extra: PropTypes.any,
bordered: PropTypes.bool.def(true), bordered: PropTypes.bool.def(true),
@ -22,11 +23,15 @@ export default {
loading: PropTypes.bool.def(false), loading: PropTypes.bool.def(false),
hoverable: PropTypes.bool.def(false), hoverable: PropTypes.bool.def(false),
type: PropTypes.string, type: PropTypes.string,
size: PropTypes.oneOf(['default', 'small']),
actions: PropTypes.any, actions: PropTypes.any,
tabList: PropTypes.array, tabList: PropTypes.array,
activeTabKey: PropTypes.string, activeTabKey: PropTypes.string,
defaultActiveTabKey: PropTypes.string, defaultActiveTabKey: PropTypes.string,
}, },
inject: {
configProvider: { default: () => ({}) },
},
data() { data() {
this.updateWiderPaddingCalled = false; this.updateWiderPaddingCalled = false;
return { return {
@ -91,11 +96,12 @@ export default {
}, },
render() { render() {
const { const {
prefixCls = 'ant-card', prefixCls: customizePrefixCls,
headStyle = {}, headStyle = {},
bodyStyle = {}, bodyStyle = {},
loading, loading,
bordered = true, bordered = true,
size = 'default',
type, type,
tabList, tabList,
hoverable, hoverable,
@ -103,6 +109,9 @@ export default {
defaultActiveTabKey, defaultActiveTabKey,
} = this.$props; } = this.$props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('card', customizePrefixCls);
const { $slots, $scopedSlots, $listeners } = this; const { $slots, $scopedSlots, $listeners } = this;
const classString = { const classString = {
@ -114,6 +123,7 @@ export default {
[`${prefixCls}-padding-transition`]: this.updateWiderPaddingCalled, [`${prefixCls}-padding-transition`]: this.updateWiderPaddingCalled,
[`${prefixCls}-contain-grid`]: this.isContainGrid($slots.default), [`${prefixCls}-contain-grid`]: this.isContainGrid($slots.default),
[`${prefixCls}-contain-tabs`]: tabList && tabList.length, [`${prefixCls}-contain-tabs`]: tabList && tabList.length,
[`${prefixCls}-${size}`]: size !== 'default',
[`${prefixCls}-type-${type}`]: !!type, [`${prefixCls}-type-${type}`]: !!type,
}; };
@ -162,17 +172,6 @@ export default {
<div class={`${prefixCls}-loading-block`} /> <div class={`${prefixCls}-loading-block`} />
</Col> </Col>
</Row> </Row>
<Row gutter={8}>
<Col span={8}>
<div class={`${prefixCls}-loading-block`} />
</Col>
<Col span={6}>
<div class={`${prefixCls}-loading-block`} />
</Col>
<Col span={8}>
<div class={`${prefixCls}-loading-block`} />
</Col>
</Row>
</div> </div>
); );

View File

@ -1,4 +1,5 @@
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { ConfigConsumerProps } from '../config-provider';
export default { export default {
name: 'ACardGrid', name: 'ACardGrid',
@ -6,8 +7,15 @@ export default {
props: { props: {
prefixCls: PropTypes.string.def('ant-card'), prefixCls: PropTypes.string.def('ant-card'),
}, },
inject: {
configProvider: { default: () => ({}) },
},
render() { render() {
const { prefixCls = 'ant-card' } = this.$props; const { prefixCls: customizePrefixCls } = this.$props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('card', customizePrefixCls);
const classString = { const classString = {
[`${prefixCls}-grid`]: true, [`${prefixCls}-grid`]: true,
}; };

View File

@ -1,5 +1,6 @@
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { getComponentFromProp } from '../_util/props-util'; import { getComponentFromProp } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export default { export default {
name: 'ACardMeta', name: 'ACardMeta',
@ -8,8 +9,15 @@ export default {
title: PropTypes.any, title: PropTypes.any,
description: PropTypes.any, description: PropTypes.any,
}, },
inject: {
configProvider: { default: () => ({}) },
},
render() { render() {
const { prefixCls = 'ant-card' } = this.$props; const { prefixCls: customizePrefixCls } = this.$props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('card', customizePrefixCls);
const classString = { const classString = {
[`${prefixCls}-meta`]: true, [`${prefixCls}-meta`]: true,
}; };

View File

@ -1,20 +1,31 @@
<cn> <cn>
#### 典型卡片 #### 典型卡片
包含标题、内容、操作区域。 包含标题、内容、操作区域。
可通过设置size为`default`或者`small`,控制尺寸
</cn> </cn>
<us> <us>
#### Basic card #### Basic card
A basic card containing a title, content and an extra corner content. A basic card containing a title, content and an extra corner content.
Supports two sizes: `default` and `small`.
</us> </us>
```html ```html
<template> <template>
<a-card title="Card Title"> <div>
<a href="#" slot="extra">more</a> <a-card title="Default size card" style="width: 300px">
<p>card content</p> <a href="#" slot="extra">more</a>
<p>card content</p> <p>card content</p>
<p>card content</p> <p>card content</p>
</a-card> <p>card content</p>
</a-card>
<br>
<a-card size="small" title="Small size card" style="width: 300px">
<a href="#" slot="extra">more</a>
<p>card content</p>
<p>card content</p>
<p>card content</p>
</a-card>
</div>
</template> </template>
``` ```

View File

@ -15,6 +15,7 @@
| hoverable | Lift up when hovering card | boolean | false | | hoverable | Lift up when hovering card | boolean | false |
| loading | Shows a loading indicator while the contents of the card are being fetched | boolean | false | | loading | Shows a loading indicator while the contents of the card are being fetched | boolean | false |
| tabList | List of TabPane's head, Custom tabs can be created with the scopedSlots property | Array<{key: string, tab: any, scopedSlots: {tab: 'XXX'}}> | - | | tabList | List of TabPane's head, Custom tabs can be created with the scopedSlots property | Array<{key: string, tab: any, scopedSlots: {tab: 'XXX'}}> | - |
| size | Size of card | `default` \| `small` | `default` |
| title | Card title | string\|slot | - | | title | Card title | string\|slot | - |
| 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 | - |

View File

@ -16,6 +16,7 @@
| hoverable | 鼠标移过时可浮起 | boolean | false | | hoverable | 鼠标移过时可浮起 | boolean | false |
| loading | 当卡片内容还在加载中时,可以用 loading 展示一个占位 | boolean | false | | loading | 当卡片内容还在加载中时,可以用 loading 展示一个占位 | boolean | false |
| tabList | 页签标题列表, 可以通过scopedSlots属性自定义tab | Array<{key: string, tab: any, scopedSlots: {tab: 'XXX'}}> | - | | tabList | 页签标题列表, 可以通过scopedSlots属性自定义tab | Array<{key: string, tab: any, scopedSlots: {tab: 'XXX'}}> | - |
| size | card 的尺寸 | `default` \| `small` | `default` |
| title | 卡片标题 | string\|slot | - | | title | 卡片标题 | string\|slot | - |
| type | 卡片类型,可设置为 `inner` 或 不设置 | string | - | | type | 卡片类型,可设置为 `inner` 或 不设置 | string | - |