import * as React from 'react'; import classNames from 'classnames'; import LoadingOutlined from '@ant-design/icons/LoadingOutlined'; import FileOutlined from '@ant-design/icons/FileOutlined'; import MinusSquareOutlined from '@ant-design/icons/MinusSquareOutlined'; import PlusSquareOutlined from '@ant-design/icons/PlusSquareOutlined'; import CaretDownFilled from '@ant-design/icons/CaretDownFilled'; import type { AntTreeNodeProps, SwitcherIcon } from '../Tree'; import { isValidElement, cloneElement } from '../../_util/reactNode'; export default function renderSwitcherIcon( prefixCls: string, switcherIcon: SwitcherIcon, showLine: boolean | { showLeafIcon: boolean } | undefined, treeNodeProps: AntTreeNodeProps, ): React.ReactNode { const { isLeaf, expanded, loading } = treeNodeProps; if (loading) { return ; } let showLeafIcon; if (showLine && typeof showLine === 'object') { showLeafIcon = showLine.showLeafIcon; } if (isLeaf) { if (showLine) { if (typeof showLine === 'object' && !showLeafIcon) { return ; } return ; } return null; } const switcherCls = `${prefixCls}-switcher-icon`; const switcher = typeof switcherIcon === 'function' ? switcherIcon({ expanded: !!expanded }) : switcherIcon; if (isValidElement(switcher)) { return cloneElement(switcher, { className: classNames(switcher.props.className || '', switcherCls), }); } if (switcher) { return switcher; } if (showLine) { return expanded ? ( ) : ( ); } return ; }