A Shadcn UI component for hierarchical lists of data with nested levels that can be expanded and collapsed.
A Shadcn UI component for hierarchical lists of data with nested levels that can be expanded and collapsed.
The Tree View component allows you to navigate hierarchical lists of data with nested levels that can be expanded and collapsed.
Based on implementation by WangLarry and bytechase.
npx shadcn add "https://mrlightful.com/registry/tree-view"type TreeProps = React.HTMLAttributes & {
data: TreeDataItem[] | TreeDataItem;
initialSelectedItemId?: string;
onSelectChange?: (item: TreeDataItem | undefined) => void;
renderItem?: (params: TreeRenderItemParams) => React.ReactNode;
expandAll?: boolean;
defaultNodeIcon?: React.ComponentType;
defaultLeafIcon?: React.ComponentType;
};interface TreeDataItem {
id: string;
name: string;
icon?: React.ComponentType;
selectedIcon?: React.ComponentType;
openIcon?: React.ComponentType;
children?: TreeDataItem[];
actions?: React.ReactNode;
onClick?: () => void;
draggable?: boolean;
droppable?: boolean;
disabled?: boolean;
className?: string;
}import { TreeView, TreeDataItem } from "@/components/ui/tree-view";
const data: TreeDataItem[] = [
{
id: "1",
name: "Item 1",
children: [
{
id: "2",
name: "Item 1.1",
children: [
{
id: "3",
name: "Item 1.1.1",
},
{
id: "4",
name: "Item 1.1.2",
},
],
},
{
id: "5",
name: "Item 1.2 (disabled)",
disabled: true,
},
],
},
{
id: "6",
name: "Item 2 (draggable)",
draggable: true,
},
];
;Licensed under the MIT license, see LICENSE.
No open issues yet, or sync has not completed.