UNPKG

4.72 kBTypeScriptView Raw
1import type { Component } from 'react';
2import React from 'react';
3import type { BasicDataNode, TreeProps as RcTreeProps } from 'rc-tree';
4import RcTree from 'rc-tree';
5import type { DataNode, Key } from 'rc-tree/lib/interface';
6export type SwitcherIcon = React.ReactNode | ((props: AntTreeNodeProps) => React.ReactNode);
7export type TreeLeafIcon = React.ReactNode | ((props: AntTreeNodeProps) => React.ReactNode);
8export interface AntdTreeNodeAttribute {
9 eventKey: string;
10 prefixCls: string;
11 className: string;
12 expanded: boolean;
13 selected: boolean;
14 checked: boolean;
15 halfChecked: boolean;
16 children: React.ReactNode;
17 title: React.ReactNode;
18 pos: string;
19 dragOver: boolean;
20 dragOverGapTop: boolean;
21 dragOverGapBottom: boolean;
22 isLeaf: boolean;
23 selectable: boolean;
24 disabled: boolean;
25 disableCheckbox: boolean;
26}
27export interface AntTreeNodeProps {
28 className?: string;
29 checkable?: boolean;
30 disabled?: boolean;
31 disableCheckbox?: boolean;
32 title?: string | React.ReactNode;
33 key?: Key;
34 eventKey?: string;
35 isLeaf?: boolean;
36 checked?: boolean;
37 expanded?: boolean;
38 loading?: boolean;
39 selected?: boolean;
40 selectable?: boolean;
41 icon?: ((treeNode: AntdTreeNodeAttribute) => React.ReactNode) | React.ReactNode;
42 children?: React.ReactNode;
43 [customProp: string]: any;
44}
45export interface AntTreeNode extends Component<AntTreeNodeProps, {}> {
46}
47export interface AntTreeNodeBaseEvent {
48 node: AntTreeNode;
49 nativeEvent: MouseEvent;
50}
51export interface AntTreeNodeCheckedEvent extends AntTreeNodeBaseEvent {
52 event: 'check';
53 checked?: boolean;
54 checkedNodes?: AntTreeNode[];
55}
56export interface AntTreeNodeSelectedEvent extends AntTreeNodeBaseEvent {
57 event: 'select';
58 selected?: boolean;
59 selectedNodes?: DataNode[];
60}
61export interface AntTreeNodeExpandedEvent extends AntTreeNodeBaseEvent {
62 expanded?: boolean;
63}
64export interface AntTreeNodeMouseEvent {
65 node: AntTreeNode;
66 event: React.DragEvent<HTMLElement>;
67}
68export interface AntTreeNodeDragEnterEvent extends AntTreeNodeMouseEvent {
69 expandedKeys: Key[];
70}
71export interface AntTreeNodeDropEvent {
72 node: AntTreeNode;
73 dragNode: AntTreeNode;
74 dragNodesKeys: Key[];
75 dropPosition: number;
76 dropToGap?: boolean;
77 event: React.MouseEvent<HTMLElement>;
78}
79export type TreeNodeNormal = DataNode;
80type DraggableFn = (node: DataNode) => boolean;
81interface DraggableConfig {
82 icon?: React.ReactNode | false;
83 nodeDraggable?: DraggableFn;
84}
85export interface TreeProps<T extends BasicDataNode = DataNode> extends Omit<RcTreeProps<T>, 'prefixCls' | 'showLine' | 'direction' | 'draggable' | 'icon' | 'switcherIcon'> {
86 showLine?: boolean | {
87 showLeafIcon: boolean | TreeLeafIcon;
88 };
89 className?: string;
90 /** Whether to support multiple selection */
91 multiple?: boolean;
92 /** Whether to automatically expand the parent node */
93 autoExpandParent?: boolean;
94 /** Node selection in Checkable state is fully controlled (the selected state of parent and child nodes is no longer associated) */
95 checkStrictly?: boolean;
96 /** Whether to support selection */
97 checkable?: boolean;
98 /** whether to disable the tree */
99 disabled?: boolean;
100 /** Expand all tree nodes by default */
101 defaultExpandAll?: boolean;
102 /** Expand the corresponding tree node by default */
103 defaultExpandParent?: boolean;
104 /** Expand the specified tree node by default */
105 defaultExpandedKeys?: Key[];
106 /** (Controlled) Expand the specified tree node */
107 expandedKeys?: Key[];
108 /** (Controlled) Tree node with checked checkbox */
109 checkedKeys?: Key[] | {
110 checked: Key[];
111 halfChecked: Key[];
112 };
113 /** Tree node with checkbox checked by default */
114 defaultCheckedKeys?: Key[];
115 /** (Controlled) Set the selected tree node */
116 selectedKeys?: Key[];
117 /** Tree node selected by default */
118 defaultSelectedKeys?: Key[];
119 selectable?: boolean;
120 /** Click on the tree node to trigger */
121 filterAntTreeNode?: (node: AntTreeNode) => boolean;
122 loadedKeys?: Key[];
123 /** Set the node to be draggable (IE>8) */
124 draggable?: DraggableFn | boolean | DraggableConfig;
125 style?: React.CSSProperties;
126 showIcon?: boolean;
127 icon?: ((nodeProps: AntdTreeNodeAttribute) => React.ReactNode) | React.ReactNode | RcTreeProps<T>['icon'];
128 switcherIcon?: SwitcherIcon | RcTreeProps<T>['switcherIcon'];
129 prefixCls?: string;
130 children?: React.ReactNode;
131 blockNode?: boolean;
132}
133declare const Tree: React.ForwardRefExoticComponent<TreeProps<DataNode> & React.RefAttributes<RcTree<DataNode>>>;
134export default Tree;
135
\No newline at end of file