mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 09:21:22 +08:00
82 lines
2.0 KiB
Markdown
82 lines
2.0 KiB
Markdown
---
|
|
order: 1
|
|
title:
|
|
zh-CN: 配合 List 组件
|
|
en-US: Usage with list
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
配合 List 组件展现评论列表。
|
|
|
|
## en-US
|
|
|
|
Displaying a series of comments using the `antd` List Component.
|
|
|
|
```tsx
|
|
import { Comment, List, Tooltip } from 'antd';
|
|
import dayjs from 'dayjs';
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
import React from 'react';
|
|
|
|
dayjs.extend(relativeTime);
|
|
const data = [
|
|
{
|
|
actions: [<span key="comment-list-reply-to-0">Reply to</span>],
|
|
author: 'Han Solo',
|
|
avatar: 'https://joeschmoe.io/api/v1/random',
|
|
content: (
|
|
<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>
|
|
),
|
|
datetime: (
|
|
<Tooltip title={dayjs().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss')}>
|
|
<span>{dayjs().subtract(1, 'days').fromNow()}</span>
|
|
</Tooltip>
|
|
),
|
|
},
|
|
{
|
|
actions: [<span key="comment-list-reply-to-0">Reply to</span>],
|
|
author: 'Han Solo',
|
|
avatar: 'https://joeschmoe.io/api/v1/random',
|
|
content: (
|
|
<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>
|
|
),
|
|
datetime: (
|
|
<Tooltip title={dayjs().subtract(2, 'days').format('YYYY-MM-DD HH:mm:ss')}>
|
|
<span>{dayjs().subtract(2, 'days').fromNow()}</span>
|
|
</Tooltip>
|
|
),
|
|
},
|
|
];
|
|
|
|
const App: React.FC = () => (
|
|
<List
|
|
className="comment-list"
|
|
header={`${data.length} replies`}
|
|
itemLayout="horizontal"
|
|
dataSource={data}
|
|
renderItem={item => (
|
|
<li>
|
|
<Comment
|
|
actions={item.actions}
|
|
author={item.author}
|
|
avatar={item.avatar}
|
|
content={item.content}
|
|
datetime={item.datetime}
|
|
/>
|
|
</li>
|
|
)}
|
|
/>
|
|
);
|
|
|
|
export default App;
|
|
```
|