UNPKG

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