Components
Tree

Based on the provided type definitions for your Tree component, here's a comprehensive and understandable MDX documentation that you can use:

Tree Component API Reference

The Tree component provides a flexible and interactive way to display hierarchical data structures within your React application. It supports features like expand/collapse, drag-and-drop reordering, nesting, and virtualization for performance optimization with large datasets.

Props

OptionTypeDescription
treeTreeDataThe tree data structure to be rendered.
onExpand(ItemId: ItemId, path: Path) => voidFunction called when a parent item needs to be expanded.
onCollapse(ItemId: ItemId, path: Path) => voidFunction called when a parent item needs to be collapsed.
onDragStart(ItemId: ItemId) => voidFunction called when the user starts dragging an item.
onDragEnd( sourcePosition: TreeSourcePosition, destinationPosition?: TreeDestinationPosition ) => voidFunction called when the user finishes dragging, with source and optional destination positions.
renderItem(item: RenderItemParams) => ReactNodeFunction to render a single item within the tree.
offsetPerLevelnumberPixel offset used to scaffold the tree by the consumer
isDragEnabledboolean | ((item: TreeItem) => boolean)Enables drag-and-drop reordering on the tree. Can be conditionally set based on the item.
isNestingEnabledbooleanAllows items to be nested within each other while dragging.
isVirtualizationEnabledbooleanEnables virtualization to render only visible parts of the tree, improving performance with large datasets.
virtualItemHeightnumberVirtual item's height. If the isVirtualizationEnabled is true, please set it manually.

Types

RenderItemParams

RenderItemParams provides properties essential for rendering a tree item with drag-and-drop functionality.

OptionTypeDescription
itemTreeItemThe tree item that is being rendered.
onExpand(ItemId: ItemId) => voidFunction called when an item needs to be expanded.
onCollapse(ItemId: ItemId) => voidFunction called when an item needs to be collapsed.
providedDraggableProvidedProvides drag-and-drop handlers, including draggable props.
snapshotDraggableStateSnapshotContains state information about the drag-and-drop operation.

TreeItem

TreeItem represents a single item within the tree structure.

OptionTypeDescription
idItemIdUnique identifier for the item.
childrenItemId[]Array of ItemIds representing the item's children.
hasChildrenboolean?Optional boolean indicating if the item has children.
isExpandedboolean?Optional boolean indicating if the item's children are currently visible.
isChildrenLoadingboolean?Optional boolean indicating if the item's children are being loaded.
dataTreeItemData?Optional field for additional data associated with the item.

TreeData

TreeData structures the overall tree data.

OptionTypeDescription
rootIdItemIdThe unique identifier for the root item of the tree.
itemsRecord<ItemId, TreeItem>An object mapping each ItemId to its corresponding TreeItem.

Example Usage

Below, in the CodeSandbox, you can find an example demonstrating the example usage of the Tree component: