import * as React from 'react'; import classNames from 'classnames'; export interface CommentProps { /** List of action items rendered below the comment content */ actions?: Array; /** The element to display as the comment author. */ author?: string; /** The element to display as the comment avatar - generally an antd Avatar */ 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?: any; /** Optional ID for the comment */ id?: string; /** Comment prefix defaults to '.ant-comment' */ prefixCls?: string; /** Additional style for the comment */ style?: React.CSSProperties; /** A datetime element containing the time to be displayed */ datetime?: React.ReactNode; /** Direction of the comment left or right */ direction?: 'left' | 'right'; } export default class Comment extends React.Component { getAction(actions: React.ReactNode[]) { if (!actions || !actions.length) { return null; } const actionList = actions.map((action, index) => (
  • {action}
  • ), ); return actionList; } renderNested = (child: any) => { const { prefixCls = 'ant-comment' } = this.props; const classString = classNames(`${prefixCls}-nested`); return (
    {child}
    ) } render() { const { actions, author, avatar, children, className, content, direction = 'left', prefixCls = 'ant-comment', style = {}, datetime, ...otherProps } = this.props; const classString = classNames(prefixCls, className, { [`${prefixCls}-rtl`]: direction === 'left', [`${prefixCls}-ltr`]: direction === 'right', }); const authorElements = []; if (author) { authorElements.push( {author} , ); } if (datetime) { authorElements.push( {datetime}, ); } const avatarDom = (
    {typeof avatar === 'string' ? : avatar}
    ); const actionDom = actions && actions.length ? : null; const authorContent = (
    {direction === 'left' ? authorElements : authorElements.reverse()}
    ); const contentDom = (
    {authorContent}
    {content}
    {actionDom}
    ); const comment = (
    {direction === 'left' ? [avatarDom, contentDom] : [contentDom, avatarDom] }
    ) const nestedComments = React.Children .toArray(children) .map((child: React.ReactElement) => this.renderNested(child)) return (
    {comment} {nestedComments}
    ); } }