index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  2. import { createVNode as _createVNode } from "vue";
  3. import { defineComponent } from 'vue';
  4. import PropTypes from '../_util/vue-types';
  5. import { flattenChildren } from '../_util/props-util';
  6. import { withInstall } from '../_util/type';
  7. import useConfigInject from '../_util/hooks/useConfigInject';
  8. export var commentProps = function commentProps() {
  9. return {
  10. actions: Array,
  11. /** The element to display as the comment author. */
  12. author: PropTypes.any,
  13. /** The element to display as the comment avatar - generally an antd Avatar */
  14. avatar: PropTypes.any,
  15. /** The main content of the comment */
  16. content: PropTypes.any,
  17. /** Comment prefix defaults to '.ant-comment' */
  18. prefixCls: String,
  19. /** A datetime element containing the time to be displayed */
  20. datetime: PropTypes.any
  21. };
  22. };
  23. var Comment = defineComponent({
  24. compatConfig: {
  25. MODE: 3
  26. },
  27. name: 'AComment',
  28. props: commentProps(),
  29. slots: ['actions', 'author', 'avatar', 'content', 'datetime'],
  30. setup: function setup(props, _ref) {
  31. var slots = _ref.slots;
  32. var _useConfigInject = useConfigInject('comment', props),
  33. prefixCls = _useConfigInject.prefixCls,
  34. direction = _useConfigInject.direction;
  35. var renderNested = function renderNested(prefixCls, children) {
  36. return _createVNode("div", {
  37. "class": "".concat(prefixCls, "-nested")
  38. }, [children]);
  39. };
  40. var getAction = function getAction(actions) {
  41. if (!actions || !actions.length) {
  42. return null;
  43. }
  44. var actionList = actions.map(function (action, index) {
  45. return _createVNode("li", {
  46. "key": "action-".concat(index)
  47. }, [action]);
  48. });
  49. return actionList;
  50. };
  51. return function () {
  52. var _props$actions, _slots$actions, _props$author, _slots$author, _props$avatar, _slots$avatar, _props$content, _slots$content, _props$datetime, _slots$datetime, _slots$default;
  53. var pre = prefixCls.value;
  54. var actions = (_props$actions = props.actions) !== null && _props$actions !== void 0 ? _props$actions : (_slots$actions = slots.actions) === null || _slots$actions === void 0 ? void 0 : _slots$actions.call(slots);
  55. var author = (_props$author = props.author) !== null && _props$author !== void 0 ? _props$author : (_slots$author = slots.author) === null || _slots$author === void 0 ? void 0 : _slots$author.call(slots);
  56. var avatar = (_props$avatar = props.avatar) !== null && _props$avatar !== void 0 ? _props$avatar : (_slots$avatar = slots.avatar) === null || _slots$avatar === void 0 ? void 0 : _slots$avatar.call(slots);
  57. var content = (_props$content = props.content) !== null && _props$content !== void 0 ? _props$content : (_slots$content = slots.content) === null || _slots$content === void 0 ? void 0 : _slots$content.call(slots);
  58. var datetime = (_props$datetime = props.datetime) !== null && _props$datetime !== void 0 ? _props$datetime : (_slots$datetime = slots.datetime) === null || _slots$datetime === void 0 ? void 0 : _slots$datetime.call(slots);
  59. var avatarDom = _createVNode("div", {
  60. "class": "".concat(pre, "-avatar")
  61. }, [typeof avatar === 'string' ? _createVNode("img", {
  62. "src": avatar,
  63. "alt": "comment-avatar"
  64. }, null) : avatar]);
  65. var actionDom = actions ? _createVNode("ul", {
  66. "class": "".concat(pre, "-actions")
  67. }, [getAction(Array.isArray(actions) ? actions : [actions])]) : null;
  68. var authorContent = _createVNode("div", {
  69. "class": "".concat(pre, "-content-author")
  70. }, [author && _createVNode("span", {
  71. "class": "".concat(pre, "-content-author-name")
  72. }, [author]), datetime && _createVNode("span", {
  73. "class": "".concat(pre, "-content-author-time")
  74. }, [datetime])]);
  75. var contentDom = _createVNode("div", {
  76. "class": "".concat(pre, "-content")
  77. }, [authorContent, _createVNode("div", {
  78. "class": "".concat(pre, "-content-detail")
  79. }, [content]), actionDom]);
  80. var comment = _createVNode("div", {
  81. "class": "".concat(pre, "-inner")
  82. }, [avatarDom, contentDom]);
  83. var children = flattenChildren((_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots));
  84. return _createVNode("div", {
  85. "class": [pre, _defineProperty({}, "".concat(pre, "-rtl"), direction.value === 'rtl')]
  86. }, [comment, children && children.length ? renderNested(pre, children) : null]);
  87. };
  88. }
  89. });
  90. export default withInstall(Comment);