import PropsTypes from '../_util/vue-types';
import { initDefaultProps, getComponentFromProp } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import Base from '../base';
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,
inject: {
configProvider: { default: () => ({}) },
},
methods: {
getAction(actions) {
if (!actions || !actions.length) {
return null;
}
const actionList = actions.map((action, index) =>
{action});
return actionList;
},
renderNested(children) {
const { prefixCls } = this.$props;
return {children}
;
},
},
render() {
const { prefixCls: customizePrefixCls } = this.$props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('comment', customizePrefixCls);
const actions = getComponentFromProp(this, 'actions');
const author = getComponentFromProp(this, 'author');
const avatar = getComponentFromProp(this, 'avatar');
const content = getComponentFromProp(this, 'content');
const datetime = getComponentFromProp(this, 'datetime');
const avatarDom = (
{typeof avatar === 'string' ?
: avatar}
);
const actionDom =
actions && actions.length ? (
{this.getAction(actions)}
) : null;
const authorContent = (
{author && {author}}
{datetime && {datetime}}
);
const contentDom = (
{authorContent}
{content}
{actionDom}
);
const comment = (
{avatarDom}
{contentDom}
);
const children = this.$slots.default;
return (
{comment}
{children ? this.renderNested(children) : null}
);
},
};
/* istanbul ignore next */
Comment.install = function(Vue) {
Vue.use(Base);
Vue.component(Comment.name, Comment);
};
export default Comment;