2018-10-22 21:20:28 +08:00
|
|
|
---
|
|
|
|
order: 0
|
|
|
|
title:
|
|
|
|
zh-CN: 基本评论
|
|
|
|
en-US: Basic comment
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2018-10-28 22:09:38 +08:00
|
|
|
一个基本的评论组件,带有作者、头像、时间和操作。
|
2018-10-22 21:20:28 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
A basic comment with author, avatar, time and actions.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2020-03-23 11:14:29 +08:00
|
|
|
import React, { createElement, useState } from 'react';
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Comment, Tooltip, Avatar } from 'antd';
|
2018-10-22 21:20:28 +08:00
|
|
|
import moment from 'moment';
|
2019-11-28 12:34:33 +08:00
|
|
|
import { DislikeOutlined, LikeOutlined, DislikeFilled, LikeFilled } from '@ant-design/icons';
|
2018-10-22 21:20:28 +08:00
|
|
|
|
2020-03-23 11:14:29 +08:00
|
|
|
const Demo = () => {
|
|
|
|
const [likes, setLikes] = useState(0);
|
|
|
|
const [dislikes, setDislikes] = useState(0);
|
|
|
|
const [action, setAction] = useState(null);
|
2018-10-22 21:20:28 +08:00
|
|
|
|
2020-03-23 11:14:29 +08:00
|
|
|
const like = () => {
|
|
|
|
setLikes(1);
|
|
|
|
setDislikes(0);
|
|
|
|
setAction('liked');
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-10-22 21:20:28 +08:00
|
|
|
|
2020-03-23 11:14:29 +08:00
|
|
|
const dislike = () => {
|
|
|
|
setLikes(0);
|
|
|
|
setDislikes(1);
|
|
|
|
setAction('disliked');
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-10-22 21:20:28 +08:00
|
|
|
|
2020-03-23 11:14:29 +08:00
|
|
|
const actions = [
|
2020-07-06 16:03:12 +08:00
|
|
|
<Tooltip key="comment-basic-like" title="Like">
|
|
|
|
<span onClick={like}>
|
|
|
|
{createElement(action === 'liked' ? LikeFilled : LikeOutlined)}
|
|
|
|
<span className="comment-action">{likes}</span>
|
|
|
|
</span>
|
|
|
|
</Tooltip>,
|
|
|
|
<Tooltip key="comment-basic-dislike" title="Dislike">
|
|
|
|
<span onClick={dislike}>
|
|
|
|
{React.createElement(action === 'disliked' ? DislikeFilled : DislikeOutlined)}
|
|
|
|
<span className="comment-action">{dislikes}</span>
|
|
|
|
</span>
|
|
|
|
</Tooltip>,
|
2020-03-23 11:14:29 +08:00
|
|
|
<span key="comment-basic-reply-to">Reply to</span>,
|
|
|
|
];
|
2018-10-22 21:20:28 +08:00
|
|
|
|
2020-03-23 11:14:29 +08:00
|
|
|
return (
|
|
|
|
<Comment
|
|
|
|
actions={actions}
|
|
|
|
author={<a>Han Solo</a>}
|
|
|
|
avatar={
|
|
|
|
<Avatar
|
|
|
|
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
|
|
|
|
alt="Han Solo"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
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={moment().format('YYYY-MM-DD HH:mm:ss')}>
|
|
|
|
<span>{moment().fromNow()}</span>
|
2018-10-22 21:20:28 +08:00
|
|
|
</Tooltip>
|
2020-03-23 11:14:29 +08:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2020-05-25 16:27:02 +08:00
|
|
|
};
|
2018-10-22 21:20:28 +08:00
|
|
|
|
2020-03-23 11:14:29 +08:00
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2020-01-02 19:10:16 +08:00
|
|
|
|
|
|
|
```css
|
|
|
|
/* tile uploaded pictures */
|
|
|
|
.comment-action {
|
|
|
|
padding-left: 8px;
|
|
|
|
cursor: 'auto';
|
|
|
|
}
|
|
|
|
|
|
|
|
[class*='-col-rtl'] .comment-action {
|
|
|
|
padding-right: 8px;
|
|
|
|
padding-left: 0;
|
|
|
|
}
|
|
|
|
```
|