UNPKG

3.8 kBTypeScriptView Raw
1import * as React from 'react';
2export { ScrollTo } from 'rc-virtual-list/lib/List';
3export interface TreeNodeProps<TreeDataType extends BasicDataNode = DataNode> {
4 eventKey?: Key;
5 prefixCls?: string;
6 className?: string;
7 style?: React.CSSProperties;
8 id?: string;
9 expanded?: boolean;
10 selected?: boolean;
11 checked?: boolean;
12 loaded?: boolean;
13 loading?: boolean;
14 halfChecked?: boolean;
15 title?: React.ReactNode | ((data: TreeDataType) => React.ReactNode);
16 dragOver?: boolean;
17 dragOverGapTop?: boolean;
18 dragOverGapBottom?: boolean;
19 pos?: string;
20 domRef?: React.Ref<HTMLDivElement>;
21 /** New added in Tree for easy data access */
22 data?: TreeDataType;
23 isStart?: boolean[];
24 isEnd?: boolean[];
25 active?: boolean;
26 onMouseMove?: React.MouseEventHandler<HTMLDivElement>;
27 isLeaf?: boolean;
28 checkable?: boolean;
29 selectable?: boolean;
30 disabled?: boolean;
31 disableCheckbox?: boolean;
32 icon?: IconType;
33 switcherIcon?: IconType;
34 children?: React.ReactNode;
35}
36/** For fieldNames, we provides a abstract interface */
37export interface BasicDataNode {
38 checkable?: boolean;
39 disabled?: boolean;
40 disableCheckbox?: boolean;
41 icon?: IconType;
42 isLeaf?: boolean;
43 selectable?: boolean;
44 switcherIcon?: IconType;
45 /** Set style of TreeNode. This is not recommend if you don't have any force requirement */
46 className?: string;
47 style?: React.CSSProperties;
48}
49/** Provide a wrap type define for developer to wrap with customize fieldNames data type */
50export type FieldDataNode<T, ChildFieldName extends string = 'children'> = BasicDataNode & T & Partial<Record<ChildFieldName, FieldDataNode<T, ChildFieldName>[]>>;
51export type DataNode = FieldDataNode<{
52 key: string | number;
53 title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
54}>;
55export type EventDataNode<TreeDataType> = {
56 key: React.Key;
57 expanded: boolean;
58 selected: boolean;
59 checked: boolean;
60 loaded: boolean;
61 loading: boolean;
62 halfChecked: boolean;
63 dragOver: boolean;
64 dragOverGapTop: boolean;
65 dragOverGapBottom: boolean;
66 pos: string;
67 active: boolean;
68} & TreeDataType & BasicDataNode;
69export type IconType = React.ReactNode | ((props: TreeNodeProps) => React.ReactNode);
70export type Key = string | number;
71export type NodeElement = React.ReactElement<TreeNodeProps> & {
72 selectHandle?: HTMLSpanElement;
73 type: {
74 isTreeNode: boolean;
75 };
76};
77export type NodeInstance<TreeDataType extends BasicDataNode = DataNode> = React.Component<TreeNodeProps<TreeDataType>> & {
78 selectHandle?: HTMLSpanElement;
79};
80export interface Entity {
81 node: NodeElement;
82 index: number;
83 key: Key;
84 pos: string;
85 parent?: Entity;
86 children?: Entity[];
87}
88export interface DataEntity<TreeDataType extends BasicDataNode = DataNode> extends Omit<Entity, 'node' | 'parent' | 'children'> {
89 node: TreeDataType;
90 nodes: TreeDataType[];
91 parent?: DataEntity<TreeDataType>;
92 children?: DataEntity<TreeDataType>[];
93 level: number;
94}
95export interface FlattenNode<TreeDataType extends BasicDataNode = DataNode> {
96 parent: FlattenNode<TreeDataType> | null;
97 children: FlattenNode<TreeDataType>[];
98 pos: string;
99 data: TreeDataType;
100 title: React.ReactNode;
101 key: Key;
102 isStart: boolean[];
103 isEnd: boolean[];
104}
105export type GetKey<RecordType> = (record: RecordType, index?: number) => Key;
106export type GetCheckDisabled<RecordType> = (record: RecordType) => boolean;
107export type Direction = 'ltr' | 'rtl' | undefined;
108export interface FieldNames {
109 title?: string;
110 /** @private Internal usage for `rc-tree-select`, safe to remove if no need */
111 _title?: string[];
112 key?: string;
113 children?: string;
114}