2020-04-22 09:37:46 +08:00
|
|
|
import * as React from 'react';
|
2020-03-02 12:09:38 +08:00
|
|
|
import DownOutlined from '@ant-design/icons/DownOutlined';
|
|
|
|
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
|
|
|
|
import CheckOutlined from '@ant-design/icons/CheckOutlined';
|
|
|
|
import CloseOutlined from '@ant-design/icons/CloseOutlined';
|
|
|
|
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
|
|
|
import SearchOutlined from '@ant-design/icons/SearchOutlined';
|
2019-09-28 11:31:28 +08:00
|
|
|
|
|
|
|
export default function getIcons({
|
|
|
|
suffixIcon,
|
|
|
|
clearIcon,
|
|
|
|
menuItemSelectedIcon,
|
|
|
|
removeIcon,
|
|
|
|
loading,
|
|
|
|
multiple,
|
|
|
|
}: {
|
|
|
|
suffixIcon?: React.ReactNode;
|
|
|
|
clearIcon?: React.ReactNode;
|
|
|
|
menuItemSelectedIcon?: React.ReactNode;
|
|
|
|
removeIcon?: React.ReactNode;
|
|
|
|
loading?: boolean;
|
|
|
|
multiple?: boolean;
|
|
|
|
}) {
|
|
|
|
// Clear Icon
|
|
|
|
let mergedClearIcon = clearIcon;
|
|
|
|
if (!clearIcon) {
|
|
|
|
mergedClearIcon = <CloseCircleFilled />;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrow item icon
|
|
|
|
let mergedSuffixIcon = null;
|
|
|
|
if (suffixIcon !== undefined) {
|
|
|
|
mergedSuffixIcon = suffixIcon;
|
|
|
|
} else if (loading) {
|
2019-11-28 12:34:33 +08:00
|
|
|
mergedSuffixIcon = <LoadingOutlined spin />;
|
2019-09-28 11:31:28 +08:00
|
|
|
} else {
|
|
|
|
mergedSuffixIcon = ({ open, showSearch }: { open: boolean; showSearch: boolean }) => {
|
|
|
|
if (open && showSearch) {
|
2019-11-28 12:34:33 +08:00
|
|
|
return <SearchOutlined />;
|
2019-09-28 11:31:28 +08:00
|
|
|
}
|
2019-11-28 12:34:33 +08:00
|
|
|
return <DownOutlined />;
|
2019-09-28 11:31:28 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checked item icon
|
|
|
|
let mergedItemIcon = null;
|
|
|
|
if (menuItemSelectedIcon !== undefined) {
|
|
|
|
mergedItemIcon = menuItemSelectedIcon;
|
|
|
|
} else if (multiple) {
|
2019-11-28 12:34:33 +08:00
|
|
|
mergedItemIcon = <CheckOutlined />;
|
2019-09-28 11:31:28 +08:00
|
|
|
} else {
|
|
|
|
mergedItemIcon = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mergedRemoveIcon = null;
|
|
|
|
if (removeIcon !== undefined) {
|
|
|
|
mergedRemoveIcon = removeIcon;
|
|
|
|
} else {
|
2019-11-28 12:34:33 +08:00
|
|
|
mergedRemoveIcon = <CloseOutlined />;
|
2019-09-28 11:31:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
clearIcon: mergedClearIcon,
|
|
|
|
suffixIcon: mergedSuffixIcon,
|
|
|
|
itemIcon: mergedItemIcon,
|
|
|
|
removeIcon: mergedRemoveIcon,
|
|
|
|
};
|
|
|
|
}
|