Files
ant-design/components/select/useIcons.tsx
二货爱吃白萝卜 4d25be58f0 refactor: Select like component support semantic structure (#55430)
* chore: basic style

* chore: style of select variant

* chore: multiple

* chore: demo update

* chore: sizing

* chore: sizing

* chore: styles

* chore: clean up

* test: fix test case

* chore: adjust demo

* chore: adjust demo opacity

* chore: clean up

* chore: fix lint

* chore: bump ver

* chore: cascader props

* chore: bump ver

* test: update snapshot

* docs: update demo

* test: fix test case

* test: auto complete test

* test: fix semantic test

* test: fix semantic test

* chore: update test

* docs: update semantic demo

* test: simplify

* chore: clean up

* chore: fix style

* chore: fix style

* chore: fix style

* chore: fix missing

* chore: fix style

* test: update snapshot

* test: update snapshot

* chore: fix compcat style

* chore: bump version

* chore: fix style

* chore: clean up

* test: update snapshot

---------

Co-authored-by: thinkasany <480968828@qq.com>
Co-authored-by: 遇见同学 <1875694521@qq.com>
Co-authored-by: lijianan <574980606@qq.com>
2025-10-27 14:02:27 +08:00

102 lines
2.7 KiB
TypeScript

import type { ReactNode } from 'react';
import * as React from 'react';
import CheckOutlined from '@ant-design/icons/CheckOutlined';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import DownOutlined from '@ant-design/icons/DownOutlined';
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import SearchOutlined from '@ant-design/icons/SearchOutlined';
import { devUseWarning } from '../_util/warning';
type RenderNode = React.ReactNode | ((props: any) => React.ReactNode);
export default function useIcons({
suffixIcon,
clearIcon,
menuItemSelectedIcon,
removeIcon,
loading,
multiple,
hasFeedback,
showSuffixIcon,
feedbackIcon,
showArrow,
componentName,
}: {
suffixIcon?: React.ReactNode;
clearIcon?: RenderNode;
menuItemSelectedIcon?: RenderNode;
removeIcon?: RenderNode;
loading?: boolean;
multiple?: boolean;
hasFeedback?: boolean;
feedbackIcon?: ReactNode;
prefixCls: string;
showSuffixIcon?: boolean;
showArrow?: boolean;
componentName: string;
}) {
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning(componentName);
warning.deprecated(!clearIcon, 'clearIcon', 'allowClear={{ clearIcon: React.ReactNode }}');
}
// Clear Icon
const mergedClearIcon = clearIcon ?? <CloseCircleFilled />;
// Validation Feedback Icon
const getSuffixIconNode = (arrowIcon?: ReactNode) => {
if (suffixIcon === null && !hasFeedback && !showArrow) {
return null;
}
return (
<>
{showSuffixIcon !== false && arrowIcon}
{hasFeedback && feedbackIcon}
</>
);
};
// Arrow item icon
let mergedSuffixIcon = null;
if (suffixIcon !== undefined) {
mergedSuffixIcon = getSuffixIconNode(suffixIcon);
} else if (loading) {
mergedSuffixIcon = getSuffixIconNode(<LoadingOutlined spin />);
} else {
mergedSuffixIcon = ({ open, showSearch }: { open: boolean; showSearch: boolean }) => {
if (open && showSearch) {
return getSuffixIconNode(<SearchOutlined />);
}
return getSuffixIconNode(<DownOutlined />);
};
}
// Checked item icon
let mergedItemIcon = null;
if (menuItemSelectedIcon !== undefined) {
mergedItemIcon = menuItemSelectedIcon;
} else if (multiple) {
mergedItemIcon = <CheckOutlined />;
} else {
mergedItemIcon = null;
}
let mergedRemoveIcon = null;
if (removeIcon !== undefined) {
mergedRemoveIcon = removeIcon;
} else {
mergedRemoveIcon = <CloseOutlined />;
}
return {
// TODO: remove as when all the deps bumped
clearIcon: mergedClearIcon as React.ReactNode,
suffixIcon: mergedSuffixIcon,
itemIcon: mergedItemIcon,
removeIcon: mergedRemoveIcon,
};
}