iconUtil.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use client";
  2. import * as React from 'react';
  3. import CaretDownFilled from "@ant-design/icons/es/icons/CaretDownFilled";
  4. import FileOutlined from "@ant-design/icons/es/icons/FileOutlined";
  5. import LoadingOutlined from "@ant-design/icons/es/icons/LoadingOutlined";
  6. import MinusSquareOutlined from "@ant-design/icons/es/icons/MinusSquareOutlined";
  7. import PlusSquareOutlined from "@ant-design/icons/es/icons/PlusSquareOutlined";
  8. import classNames from 'classnames';
  9. import { cloneElement } from '../../_util/reactNode';
  10. const SwitcherIconCom = props => {
  11. var _a, _b;
  12. const {
  13. prefixCls,
  14. switcherIcon,
  15. treeNodeProps,
  16. showLine,
  17. switcherLoadingIcon
  18. } = props;
  19. const {
  20. isLeaf,
  21. expanded,
  22. loading
  23. } = treeNodeProps;
  24. if (loading) {
  25. if (/*#__PURE__*/React.isValidElement(switcherLoadingIcon)) {
  26. return switcherLoadingIcon;
  27. }
  28. return /*#__PURE__*/React.createElement(LoadingOutlined, {
  29. className: `${prefixCls}-switcher-loading-icon`
  30. });
  31. }
  32. let showLeafIcon;
  33. if (showLine && typeof showLine === 'object') {
  34. showLeafIcon = showLine.showLeafIcon;
  35. }
  36. if (isLeaf) {
  37. if (!showLine) {
  38. return null;
  39. }
  40. if (typeof showLeafIcon !== 'boolean' && !!showLeafIcon) {
  41. const leafIcon = typeof showLeafIcon === 'function' ? showLeafIcon(treeNodeProps) : showLeafIcon;
  42. const leafCls = `${prefixCls}-switcher-line-custom-icon`;
  43. if (/*#__PURE__*/React.isValidElement(leafIcon)) {
  44. return cloneElement(leafIcon, {
  45. className: classNames((_a = leafIcon.props) === null || _a === void 0 ? void 0 : _a.className, leafCls)
  46. });
  47. }
  48. return leafIcon;
  49. }
  50. return showLeafIcon ? (/*#__PURE__*/React.createElement(FileOutlined, {
  51. className: `${prefixCls}-switcher-line-icon`
  52. })) : (/*#__PURE__*/React.createElement("span", {
  53. className: `${prefixCls}-switcher-leaf-line`
  54. }));
  55. }
  56. const switcherCls = `${prefixCls}-switcher-icon`;
  57. const switcher = typeof switcherIcon === 'function' ? switcherIcon(treeNodeProps) : switcherIcon;
  58. if (/*#__PURE__*/React.isValidElement(switcher)) {
  59. return cloneElement(switcher, {
  60. className: classNames((_b = switcher.props) === null || _b === void 0 ? void 0 : _b.className, switcherCls)
  61. });
  62. }
  63. if (switcher !== undefined) {
  64. return switcher;
  65. }
  66. if (showLine) {
  67. return expanded ? (/*#__PURE__*/React.createElement(MinusSquareOutlined, {
  68. className: `${prefixCls}-switcher-line-icon`
  69. })) : (/*#__PURE__*/React.createElement(PlusSquareOutlined, {
  70. className: `${prefixCls}-switcher-line-icon`
  71. }));
  72. }
  73. return /*#__PURE__*/React.createElement(CaretDownFilled, {
  74. className: switcherCls
  75. });
  76. };
  77. export default SwitcherIconCom;