https://github.com/brimdata/react-arborist?tab=readme-ov-file#node-component-props
npm install react-arborist
const data = [
{ id: "1", name: "Unread" },
{ id: "2", name: "Threads" },
{
id: "3",
name: "Chat Rooms",
children: [
{ id: "c1", name: "General" },
{ id: "c2", name: "Random" },
{ id: "c3", name: "Open Source Projects" },
],
},
];
import { Tree } from "react-arborist";
function App() {
return <Tree initialData={data}> </Tree>;
}
import { Tree } from "react-arborist";
function App() {
return <Tree initialData={data}
width={300} // 컨테이너 너비
height={300} // 컨테이너 높이
paddingTop={10} // 컨테이너 상단 패딩
paddingBottom={10} //컨테이너 하단 패딩
padding={20} // 컨테이너 상/하당 패딩
rowHeight={20} // 노드 높이
indent={20} // 하위 노드 깊이
className={"border"} // 컨테이너 className
rowClassName={"border"} // 노드 className
/>;
}
import { Tree } from "react-arborist";
function App() {
return <Tree initialData={data}>{Node}</Tree>;
}
// 커스텀 노드 생성
import { NodeRendererProps } from "react-arborist";
function Node({ node, tree, style, dragHandle }: NodeRendererProps<T>) {
return (
<div className="node-container" style={style} ref={dragHandle}>
<div
className="node-content"
onClick={() => node.isInternal && node.toggle()}
>
{/* isOpen : 하위 요소 노출 여부 */}
{node.isOpen ? "-" : "+"}
{/* isInternal: 하위 요소 존재 여부 */}
{node.isInternal ? "🗂️" : "📁"}
<span className="node-text">
<span>{node.data.name}</span>
</span>
</div>
</div>
);
}
node.isRoot
node.isLeaf
node.isInternal
node.isOpen
node.isEditing
node.isSelected
node.isSelectedStart
node.isSelectedEnd
node.isOnlySelection
node.isFocused
node.isDragging
node.willReceiveDrop
node.state
type NodeState = {
isEditing: boolean;
isDragging: boolean;
isSelected: boolean;
isSelectedStart: boolean;
isSelectedEnd: boolean;
isFocused: boolean;
isOpen: boolean;
isClosed: boolean;
isLeaf: boolean;
isInternal: boolean;
willReceiveDrop: boolean;
};
node.childIndex
node.next
node.prev
node.nextSibling
node.select()
node.deselect()
node.selectMulti()
node.selectContiguous()
node.activate()
node.focus()
node.open()
node.close()
node.toggle()
node.openParents()
node.edit()
node.submit(newName)
node.reset()
node.handleClick(event)
tree.get(id) : NodeApi | null
tree.at(index) : NodeApi | null
tree.visibleNodes : NodeApi[]
tree.firstNode : NodeApi | null
tree.lastNode : NodeApi | null
tree.focusedNode : NodeApi | null
tree.mostRecentNode : NodeApi | null
tree.nextNode : NodeApi | null
tree.prevNode : NodeApi | null
tree.hasFocus : boolean
tree.focus(id)
tree.isFocused(id) : boolean
tree.pageUp()
tree.pageDown()
tree.selectedIds : Set
tree.selectedNodes : NodeApi[]
tree.hasNoSelection : boolean
tree.hasSingleSelection : boolean
tree.hasMultipleSelections : boolean
tree.isSelected(id) : boolean
tree.select(id)
tree.deselect(id)
tree.selectMulti(id)
tree.selectContiguous(id)
tree.deselectAll()
tree.selectAll()
tree.open(id)
tree.close(id)
tree.toggle(id)
tree.openParents(id)
tree.openSiblings(id)
tree.openAll()
tree.closeAll()
tree.isOpen(id) : boolean
tree.isDragging(id) : boolean
tree.willReceiveDrop(id) : boolean
tree.scrollTo(id, [align])
tree.isEditing : boolean
tree.isFiltered : boolean
tree.props : TreeProps
tree.root : NodeApi