Browse Source

updating comment api, docs and demos

pull/13084/head
ilanus 6 years ago
committed by 偏右
parent
commit
11e6fec65a
  1. 57
      components/comment/Editor.tsx
  2. 11
      components/comment/demo/basic.md
  3. 51
      components/comment/demo/direction.md
  4. 19
      components/comment/demo/editor.md
  5. 19
      components/comment/demo/list.md
  6. 33
      components/comment/demo/nested.md
  7. 18
      components/comment/index.en-US.md
  8. 94
      components/comment/index.tsx
  9. 18
      components/comment/index.zh-CN.md
  10. 73
      components/comment/style/index.less
  11. 2
      components/style/themes/default.less

57
components/comment/Editor.tsx

@ -1,57 +0,0 @@
import * as React from 'react';
import classNames from 'classnames';
export interface CommentEditorProps {
avatar: React.ReactNode;
className?: string;
editorStyle?: React.CSSProperties;
headStyle?: React.CSSProperties;
innerStyle?: React.CSSProperties;
prefixCls?: string;
style?: React.CSSProperties;
content: React.ReactNode;
}
export default (props: CommentEditorProps) => {
const {
avatar,
className,
content,
editorStyle,
headStyle,
innerStyle,
prefixCls = 'ant-comment',
style,
...others
} = props;
const classString = classNames(`${prefixCls}-editor`, className);
const avatarDom = typeof avatar === 'string'
? <img src={avatar} />
: avatar;
const headDom = (
<div className={`${prefixCls}-header`} style={headStyle}>
<span className={`${prefixCls}-header-avatar`}>
{avatarDom}
</span>
</div>
);
const contentDom = (
<div className={`${prefixCls}-content`} style={editorStyle}>
<div className={`${prefixCls}-content-wrapper`}>
{content}
</div>
</div>
);
return (
<div {...others} className={classString} style={style}>
<div className={`${prefixCls}-inner`} style={innerStyle}>
{headDom}
{contentDom}
</div>
</div>
);
}

11
components/comment/demo/basic.md

@ -48,7 +48,7 @@ class App extends React.Component {
<Tooltip title="Like">
<Icon
type="like"
theme={action === 'liked' ? 'twoTone' : 'filled'}
theme={action === 'liked' ? 'filled' : 'outlined'}
onClick={this.like}
/>
</Tooltip>
@ -60,7 +60,7 @@ class App extends React.Component {
<Tooltip title="Dislike">
<Icon
type="dislike"
theme={action === 'disliked' ? 'twoTone' : 'filled'}
theme={action === 'disliked' ? 'filled' : 'outlined'}
onClick={this.dislike}
/>
</Tooltip>
@ -84,8 +84,11 @@ class App extends React.Component {
content={
<p>Sagittis id consectetur purus ut faucibus pulvinar elementum integer enim. Pellentesque massa placerat duis ultricies lacus sed turpis. Tempus urna et pharetra pharetra massa massa.</p>
}
time={moment().fromNow()}
tooltipTime={moment().format('YYYY-MM-DD HH:mm:ss')}
time={
<Tooltip title={moment().format('YYYY-MM-DD HH:mm:ss')}>
<span>{moment().fromNow()}</span>
</Tooltip>
}
/>
);
}

51
components/comment/demo/direction.md

@ -0,0 +1,51 @@
---
order: 4
title:
zh-CN: 基本评论
en-US: Custom direction comment
---
## zh-CN
一个基本的评论组件,带有作者、头像、时间和操作。
## en-US
A basic comment with author, avatar, time and actions.
````jsx
import { Comment, Icon, Tooltip, Avatar } from 'antd';
import moment from 'moment';
function ExampleComment({ direction = 'left' }) {
return (
<Comment
direction={direction}
avatar={
<Tooltip title="Han Solo">
<Avatar
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
alt="Han Solo"
/>
</Tooltip>
}
content={
<p>Sagittis id consectetur purus ut faucibus pulvinar elementum integer enim. Pellentesque massa placerat duis ultricies lacus sed turpis. Tempus urna et pharetra pharetra massa massa.</p>
}
/>
)
}
class App extends React.Component {
render() {
return (
<React.Fragment>
<ExampleComment />
<ExampleComment direction="right" />
</React.Fragment>
);
}
}
ReactDOM.render(<App />, mountNode);
````

19
components/comment/demo/editor.md

@ -14,10 +14,9 @@ title:
Comment can be used as editor, user can customize the editor component.
````jsx
import { Comment, Icon, Tooltip, Avatar, Form, Button, List, Input } from 'antd';
import { Comment, Icon, Tooltip, Avatar, Form, Button, List, Input, Radio } from 'antd';
import moment from 'moment';
const CommentEditor = Comment.Editor;
const FormItem = Form.Item;
const TextArea = Input.TextArea;
@ -82,6 +81,7 @@ class App extends React.Component {
state = {
comments: [],
submitting: false,
direction: 'left',
}
handleSubmit = (values, cb) => {
@ -106,6 +106,10 @@ class App extends React.Component {
}, 1000);
}
handleChange = (e) => {
this.setState({ direction: e.target.value });
}
render() {
return (
<React.Fragment>
@ -114,7 +118,16 @@ class App extends React.Component {
comments={this.state.comments}
/>
)}
<CommentEditor
<Form layout="inline">
<FormItem label="Editor direction">
<Radio.Group size="default" value={this.state.direction} onChange={this.handleChange}>
<Radio.Button value="left">Left</Radio.Button>
<Radio.Button value="right">Right</Radio.Button>
</Radio.Group>
</FormItem>
</Form>
<Comment
direction={this.state.direction}
avatar={
<Avatar
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"

19
components/comment/demo/list.md

@ -2,7 +2,7 @@
order: 1
title:
zh-CN: 用法用名单
en-US: Usage With List
en-US: Usage with list
---
## zh-CN
@ -25,18 +25,24 @@ const data = [
content: (
<p>Nisl nisi scelerisque eu ultrices vitae auctor eu augue. Nulla at volutpat diam ut venenatis tellus in metus vulputate.</p>
),
time: moment().subtract(1, 'days').fromNow(),
tooltipTime: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
time: (
<Tooltip title={moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss')}>
<span>{moment().subtract(1, 'days').fromNow()}</span>
</Tooltip>
),
},
{
actions: [<span>Reply to</span>],
author: 'Stormtrooper',
author: 'Han Solo',
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
content: (
<p>Sed turpis tincidunt id aliquet risus feugiat in ante metus. Faucibus nisl tincidunt eget nullam non.</p>
),
time: moment().subtract(2, 'days').fromNow(),
tooltipTime: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'),
time: (
<Tooltip title={moment().subtract(2, 'days').format('YYYY-MM-DD HH:mm:ss')}>
<span>{moment().subtract(2, 'days').fromNow()}</span>
</Tooltip>
),
},
];
@ -53,7 +59,6 @@ ReactDOM.render(
avatar={item.avatar}
content={item.content}
time={item.time}
tooltipTime={item.tooltipTime}
/>
)}
/>,

33
components/comment/demo/nested.md

@ -17,22 +17,23 @@ Comment can be nested
import { Comment, Icon, Tooltip, Avatar } from 'antd';
import moment from 'moment';
const ExampleComment = ({ children }) => (
<Comment
actions={[<span>Reply to</span>]}
author={<a>Han Solo</a>}
avatar={
<Avatar
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
alt="Han Solo"
/>
}
content={<p>Sagittis id consectetur purus ut faucibus pulvinar elementum integer enim.</p>}
time={moment().fromNow()}
>
{children}
</Comment>
);
function ExampleComment({ children }) {
return (
<Comment
actions={[<span>Reply to</span>]}
author={<a>Han Solo</a>}
avatar={
<Avatar
src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
alt="Han Solo"
/>
}
content={<p>Sagittis id consectetur purus ut faucibus pulvinar elementum integer enim.</p>}
>
{children}
</Comment>
);
}
ReactDOM.render(
<ExampleComment>

18
components/comment/index.en-US.md

@ -19,26 +19,12 @@ Comments can be used to enable discussions on an entity for example page, blog p
| author | The element to display as the comment author | ReactNode | - |
| avatar | The element to display as the comment avatar - generally an antd `Avatar` | ReactNode | - |
| children | Nested comments should be provided as children of the Comment | ReactNode | - |
| className | className of comment | string | - |
| className | Addtional className for comment | string | - |
| content | The main content of the comment | ReactNode | - |
| contentStyle | Inline style to apply to the comment content | object | - |
| headStyle | Inline style to apply to the comment head | object | - |
| avatarStyle | Inline style to apply to the comment avatar | object | - |
| id | Optional ID for the comment | string | - |
| innerStyle | Additional style for the inner content | object | - |
| prefixCls | Comment prefix className defaults to `.ant-comment` | string | .ant-comment |
| style | Additional style for the comment | object | - |
| time | A time element containing the time to be displayed | ReactNode | - |
| tooltipTime | A time element to be displayed as the time tooltip | ReactNode | - |
# Comment.Editor
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| avatar | The element to display as the comment avatar - generally an antd `Avatar` | ReactNode | - |
| className | className of editor | string | - |
| content | The element to display as the editor | ReactNode | - |
| editorStyle | Inline style to apply to the comment editor | object | - |
| headStyle | Inline style to apply to the comment head | object | - |
| innerStyle | Inline style to apply to the comment inner comment editor | object | - |
| prefixCls | prefix className defaults to `.ant-comment` | string | .ant-comment |
| style | Additional style for the editor | object | - |

94
components/comment/index.tsx

@ -1,27 +1,23 @@
import * as React from 'react';
import classNames from 'classnames';
import Tooltip from '../tooltip';
import Editor from './Editor';
export { CommentEditorProps } from './Editor';
export interface CommentProps {
/** List of action items rendered below the comment content */
actions?: Array<React.ReactNode>;
/** The element to display as the comment author. */
author: string;
author?: string;
/** The element to display as the comment avatar - generally an antd Avatar */
avatar: React.ReactNode;
avatar?: React.ReactNode;
/** className of comment */
className?: string;
/** The main content of the comment */
content: React.ReactNode;
/** Nested comments should be provided as children of the Comment */
children?: React.ReactNode;
children?: any;
/** Additional style for the comment content */
contentStyle?: React.CSSProperties;
/** Additional style for the comment head */
headStyle?: React.CSSProperties;
/** Additional style for the comment avatar */
avatarStyle?: React.CSSProperties;
/** Optional ID for the comment */
id?: string;
/** Additional style for the comment inner wrapper */
@ -32,13 +28,11 @@ export interface CommentProps {
style?: React.CSSProperties;
/** A time element containing the time to be displayed */
time?: React.ReactNode;
/** A time element to be displayed as the time tooltip */
tooltipTime?: React.ReactNode;
/** Direction of the comment left or right */
direction?: 'left' | 'right';
}
export default class Comment extends React.Component<CommentProps, {}> {
static Editor: typeof Editor = Editor;
getAction(actions: React.ReactNode[]) {
if (!actions || !actions.length)