Skip to content

Commit

Permalink
feat(Card): add free card
Browse files Browse the repository at this point in the history
  • Loading branch information
myronliu347 committed Sep 11, 2019
1 parent 7ac35b0 commit 5ee79c7
Show file tree
Hide file tree
Showing 16 changed files with 991 additions and 146 deletions.
110 changes: 110 additions & 0 deletions docs/card/demo/free.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 自定义卡片

- order: 5

与子组件的组合来自定义卡片样式

:::lang=en-us
# Free Mode

- order: 5

Combination with subcomponents to customize card styles

:::

---

````jsx
import { Card, Button } from '@alifd/next';

ReactDOM.render(
<div>
<Card
className="free-card"
free
>
<Card.Media style={{ height: 140 }} image="https://img.alicdn.com/tfs/TB1FNIOSFXXXXaWXXXXXXXXXXXX-260-188.png" />
<Card.BulletHeader title="Title" subTitle="Sub Title" extra={<Button type="primary" text>Link</Button>} />
<Card.CollaspeContent contentHeight="auto">
Lorem ipsum dolor sit amet, est viderer iuvaret perfecto et. Ne petentium quaerendum nec, eos ex recteque mediocritatem, ex usu assum legendos temporibus. Ius feugiat pertinacia an, cu verterem praesent quo.
</Card.CollaspeContent>
<Card.Actions>
<Button type="primary" key="action1" text>Action 1</Button>
<Button type="primary" key="action2" text>Action 2</Button>
</Card.Actions>
</Card>

<Card
className="free-card"
free
>
<Card.Media style={{ height: 140 }} image="https://img.alicdn.com/tfs/TB1FNIOSFXXXXaWXXXXXXXXXXXX-260-188.png" />
<Card.Header title="Title" subTitle="Sub Title" extra={<Button type="primary" text>Link</Button>} />
<Card.Divider />
<Card.Content>
Lorem ipsum dolor sit amet, est viderer iuvaret perfecto et. Ne petentium quaerendum nec, eos ex recteque mediocritatem, ex usu assum legendos temporibus. Ius feugiat pertinacia an, cu verterem praesent quo.
</Card.Content>
<Card.Actions>
<Button type="primary" key="action1" text>Action 1</Button>
<Button type="primary" key="action2" text>Action 2</Button>
</Card.Actions>
</Card>
<Card
className="free-card custom"
free
>
<Card.Media image="https://img.alicdn.com/tfs/TB1FNIOSFXXXXaWXXXXXXXXXXXX-260-188.png" />
<div className="free-card-main">
<Card.Header title="Title" subTitle="Sub Title" extra={<Button type="primary" text>Link</Button>} />
<Card.Divider />
<Card.Content>
Lorem ipsum dolor sit amet, est viderer iuvaret perfecto et.
</Card.Content>
<Card.Actions>
<Button type="primary" key="action1" text>Action 1</Button>
<Button type="primary" key="action2" text>Action 2</Button>
</Card.Actions>
</div>
</Card>
</div>
, mountNode);
````

````css
.free-card {
display: inline-block;
width: 300px;
vertical-align: top;
}
.free-card + .free-card {
margin-left: 20px;
}

.free-card.custom {
display: flex;
justify-content: space-between;
width: 500px;
height: 200px;
}

.free-card.custom .next-card-media {
height: 100%;
width: 200px;
flex-shrink: 0;
}

.free-card-main {
display: flex;
flex-direction: column;
align-items: stretch;
}

.free-card-main .next-card-content-container {
flex: 1;
}

.free-card-main .next-card-actions {
text-align: right;
}
````
50 changes: 50 additions & 0 deletions docs/card/demo/media.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 多媒体内容

- order: 4

下面是一个使用图像来增强内容的卡片示例。

:::lang=en-us
# Media Content

- order: 4

Here is an example of a card that uses images to enhance content.

:::

---

````jsx
import { Card, Button } from '@alifd/next';

ReactDOM.render(
<Card
className="media-card"
media={<img src="https://img.alicdn.com/tfs/TB1FNIOSFXXXXaWXXXXXXXXXXXX-260-188.png" />}
contentHeight="auto"
title="Title"
subTitle="Sub Title"
extra={[
<Button type="primary" key="action1" text>More</Button>
]}
actions={[
<Button type="primary" key="action1" text>Action 1</Button>,
<Button type="primary" key="action2" text>Action 2</Button>
]}
>
Lorem ipsum dolor sit amet, est viderer iuvaret perfecto et. Ne petentium quaerendum nec, eos ex recteque mediocritatem, ex usu assum legendos temporibus. Ius feugiat pertinacia an, cu verterem praesent quo.

</Card>
, mountNode);
````

````css
.media-card {
width: 300px;
}

.custom-card p {
color: #999;
}
````
38 changes: 38 additions & 0 deletions docs/card/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,41 @@ A card could contain a photo, text, and a link about a single subject.
| showHeadDivider | If show head divider | Boolean | true |
| contentHeight | Height of content | String/Number | 120 |
| extra | Extra of card header | ReactNode | - |
| media | Media content | ReactNode | - |
| actions | Actions of card | ReactNode | - |
| free | Whether to open free mode, if opened, can`t set title subTitle ..., must use Card.Header Card.Content ... to set Card | Boolean | - |

### Card.Actions

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------ | ------ | ----- |
| component | The html tag to be rendered | custom | 'div' |

### Card.Content

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------ | ------ | ----- |
| component | The html tag to be rendered | custom | 'div' |

### Card.Divider

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------ | ------ | ---- |
| component | The html tag to be rendered | custom | 'hr' |

### Card.Header

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------------ | --------- | ----- |
| title | Title of card | ReactNode | - |
| subTitle | Sub Title of Card | ReactNode | - |
| extra | Extra of card header | ReactNode | - |
| component | The html tag to be rendered | custom | 'div' |

### Card.Media

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------- | ------ | ----- |
| component | The html tag to be rendered | custom | 'div' |
| image | Media background image | String | - |
| src | Media source URL | String | - |
54 changes: 46 additions & 8 deletions docs/card/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,49 @@

### Card

| 参数 | 说明 | 类型 | 默认值 |
| --------------- | ------------ | ------------- | ---- |
| title | 卡片的标题 | ReactNode | - |
| subTitle | 卡片的副标题 | ReactNode | - |
| showTitleBullet | 是否显示标题的项目符号 | Boolean | true |
| showHeadDivider | 是否展示头部的分隔线 | Boolean | true |
| contentHeight | 内容区域的固定高度 | String/Number | 120 |
| extra | 标题区域的用户自定义内容 | ReactNode | - |
| 参数 | 说明 | 类型 | 默认值 |
| --------------- | ------------------------------------------------------------ | ------------- | ----- |
| media | 卡片的上的图片 / 视频 | ReactNode | - |
| title | 卡片的标题 | ReactNode | - |
| subTitle | 卡片的副标题 | ReactNode | - |
| actions | 卡片操作组,位置在卡片底部 | ReactNode | - |
| showTitleBullet | 是否显示标题的项目符号 | Boolean | true |
| showHeadDivider | 是否展示头部的分隔线 | Boolean | true |
| contentHeight | 内容区域的固定高度 | String/Number | 120 |
| extra | 标题区域的用户自定义内容 | ReactNode | - |
| free | 是否开启自由模式,开启后card 将使用子组件配合使用, 设置此项后 title, subtitle, 等等属性都将失效 | Boolean | false |

### Card.Actions

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------ | ------ | ----- |
| component | 设置标签类型 | custom | 'div' |

### Card.Content

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------ | ------ | ----- |
| component | 设置标签类型 | custom | 'div' |

### Card.Divider

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------ | ------ | ---- |
| component | 设置标签类型 | custom | 'hr' |

### Card.Header

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------------ | --------- | ----- |
| title | 卡片的标题 | ReactNode | - |
| subTitle | 卡片的副标题 | ReactNode | - |
| extra | 标题区域的用户自定义内容 | ReactNode | - |
| component | 设置标签类型 | custom | 'div' |

### Card.Media

| 参数 | 说明 | 类型 | 默认值 |
| --------- | ------- | ------ | ----- |
| component | 设置标签类型 | custom | 'div' |
| image | 背景图片地址 | String | - |
| src | 媒体源文件地址 | String | - |
40 changes: 40 additions & 0 deletions src/card/actions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ConfigProvider from '../config-provider';

/**
* Card.Actions
*/
class CardActions extends PureComponent {
static propTypes = {
prefix: PropTypes.string,
/**
* 设置标签类型
*/
component: PropTypes.elementType,
className: PropTypes.string,
};

static defaultProps = {
prefix: 'next-',
component: 'div',
};

render() {
const {
prefix,
component: Component,
className,
...others
} = this.props;
return (
<Component
{...others}
className={classNames(`${prefix}card-actions`, className)}
/>
);
}
}

export default ConfigProvider.config(CardActions);
69 changes: 69 additions & 0 deletions src/card/bullet-header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ConfigProvider from '../config-provider';

/**
* Card.BulletHeader
*/
class CardBulletHeader extends Component {
static propTypes = {
prefix: PropTypes.string,
/**
* 卡片的标题
*/
title: PropTypes.node,
/**
* 卡片的副标题
*/
subTitle: PropTypes.node,
/**
* 是否显示标题的项目符号
*/
showTitleBullet: PropTypes.bool,
/**
* 标题区域的用户自定义内容
*/
extra: PropTypes.node,
};

static defaultProps = {
prefix: 'next-',
showTitleBullet: true,
};

render() {
const { prefix, title, subTitle, extra, showTitleBullet } = this.props;

if (!title) return null;

const headCls = classNames({
[`${prefix}card-head`]: true,
[`${prefix}card-head-show-bullet`]: showTitleBullet,
});

const headExtra = extra ? (
<div className={`${prefix}card-extra`}>{extra}</div>
) : null;

return (
<div className={headCls}>
<div className={`${prefix}card-head-main`}>
<div className={`${prefix}card-title`}>
{title}
{subTitle ? (
<span className={`${prefix}card-subtitle`}>
{subTitle}
</span>
) : null}
</div>
{headExtra}
</div>
</div>
);
}
}

export default ConfigProvider.config(CardBulletHeader, {
componentName: 'Card',
});
Loading

0 comments on commit 5ee79c7

Please sign in to comment.