iconUtil.js 3.2 KB

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