mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
type: fix Tree icon and switcherIcon type (#49821)
This commit is contained in:
parent
8a090c951c
commit
e97a27d384
@ -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}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user