Skip to content

Commit

Permalink
feat(List): add loading/emptyContent/dataSource/renderItem, close ali…
Browse files Browse the repository at this point in the history
…baba-fusion#2050 (alibaba-fusion#2105)

* feat(List): add loading/emptyContent/dataSource/renderItem, close alibaba-fusion#2050
  • Loading branch information
youluna authored Aug 24, 2020
1 parent 5017eb2 commit 1fb62bf
Show file tree
Hide file tree
Showing 21 changed files with 473 additions and 61 deletions.
36 changes: 29 additions & 7 deletions docs/list/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,37 @@ Simple usage of List component.
````jsx
import { List, Avatar } from '@alifd/next';

const data = [
{
title: 'A Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
{
title: 'B Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$10',
},
{
title: 'Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
{
title: 'Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
];

ReactDOM.render(
<div style={{width: 288}}>
<List size="small" header={<div>Notifications</div>}>
<List.Item extra={'$20'} media={<Avatar src={'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png'}/>} title="Title">List Item 1</List.Item>
<List.Item extra={'$20'} title="Title" media={<Avatar src={'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png'}/>}>List Item 2</List.Item>
<List.Item extra={'$20'} title="Title" media={<Avatar src={'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png'}/>}>List Item 3</List.Item>
<List.Item extra={'$20'} title="Title" media={<Avatar src={'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png'}/>}>List Item 4</List.Item>
<List.Item extra={'$20'} title="Title" media={<Avatar src={'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png'}/>}>List Item 5</List.Item>
</List>
<List
size="small"
header={<div>Notifications</div>}
dataSource={data}
renderItem={(item, i) => <List.Item key={i} extra={item.money} title={item.title} media={<Avatar src={item.img}/>}>List Item {i}</List.Item>}
/>
</div>
, mountNode);
````
Expand Down
56 changes: 32 additions & 24 deletions docs/list/demo/complex.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 大列表

- order: 0
- order: 1

页面级列表展示

:::lang=en-us
# Basic Usage

- order: 0
- order: 1

Simple usage of List component.

Expand All @@ -17,6 +17,27 @@ Simple usage of List component.
````jsx
import { List, Avatar, Box, Button, Divider } from '@alifd/next';

const data = [{
title: '构建一套产品化设计系统',
description: '随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …',
author: '谢瑶 3 小时前更新',
img: 'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png',
}, {
title: '构建一套产品化设计系统',
description: '随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …',
author: '谢瑶 3 小时前更新',
img: 'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png',
}, {
title: '构建一套产品化设计系统',
description: '随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …',
author: '谢瑶 3 小时前更新',
img: 'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png',
}, {
title: '构建一套产品化设计系统',
description: '随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …',
author: '谢瑶 3 小时前更新',
img: 'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png',
}];
const actions = (
<Box direction="row" align="center" style={{whiteSpace: 'nowrap', height: '100%', paddingLeft: 100}}>
<Button text type="primary">编辑</Button>
Expand All @@ -28,28 +49,15 @@ const actions = (
);

ReactDOM.render(
<List>
<List.Item extra={actions} media={<img width="161" height="108" src={'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png'}/>} title="构建一套产品化设计系统">
<p style={{margin: '12px 0'}}>随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …</p>
<div>谢瑶 3 小时前更新</div>
</List.Item>
<List.Item extra={actions} title="构建一套产品化设计系统" media={<img width="161" height="108" src={'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png'}/>}>
<p style={{margin: '12px 0'}}>随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …</p>
<div>谢瑶 3 小时前更新</div>
</List.Item>
<List.Item extra={actions} title="构建一套产品化设计系统" media={<img width="161" height="108" src={'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png'}/>}>
<p style={{margin: '12px 0'}}>随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …</p>
<div>谢瑶 3 小时前更新</div>
</List.Item>
<List.Item extra={actions} title="构建一套产品化设计系统" media={<img width="161" height="108" src={'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png'}/>}>
<p style={{margin: '12px 0'}}>随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …</p>
<div>谢瑶 3 小时前更新</div>
</List.Item>
<List.Item extra={actions} title="构建一套产品化设计系统" media={<img width="161" height="108" src={'https://img.alicdn.com/tfs/TB1R5fio4v1gK0jSZFFXXb0sXXa-322-216.png'}/>}>
<p style={{margin: '12px 0'}}>随着互联网行业的聚变式发展,在电商业务从“信息透出” 到 “在线交易” 的过程中,网站 UI 构建也经历了“体验一致性”、“设计效率”、“UI系统构建/应用效率”、“多端适配” …</p>
<div>谢瑶 3 小时前更新</div>
</List.Item>
</List>
<List
dataSource={data}
renderItem={(item, i) => (
<List.Item key={i} extra={actions} media={<img width="161" height="108" src={item.img}/>} title={item.title}>
<p style={{margin: '12px 0'}}>{item.description}</p>
<div>{item.author}</div>
</List.Item>
)}
/>
, mountNode);
````

Expand Down
79 changes: 79 additions & 0 deletions docs/list/demo/custom-loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 自定义 loading 样式

- order: 3

自定义 `loading` 样式。

:::lang=en-us
# Basic Usage

- order: 3

Custom Loading component.

:::
---

````jsx
import { List, Avatar, Button, Loading, Icon } from '@alifd/next';
import { useState } from 'react';

const data = [
{
title: 'A Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
{
title: 'B Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$10',
},
{
title: 'Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
{
title: 'Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
];

const indicator = (
<div>
<Icon type="loading" />
</div>
);

const CustomLoading = (props) => (
<Loading
indicator={indicator}
{...props}
/>
);

const App = () => {
const [loading, setLoading] = useState(false);

return <div style={{width: 288}}>
<Button onClick={() => setLoading(!loading)}>Toggle loading</Button>
<List
size="small"
loading={loading}
loadingComponent={CustomLoading}
header={<div>Notifications</div>}
dataSource={data}
renderItem={(item, i) => <List.Item key={i} extra={item.money} title={item.title} media={<Avatar src={item.img}/>}>List Item {i}</List.Item>}
/>
</div>
}
ReactDOM.render(
<App />
, mountNode);
````

````css

````
33 changes: 33 additions & 0 deletions docs/list/demo/empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 空状态

- order: 4

无数据时候的列表展示。

:::lang=en-us
# Basic Usage

- order: 4

List widthout data.

:::
---

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

ReactDOM.render(
<div style={{width: 288}}>
<List
size="small"
header={<div>Notifications</div>}
dataSource={[]}
renderItem={(item, i) => <List.Item key={i} extra={item.money} title={item.title} media={<Avatar src={item.img}/>}>List Item {i}</List.Item>}
/>
</div>
, mountNode);
````
````css

````
65 changes: 65 additions & 0 deletions docs/list/demo/loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 带 loading 列表

- order: 2

`loading` 的列表展示。

:::lang=en-us
# Basic Usage

- order: 2

List width loading.

:::
---

````jsx
import { List, Avatar, Button } from '@alifd/next';
import { useState } from 'react';

const data = [
{
title: 'A Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
{
title: 'B Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$10',
},
{
title: 'Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
{
title: 'Title',
img: 'https://img.alicdn.com/tfs/TB1QS.4l4z1gK0jSZSgXXavwpXa-1024-1024.png',
money: '$20',
},
];

const App = () => {
const [loading, setLoading] = useState(false);

return <div style={{width: 288}}>
<Button onClick={() => setLoading(!loading)}>Toggle loading</Button>
<List
size="small"
loading={loading}
header={<div>Notifications</div>}
dataSource={data}
renderItem={(item, i) => <List.Item key={i} extra={item.money} title={item.title} media={<Avatar src={item.img}/>}>List Item {i}</List.Item>}
/>
</div>
}
ReactDOM.render(
<App />
, mountNode);
````

````css

````
14 changes: 10 additions & 4 deletions docs/list/index.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ The content can consist of multiple elements of varying type and size.
| size | List size <br><br>**Options**:<br>'medium', 'small' | Enum | 'medium' |
| footer | List footer | ReactNode | - |
| divider | Toggles rendering of the divider the list item | Boolean | true |
| dataSource | datasource of List | Array | - |
| renderItem | when dataSource is set, you can custmize every item by `renderItem` <br><br>**signature**:<br>Function(current: Any, index: Number) => void<br>**params**:<br>_current_: {Any} current item<br>_index_: {Number} index of item | Function | item => item |
| loading | is loading | Boolean | false |
| loadingComponent | custmize Loading Component<br> loadingComponent={props => &lt;Loading {...props}/>}<br><br>**signature**:<br>Function() => void | Function | - |
| emptyContent | content when list is empty | ReactNode | - |


### List.Item

| Param | Descripiton | Type | Default Value |
| ----------- | ------------------- | --------- | --- |
| title | 列表元素的标题 | ReactNode | - |
| description | 列表元素的描述内容 | ReactNode | - |
| media | 列表元素的头像 / 图标 / 图片内容 | ReactNode | - |
| extra | 额外内容 | ReactNode | - |
| title | title | ReactNode | - |
| description | description | ReactNode | - |
| media | set avatar / image / icon | ReactNode | - |
| extra | extra content | ReactNode | - |
17 changes: 11 additions & 6 deletions docs/list/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@

### List

| 参数 | 说明 | 类型 | 默认值 |
| ------- | ----------------------------------------- | --------- | -------- |
| header | 列表头部 | ReactNode | - |
| size | 列表尺寸<br><br>**可选值**:<br>'medium', 'small' | Enum | 'medium' |
| footer | 列表尾部 | ReactNode | - |
| divider | 是否显示分割线 | Boolean | true |
| 参数 | 说明 | 类型 | 默认值 |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------------ |
| header | 列表头部 | ReactNode | - |
| size | 列表尺寸<br><br>**可选值**:<br>'medium', 'small' | Enum | 'medium' |
| footer | 列表尾部 | ReactNode | - |
| divider | 是否显示分割线 | Boolean | true |
| dataSource | 列表数据源 | Array | - |
| renderItem | 当使用 dataSource 时,可以用 renderItem 自定义渲染列表项<br><br>**签名**:<br>Function(current: Any, index: Number) => void<br>**参数**:<br>_current_: {Any} 当前遍历的项<br>_index_: {Number} 当前遍历的项的索引 | Function | item => item |
| loading | 是否在加载中 | Boolean | false |
| loadingComponent | 自定义 Loading 组件<br>请务必传递 props, 使用方式: loadingComponent={props => &lt;Loading {...props}/>}<br><br>**签名**:<br>Function() => void | Function | - |
| emptyContent | 设置数据为空的时候的表格内容展现 | ReactNode | - |

### List.Item

Expand Down
4 changes: 2 additions & 2 deletions scripts/server/tpls/demo.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
}
</script>
<script src="//shadow.elemecdn.com/npm/[email protected]/dist/polyfill.min.js"></script>
<script src="//shadow.elemecdn.com/npm/react@16.0.0/umd/react.development.js"></script>
<script src="//shadow.elemecdn.com/npm/react-dom@16.0.0/umd/react-dom.development.js"></script>
<script src="//shadow.elemecdn.com/npm/react@16.13.0/umd/react.development.js"></script>
<script src="//shadow.elemecdn.com/npm/react-dom@16.13.0/umd/react-dom.development.js"></script>
<script src="//shadow.elemecdn.com/npm/[email protected]/min/moment-with-locales.js"></script>
<script>
window.mountNode = document.getElementById('mount-node');
Expand Down
Loading

0 comments on commit 1fb62bf

Please sign in to comment.