Created
June 12, 2023 18:23
-
-
Save devdave/e2d5aeb0f254b7420ddc5cf4a87d2c49 to your computer and use it in GitHub Desktop.
Toggleable and hand onSelect with custom node.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {TargetedElement} from "./types.ts"; | |
import {FC} from "react"; | |
import {Tree, NodeRendererProps} from "react-arborist"; | |
type setElementsType = (elements: TargetedElement[]) => void; | |
interface ContentTreeProps { | |
elements: TargetedElement[], | |
setElements: setElementsType | |
}; | |
const Node:FC<NodeRendererProps<TargetedElement>> = ({ node, style, dragHandle }) => { | |
/* This node instance can do many things. See the API reference. */ | |
return ( | |
<div style={style} ref={dragHandle}> | |
{node.data.targetType === "chapter" ? "๐" : "๐"} | |
{node.data.name} | |
</div> | |
); | |
} | |
export const ContentTree:FC<ContentTreeProps> = ({elements, setElements}) => { | |
return ( | |
<Tree | |
data={elements} | |
disableMultiSelection={true} | |
onSelect={(nodes)=>{ | |
console.log(nodes) | |
const node = nodes[0]; | |
node.toggle(); | |
}} | |
> | |
{Node} | |
</Tree> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment