type: fix Tree icon and switcherIcon type (#49821)

This commit is contained in:
afc163 2024-07-12 10:13:27 +08:00 committed by GitHub
parent 8a090c951c
commit e97a27d384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View File

@ -16,6 +16,7 @@ import SwitcherIconCom from './utils/iconUtil';
export type SwitcherIcon = React.ReactNode | ((props: AntTreeNodeProps) => React.ReactNode);
export type TreeLeafIcon = React.ReactNode | ((props: AntTreeNodeProps) => React.ReactNode);
type TreeIcon = React.ReactNode | ((props: AntdTreeNodeAttribute) => React.ReactNode);
export interface AntdTreeNodeAttribute {
eventKey: string;
@ -42,16 +43,16 @@ export interface AntTreeNodeProps {
checkable?: boolean;
disabled?: boolean;
disableCheckbox?: boolean;
title?: string | React.ReactNode;
title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
key?: Key;
eventKey?: string;
eventKey?: Key;
isLeaf?: boolean;
checked?: boolean;
expanded?: boolean;
loading?: boolean;
selected?: boolean;
selectable?: boolean;
icon?: ((treeNode: AntdTreeNodeAttribute) => React.ReactNode) | React.ReactNode;
icon?: TreeIcon;
children?: React.ReactNode;
[customProp: string]: any;
}
@ -148,11 +149,8 @@ export interface TreeProps<T extends BasicDataNode = DataNode>
draggable?: DraggableFn | boolean | DraggableConfig;
style?: React.CSSProperties;
showIcon?: boolean;
icon?:
| ((nodeProps: AntdTreeNodeAttribute) => React.ReactNode)
| React.ReactNode
| RcTreeProps<T>['icon'];
switcherIcon?: SwitcherIcon | RcTreeProps<T>['switcherIcon'];
icon?: TreeIcon;
switcherIcon?: SwitcherIcon;
prefixCls?: string;
children?: React.ReactNode;
blockNode?: boolean;
@ -227,7 +225,7 @@ const Tree = React.forwardRef<RcTree, TreeProps>((props, ref) => {
const renderSwitcherIcon: React.FC<AntTreeNodeProps> = (nodeProps) => (
<SwitcherIconCom
prefixCls={prefixCls}
switcherIcon={switcherIcon as SwitcherIcon}
switcherIcon={switcherIcon}
treeNodeProps={nodeProps}
showLine={showLine}
/>
@ -258,7 +256,7 @@ const Tree = React.forwardRef<RcTree, TreeProps>((props, ref) => {
direction={direction}
checkable={checkable ? <span className={`${prefixCls}-checkbox-inner`} /> : checkable}
selectable={selectable}
switcherIcon={renderSwitcherIcon as RcTreeProps['switcherIcon']}
switcherIcon={renderSwitcherIcon}
draggable={draggableConfig}
>
{children}

View File

@ -77,7 +77,7 @@ describe('Tree.TypeScript', () => {
expect(container).toBeTruthy();
});
it('draggable params type', () => {
it('draggable/icon/switcherIcon params type', () => {
const { container } = render(
<Tree
treeData={[
@ -93,6 +93,8 @@ describe('Tree.TypeScript', () => {
},
]}
draggable={(node: DataNode) => node.title === 'Little'}
icon={(props) => (props.isLeaf ? 1 : 0)}
switcherIcon={(props) => (props.isLeaf ? 1 : 0)}
/>,
);
expect(container).toBeTruthy();