UNPKG

3.98 kBJavaScriptView Raw
1import { createVNode as _createVNode, isVNode as _isVNode } from "vue";
2import { defineComponent, inject } from 'vue';
3import PropsTypes from '../_util/vue-types';
4import { getComponent, getSlot } from '../_util/props-util';
5import { defaultConfigProvider } from '../config-provider';
6import { withInstall } from '../_util/type';
7
8function _isSlot(s) {
9 return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !_isVNode(s);
10}
11
12export var CommentProps = {
13 actions: PropsTypes.array,
14
15 /** The element to display as the comment author. */
16 author: PropsTypes.VNodeChild,
17
18 /** The element to display as the comment avatar - generally an antd Avatar */
19 avatar: PropsTypes.VNodeChild,
20
21 /** The main content of the comment */
22 content: PropsTypes.VNodeChild,
23
24 /** Comment prefix defaults to '.ant-comment' */
25 prefixCls: PropsTypes.string,
26
27 /** A datetime element containing the time to be displayed */
28 datetime: PropsTypes.VNodeChild
29};
30var Comment = defineComponent({
31 name: 'AComment',
32 props: CommentProps,
33 setup: function setup() {
34 return {
35 configProvider: inject('configProvider', defaultConfigProvider)
36 };
37 },
38 methods: {
39 getAction: function getAction(actions) {
40 if (!actions || !actions.length) {
41 return null;
42 }
43
44 var actionList = actions.map(function (action, index) {
45 return _createVNode("li", {
46 "key": "action-".concat(index)
47 }, _isSlot(action) ? action : {
48 default: function _default() {
49 return [action];
50 }
51 });
52 });
53 return actionList;
54 },
55 renderNested: function renderNested(prefixCls, children) {
56 return _createVNode("div", {
57 "class": "".concat(prefixCls, "-nested")
58 }, _isSlot(children) ? children : {
59 default: function _default() {
60 return [children];
61 }
62 });
63 }
64 },
65 render: function render() {
66 var customizePrefixCls = this.$props.prefixCls;
67 var getPrefixCls = this.configProvider.getPrefixCls;
68 var prefixCls = getPrefixCls('comment', customizePrefixCls);
69 var actions = getComponent(this, 'actions');
70 var author = getComponent(this, 'author');
71 var avatar = getComponent(this, 'avatar');
72 var content = getComponent(this, 'content');
73 var datetime = getComponent(this, 'datetime');
74
75 var avatarDom = _createVNode("div", {
76 "class": "".concat(prefixCls, "-avatar")
77 }, [typeof avatar === 'string' ? _createVNode("img", {
78 "src": avatar,
79 "alt": "comment-avatar"
80 }, null) : avatar]);
81
82 var actionDom = actions ? _createVNode("ul", {
83 "class": "".concat(prefixCls, "-actions")
84 }, [this.getAction(Array.isArray(actions) ? actions : [actions])]) : null;
85
86 var authorContent = _createVNode("div", {
87 "class": "".concat(prefixCls, "-content-author")
88 }, [author && _createVNode("span", {
89 "class": "".concat(prefixCls, "-content-author-name")
90 }, _isSlot(author) ? author : {
91 default: function _default() {
92 return [author];
93 }
94 }), datetime && _createVNode("span", {
95 "class": "".concat(prefixCls, "-content-author-time")
96 }, _isSlot(datetime) ? datetime : {
97 default: function _default() {
98 return [datetime];
99 }
100 })]);
101
102 var contentDom = _createVNode("div", {
103 "class": "".concat(prefixCls, "-content")
104 }, [authorContent, _createVNode("div", {
105 "class": "".concat(prefixCls, "-content-detail")
106 }, _isSlot(content) ? content : {
107 default: function _default() {
108 return [content];
109 }
110 }), actionDom]);
111
112 var comment = _createVNode("div", {
113 "class": "".concat(prefixCls, "-inner")
114 }, [avatarDom, contentDom]);
115
116 var children = getSlot(this);
117 return _createVNode("div", {
118 "class": prefixCls
119 }, [comment, children && children.length ? this.renderNested(prefixCls, children) : null]);
120 }
121});
122export default withInstall(Comment);
\No newline at end of file