import { inject } from 'vue';
import PropsTypes from '../_util/vue-types';
import { getComponent, getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export const CommentProps = {
actions: PropsTypes.array,
/** The element to display as the comment author. */
author: PropsTypes.any,
/** The element to display as the comment avatar - generally an antd Avatar */
avatar: PropsTypes.any,
/** The main content of the comment */
content: PropsTypes.any,
/** Comment prefix defaults to '.ant-comment' */
prefixCls: PropsTypes.string,
/** A datetime element containing the time to be displayed */
datetime: PropsTypes.any,
};
const Comment = {
name: 'AComment',
props: CommentProps,
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
methods: {
getAction(actions) {
if (!actions || !actions.length) {
return null;
}
const actionList = actions.map((action, index) =>
{action});
return actionList;
},
renderNested(prefixCls, children) {
return {children}
;
},
},
render() {
const { prefixCls: customizePrefixCls } = this.$props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('comment', customizePrefixCls);
const actions = getComponent(this, 'actions');
const author = getComponent(this, 'author');
const avatar = getComponent(this, 'avatar');
const content = getComponent(this, 'content');
const datetime = getComponent(this, 'datetime');
const avatarDom = (
{typeof avatar === 'string' ?
: avatar}
);
const actionDom = actions ? (
{this.getAction(Array.isArray(actions) ? actions : [actions])}
) : null;
const authorContent = (
{author && {author}}
{datetime && {datetime}}
);
const contentDom = (
{authorContent}
{content}
{actionDom}
);
const comment = (
{avatarDom}
{contentDom}
);
const children = getSlot(this);
return (
{comment}
{children && children.length ? this.renderNested(prefixCls, children) : null}
);
},
};
/* istanbul ignore next */
Comment.install = function(app) {
app.component(Comment.name, Comment);
};
export default Comment;