UNPKG

2.57 kBTypeScriptView Raw
1import * as React from "react";
2import { Props } from "../../common/props";
3import { TreeNodeInfo } from "./treeNode";
4export declare type TreeEventHandler<T = {}> = (node: TreeNodeInfo<T>, nodePath: number[], e: React.MouseEvent<HTMLElement>) => void;
5export declare type TreeProps<T = {}> = ITreeProps<T>;
6/** @deprecated use TreeProps */
7export interface ITreeProps<T = {}> extends Props {
8 /**
9 * The data specifying the contents and appearance of the tree.
10 */
11 contents: Array<TreeNodeInfo<T>>;
12 /**
13 * Invoked when a node is clicked anywhere other than the caret for expanding/collapsing the node.
14 */
15 onNodeClick?: TreeEventHandler<T>;
16 /**
17 * Invoked when caret of an expanded node is clicked.
18 */
19 onNodeCollapse?: TreeEventHandler<T>;
20 /**
21 * Invoked when a node is right-clicked or the context menu button is pressed on a focused node.
22 */
23 onNodeContextMenu?: TreeEventHandler<T>;
24 /**
25 * Invoked when a node is double-clicked. Be careful when using this in combination with
26 * an `onNodeClick` (single-click) handler, as the way this behaves can vary between browsers.
27 * See http://stackoverflow.com/q/5497073/3124288
28 */
29 onNodeDoubleClick?: TreeEventHandler<T>;
30 /**
31 * Invoked when the caret of a collapsed node is clicked.
32 */
33 onNodeExpand?: TreeEventHandler<T>;
34 /**
35 * Invoked when the mouse is moved over a node.
36 */
37 onNodeMouseEnter?: TreeEventHandler<T>;
38 /**
39 * Invoked when the mouse is moved out of a node.
40 */
41 onNodeMouseLeave?: TreeEventHandler<T>;
42}
43export declare class Tree<T = {}> extends React.Component<TreeProps<T>> {
44 static displayName: string;
45 static ofType<U>(): new (props: TreeProps<U>) => Tree<U>;
46 static nodeFromPath<U>(path: number[], treeNodes?: Array<TreeNodeInfo<U>>): TreeNodeInfo<U>;
47 private nodeRefs;
48 render(): JSX.Element;
49 /**
50 * Returns the underlying HTML element of the `Tree` node with an id of `nodeId`.
51 * This element does not contain the children of the node, only its label and controls.
52 * If the node is not currently mounted, `undefined` is returned.
53 */
54 getNodeContentElement(nodeId: string | number): HTMLElement | undefined;
55 private renderNodes;
56 private handleNodeCollapse;
57 private handleNodeClick;
58 private handleContentRef;
59 private handleNodeContextMenu;
60 private handleNodeDoubleClick;
61 private handleNodeExpand;
62 private handleNodeMouseEnter;
63 private handleNodeMouseLeave;
64 private handlerHelper;
65}