index.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _extends from "@babel/runtime/helpers/esm/extends";
  3. import { createVNode as _createVNode } from "vue";
  4. var __rest = this && this.__rest || function (s, e) {
  5. var t = {};
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  7. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { defineComponent } from 'vue';
  13. import classNames from '../_util/classNames';
  14. import LocaleReceiver from '../locale-provider/LocaleReceiver';
  15. import DefaultEmptyImg from './empty';
  16. import SimpleEmptyImg from './simple';
  17. import { filterEmpty } from '../_util/props-util';
  18. import { anyType, objectType, withInstall } from '../_util/type';
  19. import useConfigInject from '../config-provider/hooks/useConfigInject';
  20. import useStyle from './style';
  21. const defaultEmptyImg = _createVNode(DefaultEmptyImg, null, null);
  22. const simpleEmptyImg = _createVNode(SimpleEmptyImg, null, null);
  23. export const emptyProps = () => ({
  24. prefixCls: String,
  25. imageStyle: objectType(),
  26. image: anyType(),
  27. description: anyType()
  28. });
  29. const Empty = defineComponent({
  30. name: 'AEmpty',
  31. compatConfig: {
  32. MODE: 3
  33. },
  34. inheritAttrs: false,
  35. props: emptyProps(),
  36. setup(props, _ref) {
  37. let {
  38. slots = {},
  39. attrs
  40. } = _ref;
  41. const {
  42. direction,
  43. prefixCls: prefixClsRef
  44. } = useConfigInject('empty', props);
  45. const [wrapSSR, hashId] = useStyle(prefixClsRef);
  46. return () => {
  47. var _a, _b;
  48. const prefixCls = prefixClsRef.value;
  49. const _c = _extends(_extends({}, props), attrs),
  50. {
  51. image = ((_a = slots.image) === null || _a === void 0 ? void 0 : _a.call(slots)) || defaultEmptyImg,
  52. description = ((_b = slots.description) === null || _b === void 0 ? void 0 : _b.call(slots)) || undefined,
  53. imageStyle,
  54. class: className = ''
  55. } = _c,
  56. restProps = __rest(_c, ["image", "description", "imageStyle", "class"]);
  57. return wrapSSR(_createVNode(LocaleReceiver, {
  58. "componentName": "Empty",
  59. "children": locale => {
  60. const des = typeof description !== 'undefined' ? description : locale.description;
  61. const alt = typeof des === 'string' ? des : 'empty';
  62. let imageNode = null;
  63. if (typeof image === 'string') {
  64. imageNode = _createVNode("img", {
  65. "alt": alt,
  66. "src": image
  67. }, null);
  68. } else {
  69. imageNode = image;
  70. }
  71. return _createVNode("div", _objectSpread({
  72. "class": classNames(prefixCls, className, hashId.value, {
  73. [`${prefixCls}-normal`]: image === simpleEmptyImg,
  74. [`${prefixCls}-rtl`]: direction.value === 'rtl'
  75. })
  76. }, restProps), [_createVNode("div", {
  77. "class": `${prefixCls}-image`,
  78. "style": imageStyle
  79. }, [imageNode]), des && _createVNode("p", {
  80. "class": `${prefixCls}-description`
  81. }, [des]), slots.default && _createVNode("div", {
  82. "class": `${prefixCls}-footer`
  83. }, [filterEmpty(slots.default())])]);
  84. }
  85. }, null));
  86. };
  87. }
  88. });
  89. Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
  90. Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
  91. export default withInstall(Empty);