import type { ExtractPropTypes } from 'vue'; import { defineComponent } from 'vue'; import PropTypes from '../_util/vue-types'; import { flattenChildren } from '../_util/props-util'; import type { CustomSlotsType, VueNode } from '../_util/type'; import { withInstall } from '../_util/type'; import useConfigInject from '../_util/hooks/useConfigInject'; export const commentProps = () => ({ actions: Array, /** The element to display as the comment author. */ author: PropTypes.any, /** The element to display as the comment avatar - generally an antd Avatar */ avatar: PropTypes.any, /** The main content of the comment */ content: PropTypes.any, /** Comment prefix defaults to '.ant-comment' */ prefixCls: String, /** A datetime element containing the time to be displayed */ datetime: PropTypes.any, }); export type CommentProps = Partial>>; const Comment = defineComponent({ compatConfig: { MODE: 3 }, name: 'AComment', props: commentProps(), slots: Object as CustomSlotsType<{ actions: any; author: any; avatar: any; content: any; datetime: any; default: any; }>, setup(props, { slots }) { const { prefixCls, direction } = useConfigInject('comment', props); const renderNested = (prefixCls: string, children: VueNode) => { return
{children}
; }; const getAction = (actions: VueNode[]) => { if (!actions || !actions.length) { return null; } const actionList = actions.map((action, index) =>
  • {action}
  • ); return actionList; }; return () => { const pre = prefixCls.value; const actions: any[] = props.actions ?? slots.actions?.(); const author = props.author ?? slots.author?.(); const avatar = props.avatar ?? slots.avatar?.(); const content = props.content ?? slots.content?.(); const datetime = props.datetime ?? slots.datetime?.(); const avatarDom = (
    {typeof avatar === 'string' ? comment-avatar : avatar}
    ); const actionDom = actions ? ( ) : null; const authorContent = (
    {author && } {datetime && }
    ); const contentDom = (
    {authorContent}
    {content}
    {actionDom}
    ); const comment = (
    {avatarDom} {contentDom}
    ); const children = flattenChildren(slots.default?.()); return (
    {comment} {children && children.length ? renderNested(pre, children) : null}
    ); }; }, }); export default withInstall(Comment);