iconUtil.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { createVNode as _createVNode } from "vue";
  3. import LoadingOutlined from "@ant-design/icons-vue/es/icons/LoadingOutlined";
  4. import FileOutlined from "@ant-design/icons-vue/es/icons/FileOutlined";
  5. import MinusSquareOutlined from "@ant-design/icons-vue/es/icons/MinusSquareOutlined";
  6. import PlusSquareOutlined from "@ant-design/icons-vue/es/icons/PlusSquareOutlined";
  7. import CaretDownFilled from "@ant-design/icons-vue/es/icons/CaretDownFilled";
  8. import { isValidElement } from '../../_util/props-util';
  9. import { cloneVNode } from 'vue';
  10. export default function renderSwitcherIcon(prefixCls, switcherIcon, props, leafIcon, showLine) {
  11. const {
  12. isLeaf,
  13. expanded,
  14. loading
  15. } = props;
  16. let icon = switcherIcon;
  17. if (loading) {
  18. return _createVNode(LoadingOutlined, {
  19. "class": `${prefixCls}-switcher-loading-icon`
  20. }, null);
  21. }
  22. let showLeafIcon;
  23. if (showLine && typeof showLine === 'object') {
  24. showLeafIcon = showLine.showLeafIcon;
  25. }
  26. let defaultIcon = null;
  27. const switcherCls = `${prefixCls}-switcher-icon`;
  28. if (isLeaf) {
  29. if (!showLine) {
  30. return null;
  31. }
  32. if (showLeafIcon && leafIcon) {
  33. return leafIcon(props);
  34. }
  35. if (typeof showLine === 'object' && !showLeafIcon) {
  36. defaultIcon = _createVNode("span", {
  37. "class": `${prefixCls}-switcher-leaf-line`
  38. }, null);
  39. } else {
  40. defaultIcon = _createVNode(FileOutlined, {
  41. "class": `${prefixCls}-switcher-line-icon`
  42. }, null);
  43. }
  44. return defaultIcon;
  45. } else {
  46. defaultIcon = _createVNode(CaretDownFilled, {
  47. "class": switcherCls
  48. }, null);
  49. if (showLine) {
  50. defaultIcon = expanded ? _createVNode(MinusSquareOutlined, {
  51. "class": `${prefixCls}-switcher-line-icon`
  52. }, null) : _createVNode(PlusSquareOutlined, {
  53. "class": `${prefixCls}-switcher-line-icon`
  54. }, null);
  55. }
  56. }
  57. if (typeof switcherIcon === 'function') {
  58. icon = switcherIcon(_extends(_extends({}, props), {
  59. defaultIcon,
  60. switcherCls
  61. }));
  62. } else if (isValidElement(icon)) {
  63. icon = cloneVNode(icon, {
  64. class: switcherCls
  65. });
  66. }
  67. return icon || defaultIcon;
  68. }