List 列表
通用列表。
何时使用
最基础的列表展示,可承载文字、列表、图片、段落,常用于后台数据展示页面。
代码演示
import { List } from 'choerodon-ui';
const data = [
'Racing car sprays burning fuel into crowd.',
'Japanese princess to wed commoner.',
'Australian walks 100km after outback crash.',
'Man charged over missing wedding girl.',
'Los Angeles battles huge wildfires.',
];
ReactDOM.render(
<div>
<h3 style={{ marginBottom: 16 }}>Default Size</h3>
<List
header={<div>Header</div>}
footer={<div>Footer</div>}
bordered
dataSource={data}
renderItem={item => (<List.Item>{item}</List.Item>)}
/>
<h3 style={{ margin: '16px 0' }}>Small Size</h3>
<List
size="small"
header={<div>Header</div>}
footer={<div>Footer</div>}
bordered
dataSource={data}
renderItem={item => (<List.Item>{item}</List.Item>)}
/>
<h3 style={{ margin: '16px 0' }}>Large Size</h3>
<List
size="large"
header={<div>Header</div>}
footer={<div>Footer</div>}
bordered
dataSource={data}
renderItem={item => (<List.Item>{item}</List.Item>)}
/>
</div>,
mountNode);
import { List, Avatar } from 'choerodon-ui';
const data = [
{
title: 'Title 1',
},
{
title: 'Title 2',
},
{
title: 'Title 3',
},
{
title: 'Title 4',
},
];
ReactDOM.render(
<List
itemLayout="horizontal"
dataSource={data}
renderItem={item => (
<List.Item>
<List.Item.Meta
avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
title={<a href="https://github.com/choerodon">{item.title}</a>}
description="Choerodon猪齿鱼是开源多云技术平台,是基于Kubernetes的容器编排和管理能力,整合DevOps工具链、微服务和移动应用框架,来帮助企业实现敏捷化的应用交付和自动化的运营管理,并提供IoT、支付、数据、智能洞察、企业应用市场等业务组件,来帮助企业聚焦于业务,加速数字化转型。"
/>
</List.Item>
)}
/>,
mountNode);
import { List, Avatar, Button, Spin } from 'choerodon-ui';
import reqwest from 'reqwest';
const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo';
class LoadMoreList extends React.Component {
state = {
loading: true,
loadingMore: false,
showLoadingMore: true,
data: [],
}
componentDidMount() {
this.getData((res) => {
this.setState({
loading: false,
data: res.results,
});
});
}
getData = (callback) => {
reqwest({
url: fakeDataUrl,
type: 'json',
method: 'get',
contentType: 'application/json',
success: (res) => {
callback(res);
},
});
}
onLoadMore = () => {
this.setState({
loadingMore: true,
});
this.getData((res) => {
const data = this.state.data.concat(res.results);
this.setState({
data,
loadingMore: false,
}, () => {
window.dispatchEvent(new Event('resize'));
});
});
}
render() {
const { loading, loadingMore, showLoadingMore, data } = this.state;
const loadMore = showLoadingMore ? (
<div style={{ textAlign: 'center', marginTop: 12, height: 32, lineHeight: '32px' }}>
{loadingMore && <Spin />}
{!loadingMore && <Button onClick={this.onLoadMore}>loading more</Button>}
</div>
) : null;
return (
<List
className="demo-loadmore-list"
loading={loading}
itemLayout="horizontal"
loadMore={loadMore}
dataSource={data}
renderItem={item => (
<List.Item actions={[<a>edit</a>, <a>more</a>]}>
<List.Item.Meta
avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
title={<a href="https://github.com/choerodon">{item.name.last}</a>}
description="Choerodon猪齿鱼是开源多云技术平台,是基于Kubernetes的容器编排和管理能力,整合DevOps工具链、微服务和移动应用框架,来帮助企业实现敏捷化的应用交付和自动化的运营管理,并提供IoT、支付、数据、智能洞察、企业应用市场等业务组件,来帮助企业聚焦于业务,加速数字化转型。"
/>
<div>content</div>
</List.Item>
)}
/>
);
}
}
ReactDOM.render(<LoadMoreList />, mountNode);
import { List, Avatar, Icon } from 'choerodon-ui';
const listData = [];
for (let i = 0; i < 5; i++) {
listData.push({
href: 'https://github.com/choerodon',
title: `Choerodon part ${i}`,
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
description: 'Choerodon猪齿鱼是开源多云技术平台,是基于Kubernetes的容器编排和管理能力,整合DevOps工具链、微服务和移动应用框架,来帮助企业实现敏捷化的应用交付和自动化的运营管理,并提供IoT、支付、数据、智能洞察、企业应用市场等业务组件,来帮助企业聚焦于业务,加速数字化转型。',
});
}
const pagination = {
pageSize: 10,
current: 1,
total: listData.length,
onChange: (() => {}),
};
const IconText = ({ type, text }) => (
<span>
<Icon type={type} style={{ marginRight: 8 }} />
{text}
</span>
);
ReactDOM.render(
<List
itemLayout="vertical"
size="large"
pagination={pagination}
dataSource={listData}
renderItem={item => (
<List.Item
key={item.title}
actions={[<IconText type="star-o" text="156" />, <IconText type="like-o" text="156" />, <IconText type="message" text="2" />]}
extra={<img width={272} alt="logo" src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png" />}
>
<List.Item.Meta
avatar={<Avatar src={item.avatar} />}
title={<a href={item.href}>{item.title}</a>}
description={item.description}
/>
{item.content}
</List.Item>
)}
/>,
mountNode);
import { List, Card } from 'choerodon-ui';
const data = [
{
title: 'Title 1',
},
{
title: 'Title 2',
},
{
title: 'Title 3',
},
{
title: 'Title 4',
},
];
ReactDOM.render(
<List
grid={{ gutter: 16, column: 4 }}
dataSource={data}
renderItem={item => (
<List.Item>
<Card title={item.title}>Card content</Card>
</List.Item>
)}
/>,
mountNode);
import { List, Card } from 'choerodon-ui';
const data = [
{
title: 'Title 1',
},
{
title: 'Title 2',
},
{
title: 'Title 3',
},
{
title: 'Title 4',
},
{
title: 'Title 5',
},
{
title: 'Title 6',
},
];
ReactDOM.render(
<List
grid={{ gutter: 16, xs: 1, sm: 2, md: 4, lg: 4, xl: 6, xxl: 3 }}
dataSource={data}
renderItem={item => (
<List.Item>
<Card title={item.title}>Card content</Card>
</List.Item>
)}
/>,
mountNode);
import { List, message, Avatar, Spin } from 'choerodon-ui';
import reqwest from 'reqwest';
import InfiniteScroll from 'react-infinite-scroller';
const fakeDataUrl = 'https://randomuser.me/api/?results=5&inc=name,gender,email,nat&noinfo';
class InfiniteListExample extends React.Component {
state = {
data: [],
loading: false,
hasMore: true,
}
getData = (callback) => {
reqwest({
url: fakeDataUrl,
type: 'json',
method: 'get',
contentType: 'application/json',
success: (res) => {
callback(res);
},
});
}
componentWillMount() {
this.getData((res) => {
this.setState({
data: res.results,
});
});
}
handleInfiniteOnLoad = () => {
let data = this.state.data;
this.setState({
loading: true,
});
if (data.length > 14) {
message.warning('Infinite List loaded all');
this.setState({
hasMore: false,
loading: false,
});
return;
}
this.getData((res) => {
data = data.concat(res.results);
this.setState({
data,
loading: false,
});
});
}
render() {
return (
<div className="demo-infinite-container">
<InfiniteScroll
initialLoad={false}
pageStart={0}
loadMore={this.handleInfiniteOnLoad}
hasMore={!this.state.loading && this.state.hasMore}
useWindow={false}
>
<List
dataSource={this.state.data}
renderItem={item => (
<List.Item key={item.id}>
<List.Item.Meta
avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
title={<a href="https://github.com/choerodon">{item.name.last}</a>}
description={item.email}
/>
<div>Content</div>
</List.Item>
)}
>
{this.state.loading && this.state.hasMore && <Spin className="demo-loading" />}
</List>
</InfiniteScroll>
</div>
);
}
}
ReactDOM.render(<InfiniteListExample />, mountNode);
API
List
参数 |
说明 |
类型 |
默认值 |
bordered |
是否展示边框 |
boolean |
false |
footer |
列表底部 |
string|ReactNode |
- |
grid |
列表栅格配置 |
object |
- |
header |
列表头部 |
string|ReactNode |
- |
itemLayout |
设置 List.Item 布局, 设置成 vertical 则竖直样式显示, 默认横排 |
string |
- |
loading |
当卡片内容还在加载中时,可以用 loading 展示一个占位 |
boolean|object (更多) |
false |
loadMore |
加载更多 |
string|ReactNode |
- |
pagination |
对应的 pagination 配置, 设置 false 不显示 |
boolean|object |
false |
size |
list 的尺寸 |
default | middle | small |
default |
split |
是否展示分割线 |
boolean |
true |
List grid props
参数 |
说明 |
类型 |
默认值 |
column |
列数 |
number |
- |
gutter |
栅格间隔 |
number |
0 |
xs |
<576px 展示的列数 |
number |
- |
sm |
≥576px 展示的列数 |
number |
- |
md |
≥768px 展示的列数 |
number |
- |
lg |
≥992px 展示的列数 |
number |
- |
xl |
≥1200px 展示的列数 |
number |
- |
xxl |
≥1600px 展示的列数 |
number |
- |
List.Item
参数 |
说明 |
类型 |
默认值 |
actions |
列表操作组,根据 itemLayout 的不同, 位置在卡片底部或者最右侧 |
Array<ReactNode> |
- |
extra |
额外内容, 通常用在 itemLayout 为 vertical 的情况下, 展示右侧内容; horizontal 展示在列表元素最右侧 |
string|ReactNode |
- |
参数 |
说明 |
类型 |
默认值 |
avatar |
列表元素的图标 |
ReactNode |
- |
description |
列表元素的描述内容 |
string|ReactNode |
- |
title |
列表元素的标题 |
string|ReactNode |
- |