import * as React from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider';
function getAction(actions: React.ReactNode[]) {
if (!actions || !actions.length) {
return null;
}
// eslint-disable-next-line react/no-array-index-key
const actionList = actions.map((action, index) =>
{action});
return actionList;
}
export interface CommentProps {
/** List of action items rendered below the comment content */
actions?: Array;
/** The element to display as the comment author. */
author?: React.ReactNode;
/** 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?: React.ReactNode;
/** 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;
}
const Comment: React.FC = ({
actions,
author,
avatar,
children,
className,
content,
prefixCls: customizePrefixCls,
style,
datetime,
...otherProps
}) => {
const { getPrefixCls, direction } = React.useContext(ConfigContext);
const renderNested = (prefixCls: string, nestedChildren: any) => {
return {nestedChildren}
;
};
const prefixCls = getPrefixCls('comment', customizePrefixCls);
const avatarDom = (
{typeof avatar === 'string' ?
: avatar}
);
const actionDom =
actions && actions.length ? (
) : null;
const authorContent = (
{author && {author}}
{datetime && {datetime}}
);
const contentDom = (
{authorContent}
{content}
{actionDom}
);
const comment = (
{avatarDom}
{contentDom}
);
const cls = classNames(prefixCls, className, {
[`${prefixCls}-rtl`]: direction === 'rtl',
});
return (
{comment}
{children ? renderNested(prefixCls, children) : null}
);
};
export default Comment;