index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.CommentProps = undefined;
  6. var _babelHelperVueJsxMergeProps = require('babel-helper-vue-jsx-merge-props');
  7. var _babelHelperVueJsxMergeProps2 = _interopRequireDefault(_babelHelperVueJsxMergeProps);
  8. var _vueTypes = require('../_util/vue-types');
  9. var _vueTypes2 = _interopRequireDefault(_vueTypes);
  10. var _propsUtil = require('../_util/props-util');
  11. var _configConsumerProps = require('../config-provider/configConsumerProps');
  12. var _base = require('../base');
  13. var _base2 = _interopRequireDefault(_base);
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15. var CommentProps = exports.CommentProps = {
  16. actions: _vueTypes2['default'].array,
  17. /** The element to display as the comment author. */
  18. author: _vueTypes2['default'].any,
  19. /** The element to display as the comment avatar - generally an antd Avatar */
  20. avatar: _vueTypes2['default'].any,
  21. /** The main content of the comment */
  22. content: _vueTypes2['default'].any,
  23. /** Comment prefix defaults to '.ant-comment' */
  24. prefixCls: _vueTypes2['default'].string,
  25. /** A datetime element containing the time to be displayed */
  26. datetime: _vueTypes2['default'].any
  27. };
  28. var Comment = {
  29. name: 'AComment',
  30. props: CommentProps,
  31. inject: {
  32. configProvider: { 'default': function _default() {
  33. return _configConsumerProps.ConfigConsumerProps;
  34. } }
  35. },
  36. methods: {
  37. getAction: function getAction(actions) {
  38. var h = this.$createElement;
  39. if (!actions || !actions.length) {
  40. return null;
  41. }
  42. var actionList = actions.map(function (action, index) {
  43. return h(
  44. 'li',
  45. { key: 'action-' + index },
  46. [action]
  47. );
  48. });
  49. return actionList;
  50. },
  51. renderNested: function renderNested(prefixCls, children) {
  52. var h = this.$createElement;
  53. return h(
  54. 'div',
  55. { 'class': prefixCls + '-nested' },
  56. [children]
  57. );
  58. }
  59. },
  60. render: function render() {
  61. var h = arguments[0];
  62. var customizePrefixCls = this.$props.prefixCls;
  63. var getPrefixCls = this.configProvider.getPrefixCls;
  64. var prefixCls = getPrefixCls('comment', customizePrefixCls);
  65. var actions = (0, _propsUtil.getComponentFromProp)(this, 'actions');
  66. var author = (0, _propsUtil.getComponentFromProp)(this, 'author');
  67. var avatar = (0, _propsUtil.getComponentFromProp)(this, 'avatar');
  68. var content = (0, _propsUtil.getComponentFromProp)(this, 'content');
  69. var datetime = (0, _propsUtil.getComponentFromProp)(this, 'datetime');
  70. var avatarDom = h(
  71. 'div',
  72. { 'class': prefixCls + '-avatar' },
  73. [typeof avatar === 'string' ? h('img', {
  74. attrs: { src: avatar, alt: 'comment-avatar' }
  75. }) : avatar]
  76. );
  77. var actionDom = actions && actions.length ? h(
  78. 'ul',
  79. { 'class': prefixCls + '-actions' },
  80. [this.getAction(actions)]
  81. ) : null;
  82. var authorContent = h(
  83. 'div',
  84. { 'class': prefixCls + '-content-author' },
  85. [author && h(
  86. 'span',
  87. { 'class': prefixCls + '-content-author-name' },
  88. [author]
  89. ), datetime && h(
  90. 'span',
  91. { 'class': prefixCls + '-content-author-time' },
  92. [datetime]
  93. )]
  94. );
  95. var contentDom = h(
  96. 'div',
  97. { 'class': prefixCls + '-content' },
  98. [authorContent, h(
  99. 'div',
  100. { 'class': prefixCls + '-content-detail' },
  101. [content]
  102. ), actionDom]
  103. );
  104. var comment = h(
  105. 'div',
  106. { 'class': prefixCls + '-inner' },
  107. [avatarDom, contentDom]
  108. );
  109. var children = this.$slots['default'];
  110. return h(
  111. 'div',
  112. (0, _babelHelperVueJsxMergeProps2['default'])([{ 'class': prefixCls }, { on: (0, _propsUtil.getListeners)(this) }]),
  113. [comment, children ? this.renderNested(prefixCls, children) : null]
  114. );
  115. }
  116. };
  117. /* istanbul ignore next */
  118. Comment.install = function (Vue) {
  119. Vue.use(_base2['default']);
  120. Vue.component(Comment.name, Comment);
  121. };
  122. exports['default'] = Comment;