diff --git a/components/tree/Tree.tsx b/components/tree/Tree.tsx index fb6071f754..af3b4b31d4 100644 --- a/components/tree/Tree.tsx +++ b/components/tree/Tree.tsx @@ -9,6 +9,8 @@ import collapseMotion from '../_util/motion'; import renderSwitcherIcon from './utils/iconUtil'; import dropIndicatorRender from './utils/dropIndicator'; +export type SwitcherIcon = React.ReactNode | ((props: { expanded: boolean }) => React.ReactNode); + export interface AntdTreeNodeAttribute { eventKey: string; prefixCls: string; diff --git a/components/tree/utils/iconUtil.tsx b/components/tree/utils/iconUtil.tsx index 40731af2f2..eb456733a3 100644 --- a/components/tree/utils/iconUtil.tsx +++ b/components/tree/utils/iconUtil.tsx @@ -5,12 +5,12 @@ 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 { AntTreeNodeProps } from '../Tree'; +import type { AntTreeNodeProps, SwitcherIcon } from '../Tree'; import { isValidElement, cloneElement } from '../../_util/reactNode'; export default function renderSwitcherIcon( prefixCls: string, - switcherIcon: React.ReactNode | ((props: any) => React.ReactNode), + switcherIcon: SwitcherIcon, showLine: boolean | { showLeafIcon: boolean } | undefined, treeNodeProps: AntTreeNodeProps, ): React.ReactNode { @@ -35,7 +35,8 @@ export default function renderSwitcherIcon( const switcherCls = `${prefixCls}-switcher-icon`; - const switcher = typeof switcherIcon === 'function' ? switcherIcon({ expanded }) : switcherIcon; + const switcher = + typeof switcherIcon === 'function' ? switcherIcon({ expanded: !!expanded }) : switcherIcon; if (isValidElement(switcher)) { return cloneElement(switcher, {