2020-04-22 09:37:46 +08:00
|
|
|
import * as React from 'react';
|
2019-09-28 11:31:28 +08:00
|
|
|
import classNames from 'classnames';
|
2020-03-02 12:09:38 +08:00
|
|
|
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';
|
2019-09-28 11:31:28 +08:00
|
|
|
import { AntTreeNodeProps } from '../Tree';
|
2020-05-14 20:54:49 +08:00
|
|
|
import { isValidElement, cloneElement } from '../../_util/reactNode';
|
2019-09-28 11:31:28 +08:00
|
|
|
|
|
|
|
export default function renderSwitcherIcon(
|
|
|
|
prefixCls: string,
|
|
|
|
switcherIcon: React.ReactNode | null | undefined,
|
2020-06-24 00:19:43 +08:00
|
|
|
showLine: boolean | { showLeafIcon: boolean } | undefined,
|
2019-09-28 11:31:28 +08:00
|
|
|
{ isLeaf, expanded, loading }: AntTreeNodeProps,
|
|
|
|
) {
|
|
|
|
if (loading) {
|
2019-11-28 12:34:33 +08:00
|
|
|
return <LoadingOutlined className={`${prefixCls}-switcher-loading-icon`} />;
|
2019-09-28 11:31:28 +08:00
|
|
|
}
|
2020-06-24 00:19:43 +08:00
|
|
|
let showLeafIcon;
|
|
|
|
if (showLine && typeof showLine === 'object') {
|
|
|
|
showLeafIcon = showLine.showLeafIcon;
|
|
|
|
}
|
2019-09-28 11:31:28 +08:00
|
|
|
if (isLeaf) {
|
2020-06-24 00:19:43 +08:00
|
|
|
if (showLine) {
|
|
|
|
if (typeof showLine === 'object' && !showLeafIcon) {
|
|
|
|
return <span className={`${prefixCls}-switcher-leaf-line`} />;
|
|
|
|
}
|
|
|
|
return <FileOutlined className={`${prefixCls}-switcher-line-icon`} />;
|
|
|
|
}
|
|
|
|
return null;
|
2019-09-28 11:31:28 +08:00
|
|
|
}
|
|
|
|
const switcherCls = `${prefixCls}-switcher-icon`;
|
2020-05-14 20:54:49 +08:00
|
|
|
if (isValidElement(switcherIcon)) {
|
|
|
|
return cloneElement(switcherIcon, {
|
2020-01-08 14:09:06 +08:00
|
|
|
className: classNames(switcherIcon.props.className || '', switcherCls),
|
2019-09-28 11:31:28 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switcherIcon) {
|
|
|
|
return switcherIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showLine) {
|
|
|
|
return expanded ? (
|
2019-11-28 12:34:33 +08:00
|
|
|
<MinusSquareOutlined className={`${prefixCls}-switcher-line-icon`} />
|
2019-09-28 11:31:28 +08:00
|
|
|
) : (
|
2019-11-28 12:34:33 +08:00
|
|
|
<PlusSquareOutlined className={`${prefixCls}-switcher-line-icon`} />
|
2019-09-28 11:31:28 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return <CaretDownFilled className={switcherCls} />;
|
|
|
|
}
|