index.js 5.0 KB

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