- React Arborist
+ React Arborist
In this demo, we have the Game of Thrones family tree rendered with
the Tree
component. You can drag and drop the items in
diff --git a/packages/demo/src/got.tsx b/packages/demo/src/got.tsx
index dbe4818a..56d43a0c 100644
--- a/packages/demo/src/got.tsx
+++ b/packages/demo/src/got.tsx
@@ -1,39 +1,43 @@
-import React from "react";
+import React, { useRef } from "react";
// @ts-ignore
import AutoSize from "react-virtualized-auto-sizer";
import { Tree, TreeApi } from "react-arborist";
import { Node } from "./node";
-import { useBackend } from "./backend";
+import { MyData, useBackend } from "./backend";
export function GotLineage() {
const backend = useBackend();
+ const rootElement = useRef(null);
return (
-
- {(props: any) => (
- {
- // @ts-ignore
- global.tree = tree;
- }}
- className="react-aborist"
- data={backend.data}
- getChildren="children"
- isOpen="isOpen"
- disableDrop={(d) => d.name === "House Arryn"}
- hideRoot
- indent={24}
- onMove={backend.onMove}
- onToggle={backend.onToggle}
- onEdit={backend.onEdit}
- rowHeight={22}
- width={props.width}
- height={props.height}
- onClick={() => console.log("clicked the tree")}
- onContextMenu={() => console.log("context menu the tree")}
- >
- {Node}
-
- )}
-
+
+
+ {(props: any) => (
+ {
+ // @ts-ignore
+ global.tree = tree;
+ }}
+ className="react-aborist"
+ data={backend.data}
+ getChildren="children"
+ isOpen="isOpen"
+ disableDrop={(d: MyData) => d.name === "House Arryn"}
+ hideRoot
+ indent={24}
+ onMove={backend.onMove}
+ onToggle={backend.onToggle}
+ onEdit={backend.onEdit}
+ rowHeight={22}
+ width={props.width}
+ height={props.height}
+ onClick={() => console.log("clicked the tree")}
+ onContextMenu={() => console.log("context menu the tree")}
+ dndRootElement={undefined}
+ >
+ {Node}
+
+ )}
+
+
);
}
diff --git a/packages/react-arborist/package.json b/packages/react-arborist/package.json
index daa68d38..84d2b82c 100644
--- a/packages/react-arborist/package.json
+++ b/packages/react-arborist/package.json
@@ -17,7 +17,8 @@
"scripts": {
"build": "run-p 'build:**'",
"build:js": "parcel build --target main --target module",
- "build:types": "tsc --outDir dist"
+ "build:types": "tsc --outDir dist",
+ "watch": "yarn build:types --watch"
},
"peerDependencies": {
"react": ">= 16.14",
diff --git a/packages/react-arborist/src/components/tree.tsx b/packages/react-arborist/src/components/tree.tsx
index a10c3c86..1f89a6e1 100644
--- a/packages/react-arborist/src/components/tree.tsx
+++ b/packages/react-arborist/src/components/tree.tsx
@@ -1,4 +1,10 @@
-import { forwardRef, MouseEventHandler, ReactElement, useMemo, useRef } from "react";
+import {
+ forwardRef,
+ MouseEventHandler,
+ ReactElement,
+ useMemo,
+ useRef,
+} from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { FixedSizeList } from "react-window";
@@ -20,8 +26,13 @@ const OuterElement = forwardRef(function Outer(
const { children, ...rest } = props;
const tree = useStaticContext();
return (
- // @ts-ignore
-
+
@@ -91,6 +102,7 @@ export const Tree = forwardRef(function Tree
(
props.openByDefault,
]
);
+
return (
(
onClick={props.onClick}
onContextMenu={props.onContextMenu}
>
-
+
-
+
diff --git a/packages/react-arborist/src/types.ts b/packages/react-arborist/src/types.ts
index f2e35351..3a7027cc 100644
--- a/packages/react-arborist/src/types.ts
+++ b/packages/react-arborist/src/types.ts
@@ -102,26 +102,30 @@ export type StateContext = {
selection: SelectionState;
visibleIds: string[];
};
+
+type BoolFunc = (data: T) => boolean;
+
export interface TreeProps {
children: NodeRenderer;
+ className?: string | undefined;
data: T;
+ disableDrag?: string | boolean | BoolFunc;
+ disableDrop?: string | boolean | BoolFunc;
+ dndRootElement?: globalThis.Node | null;
+ getChildren?: string | ((d: T) => T[]);
+ handle?: Ref>; // Deprecated
height?: number;
- width?: number;
- rowHeight?: number;
- indent?: number;
hideRoot?: boolean;
- onToggle?: ToggleHandler;
- onMove?: MoveHandler;
- onEdit?: EditHandler;
- getChildren?: string | ((d: T) => T[]);
- isOpen?: string | ((d: T) => boolean);
- disableDrag?: string | boolean | ((d: T) => boolean);
- disableDrop?: string | boolean | ((d: T) => boolean);
- openByDefault?: boolean;
- className?: string | undefined;
- handle?: Ref>;
+ indent?: number;
+ isOpen?: string | BoolFunc;
onClick?: MouseEventHandler;
onContextMenu?: MouseEventHandler;
+ onEdit?: EditHandler;
+ onMove?: MoveHandler;
+ onToggle?: ToggleHandler;
+ openByDefault?: boolean;
+ rowHeight?: number;
+ width?: number;
}
export type TreeProviderProps = {