ant-design/components/comment/demo/list.md

67 lines
1.8 KiB
Markdown
Raw Normal View History

2018-10-22 21:20:28 +08:00
---
order: 1
title:
2018-11-02 23:38:52 +08:00
zh-CN: 配合 List 组件
en-US: Usage with list
2018-10-22 21:20:28 +08:00
---
## zh-CN
2018-11-02 23:38:52 +08:00
配合 List 组件展现评论列表。
2018-10-22 21:20:28 +08:00
## en-US
2018-11-02 23:38:52 +08:00
Displaying a series of comments using the `antd` List Component.
2018-10-22 21:20:28 +08:00
````jsx
2018-10-31 20:10:42 +08:00
import { Comment, Tooltip, List } from 'antd';
2018-10-22 21:20:28 +08:00
import moment from 'moment';
const data = [
{
actions: [<span>Reply to</span>],
2018-10-22 21:20:28 +08:00
author: 'Han Solo',
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
content: (
2018-10-30 19:25:54 +08:00
<p>We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.</p>
),
2018-10-30 00:17:26 +08:00
datetime: (
<Tooltip title={moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss')}>
<span>{moment().subtract(1, 'days').fromNow()}</span>
</Tooltip>
),
2018-10-22 21:20:28 +08:00
},
{
actions: [<span>Reply to</span>],
author: 'Han Solo',
2018-10-22 21:20:28 +08:00
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
content: (
2018-10-30 19:25:54 +08:00
<p>We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.</p>
),
2018-10-30 00:17:26 +08:00
datetime: (
<Tooltip title={moment().subtract(2, 'days').format('YYYY-MM-DD HH:mm:ss')}>
<span>{moment().subtract(2, 'days').fromNow()}</span>
</Tooltip>
),
2018-10-22 21:20:28 +08:00
},
];
ReactDOM.render(
<List
className="comment-list"
header={`${data.length} replies`}
itemLayout="horizontal"
dataSource={data}
renderItem={item => (
2018-10-24 21:17:37 +08:00
<Comment
actions={item.actions}
author={item.author}
avatar={item.avatar}
content={item.content}
2018-10-30 00:17:26 +08:00
datetime={item.datetime}
/>
2018-10-22 21:20:28 +08:00
)}
/>,
mountNode);
````