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

99 lines
2.2 KiB
Markdown
Raw Normal View History

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
import { Comment, Icon, Tooltip, Avatar } from 'antd';
2018-10-22 21:20:28 +08:00
import moment from 'moment';
class App extends React.Component {
state = {
likes: 0,
dislikes: 0,
action: null,
2019-05-07 14:57:32 +08:00
};
2018-10-22 21:20:28 +08:00
like = () => {
this.setState({
likes: 1,
dislikes: 0,
action: 'liked',
});
2019-05-07 14:57:32 +08:00
};
2018-10-22 21:20:28 +08:00
dislike = () => {
this.setState({
likes: 0,
dislikes: 1,
action: 'disliked',
2018-10-31 20:10:42 +08:00
});
2019-05-07 14:57:32 +08:00
};
2018-10-22 21:20:28 +08:00
render() {
const { likes, dislikes, action } = this.state;
const actions = [
2019-08-02 18:19:06 +08:00
<span key="comment-basic-like">
2018-10-22 21:20:28 +08:00
<Tooltip title="Like">
<Icon
type="like"
theme={action === 'liked' ? 'filled' : 'outlined'}
2018-10-22 21:20:28 +08:00
onClick={this.like}
/>
</Tooltip>
2019-05-07 14:57:32 +08:00
<span style={{ paddingLeft: 8, cursor: 'auto' }}>{likes}</span>
2018-10-22 21:20:28 +08:00
</span>,
2019-08-02 18:19:06 +08:00
<span key=' key="comment-basic-dislike"'>
2018-10-22 21:20:28 +08:00
<Tooltip title="Dislike">
<Icon
type="dislike"
theme={action === 'disliked' ? 'filled' : 'outlined'}
2018-10-22 21:20:28 +08:00
onClick={this.dislike}
/>
</Tooltip>
2019-05-07 14:57:32 +08:00
<span style={{ paddingLeft: 8, cursor: 'auto' }}>{dislikes}</span>
2018-10-22 21:20:28 +08:00
</span>,
2019-08-02 18:19:06 +08:00
<span key="comment-basic-reply-to">Reply to</span>,
2018-10-22 21:20:28 +08:00
];
return (
<Comment
actions={actions}
2018-10-22 21:20:28 +08:00
author={<a>Han Solo</a>}
2019-05-07 14:57:32 +08:00
avatar={
2018-10-22 21:20:28 +08:00
<Avatar
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
alt="Han Solo"
/>
2019-05-07 14:57:32 +08:00
}
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>
</Tooltip>
2019-05-07 14:57:32 +08:00
}
/>
2018-10-22 21:20:28 +08:00
);
}
}
ReactDOM.render(<App />, mountNode);
2019-05-07 14:57:32 +08:00
```