import { inject, VNodeTypes, CSSProperties, App, SetupContext } from 'vue'; import classNames from '../_util/classNames'; import { defaultConfigProvider } from '../config-provider'; export interface CommentProps { /** List of action items rendered below the comment content */ actions?: Array; /** The element to display as the comment author. */ author?: VNodeTypes; /** The element to display as the comment avatar - generally an antd Avatar */ avatar?: VNodeTypes; /** The main content of the comment */ content: VNodeTypes; /** Comment prefix defaults to '.ant-comment' */ prefixCls?: string; /** Additional style for the comment */ style?: CSSProperties; /** A datetime element containing the time to be displayed */ datetime?: VNodeTypes; } const Comment = ( { actions, author, avatar, content, prefixCls: customizePrefixCls, datetime, ...otherProps }: CommentProps, { slots }: SetupContext, ) => { const { getPrefixCls } = inject('configProvider', defaultConfigProvider); const renderNested = (prefixCls: string, nestedChildren: any) => { return
{nestedChildren}
; }; const prefixCls = getPrefixCls('comment', customizePrefixCls); const avatarDom = avatar ? (
{typeof avatar === 'string' ? comment-avatar : avatar}
) : null; const actionDom = actions && actions.length ? ( ) : null; const authorContent = (author || datetime) && (
{author && } {datetime && }
); const contentDom = (
{authorContent}
{content}
{actionDom}
); const cls = classNames(prefixCls); const children = slots.default?.(); return (
{avatarDom} {contentDom}
{children ? renderNested(prefixCls, children) : null}
); }; Comment.displayName = 'AComment'; /* istanbul ignore next */ Comment.install = function(app: App) { app.component(Comment.name, Comment); }; export default Comment;