index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props';
  2. import _typeof from 'babel-runtime/helpers/typeof';
  3. import _defineProperty from 'babel-runtime/helpers/defineProperty';
  4. import _extends from 'babel-runtime/helpers/extends';
  5. import PropTypes from '../_util/vue-types';
  6. import { ConfigConsumerProps } from '../config-provider/configConsumerProps';
  7. import { getComponentFromProp, getListeners } from '../_util/props-util';
  8. import LocaleReceiver from '../locale-provider/LocaleReceiver';
  9. import DefaultEmptyImg from './empty';
  10. import SimpleEmptyImg from './simple';
  11. import Base from '../base';
  12. export var TransferLocale = function TransferLocale() {
  13. return {
  14. description: PropTypes.string
  15. };
  16. };
  17. export var EmptyProps = function EmptyProps() {
  18. return {
  19. prefixCls: PropTypes.string,
  20. image: PropTypes.any,
  21. description: PropTypes.any,
  22. imageStyle: PropTypes.object
  23. };
  24. };
  25. var Empty = {
  26. name: 'AEmpty',
  27. props: _extends({}, EmptyProps()),
  28. inject: {
  29. configProvider: { 'default': function _default() {
  30. return ConfigConsumerProps;
  31. } }
  32. },
  33. methods: {
  34. renderEmpty: function renderEmpty(contentLocale) {
  35. var h = this.$createElement;
  36. var _$props = this.$props,
  37. customizePrefixCls = _$props.prefixCls,
  38. imageStyle = _$props.imageStyle;
  39. var getPrefixCls = this.configProvider.getPrefixCls;
  40. var prefixCls = getPrefixCls('empty', customizePrefixCls);
  41. var image = getComponentFromProp(this, 'image') || h(DefaultEmptyImg);
  42. var description = getComponentFromProp(this, 'description');
  43. var des = typeof description !== 'undefined' ? description : contentLocale.description;
  44. var alt = typeof des === 'string' ? des : 'empty';
  45. var cls = _defineProperty({}, prefixCls, true);
  46. var imageNode = null;
  47. if (typeof image === 'string') {
  48. imageNode = h('img', {
  49. attrs: { alt: alt, src: image }
  50. });
  51. } else if ((typeof image === 'undefined' ? 'undefined' : _typeof(image)) === 'object' && image.PRESENTED_IMAGE_SIMPLE) {
  52. var Image = image;
  53. imageNode = h(Image);
  54. cls[prefixCls + '-normal'] = true;
  55. } else {
  56. imageNode = image;
  57. }
  58. return h(
  59. 'div',
  60. _mergeJSXProps([{ 'class': cls }, { on: getListeners(this) }]),
  61. [h(
  62. 'div',
  63. { 'class': prefixCls + '-image', style: imageStyle },
  64. [imageNode]
  65. ), des && h(
  66. 'p',
  67. { 'class': prefixCls + '-description' },
  68. [des]
  69. ), this.$slots['default'] && h(
  70. 'div',
  71. { 'class': prefixCls + '-footer' },
  72. [this.$slots['default']]
  73. )]
  74. );
  75. }
  76. },
  77. render: function render() {
  78. var h = arguments[0];
  79. return h(LocaleReceiver, {
  80. attrs: { componentName: 'Empty' },
  81. scopedSlots: { 'default': this.renderEmpty } });
  82. }
  83. };
  84. Empty.PRESENTED_IMAGE_DEFAULT = DefaultEmptyImg;
  85. Empty.PRESENTED_IMAGE_SIMPLE = SimpleEmptyImg;
  86. /* istanbul ignore next */
  87. Empty.install = function (Vue) {
  88. Vue.use(Base);
  89. Vue.component(Empty.name, Empty);
  90. };
  91. export default Empty;