LoadingIcon.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { createVNode as _createVNode } from "vue";
  2. import { defineComponent, nextTick } from 'vue';
  3. import LoadingOutlined from "@ant-design/icons-vue/es/icons/LoadingOutlined";
  4. import Transition from '../_util/transition';
  5. var getCollapsedWidth = function getCollapsedWidth(node) {
  6. if (node) {
  7. node.style.width = '0px';
  8. node.style.opacity = '0';
  9. node.style.transform = 'scale(0)';
  10. }
  11. };
  12. var getRealWidth = function getRealWidth(node) {
  13. nextTick(function () {
  14. if (node) {
  15. node.style.width = "".concat(node.scrollWidth, "px");
  16. node.style.opacity = '1';
  17. node.style.transform = 'scale(1)';
  18. }
  19. });
  20. };
  21. var resetStyle = function resetStyle(node) {
  22. if (node && node.style) {
  23. node.style.width = null;
  24. node.style.opacity = null;
  25. node.style.transform = null;
  26. }
  27. };
  28. export default defineComponent({
  29. compatConfig: {
  30. MODE: 3
  31. },
  32. name: 'LoadingIcon',
  33. props: {
  34. prefixCls: String,
  35. loading: [Boolean, Object],
  36. existIcon: Boolean
  37. },
  38. setup: function setup(props) {
  39. return function () {
  40. var existIcon = props.existIcon,
  41. prefixCls = props.prefixCls,
  42. loading = props.loading;
  43. if (existIcon) {
  44. return _createVNode("span", {
  45. "class": "".concat(prefixCls, "-loading-icon")
  46. }, [_createVNode(LoadingOutlined, null, null)]);
  47. }
  48. var visible = !!loading;
  49. return _createVNode(Transition, {
  50. "name": "".concat(prefixCls, "-loading-icon-motion"),
  51. "onBeforeEnter": getCollapsedWidth,
  52. "onEnter": getRealWidth,
  53. "onAfterEnter": resetStyle,
  54. "onBeforeLeave": getRealWidth,
  55. "onLeave": function onLeave(node) {
  56. setTimeout(function () {
  57. getCollapsedWidth(node);
  58. });
  59. },
  60. "onAfterLeave": resetStyle
  61. }, {
  62. default: function _default() {
  63. return [visible ? _createVNode("span", {
  64. "class": "".concat(prefixCls, "-loading-icon")
  65. }, [_createVNode(LoadingOutlined, null, null)]) : null];
  66. }
  67. });
  68. };
  69. }
  70. });