index.js 4.4 KB

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