mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 21:18:01 +08:00
4907996b97
* use new rc-tree-select * support not found * add switch icon support * support function * support selection motion * show search icon if open * clean up * fix lint * fix lint
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import classNames from 'classnames';
|
|
import { Loading, File, MinusSquare, PlusSquare, CaretDownFilled } from '@ant-design/icons';
|
|
import { AntTreeNodeProps } from '../Tree';
|
|
|
|
export default function renderSwitcherIcon(
|
|
prefixCls: string,
|
|
switcherIcon: React.ReactNode | null | undefined,
|
|
showLine: boolean | undefined,
|
|
{ isLeaf, expanded, loading }: AntTreeNodeProps,
|
|
) {
|
|
if (loading) {
|
|
return <Loading className={`${prefixCls}-switcher-loading-icon`} />;
|
|
}
|
|
if (isLeaf) {
|
|
if (showLine) {
|
|
return <File className={`${prefixCls}-switcher-line-icon`} />;
|
|
}
|
|
return null;
|
|
}
|
|
const switcherCls = `${prefixCls}-switcher-icon`;
|
|
if (React.isValidElement(switcherIcon)) {
|
|
const switcherOriginCls = switcherIcon.props.className || '';
|
|
return React.cloneElement(switcherIcon, {
|
|
className: classNames(switcherOriginCls, switcherCls),
|
|
});
|
|
}
|
|
|
|
if (switcherIcon) {
|
|
return switcherIcon;
|
|
}
|
|
|
|
if (showLine) {
|
|
return expanded ? (
|
|
<MinusSquare className={`${prefixCls}-switcher-line-icon`} />
|
|
) : (
|
|
<PlusSquare className={`${prefixCls}-switcher-line-icon`} />
|
|
);
|
|
}
|
|
return <CaretDownFilled className={switcherCls} />;
|
|
}
|