& {
data: TreeDataItem[] | TreeDataItem;
initialSelectedItemId?: string;
onSelectChange?: (item: TreeDataItem | undefined) => void;
renderItem?: (params: TreeRenderItemParams) => React.ReactNode;
expandAll?: boolean;
defaultNodeIcon?: React.ComponentType<{ className?: string }>;
defaultLeafIcon?: React.ComponentType<{ className?: string }>;
};
```
```
--------------------------------
### Create a cn Utility Function for Class Merging
Source: https://context7.com/mrlightful/shadcn-tree-view/llms.txt
A utility function that merges Tailwind CSS classes using `clsx` and `tailwind-merge`. It prevents class conflicts and allows conditional styling. Accepts multiple string arguments or an object for conditional classes.
```typescript
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
// Usage examples:
cn("px-4 py-2", "px-6"); // "px-6 py-2" (px-6 overrides px-4)
cn("text-red-500", false && "text-blue-500"); // "text-red-500"
cn("rounded", { "bg-primary": true }); // "rounded bg-primary"
cn("p-4", undefined, null, "m-2"); // "p-4 m-2"
```
--------------------------------
### Custom Tree Item Rendering
Source: https://context7.com/mrlightful/shadcn-tree-view/llms.txt
Utilizes the `renderItem` prop for complete control over tree item display. Receives item data, level, and state information.
```tsx
import { TreeView, TreeDataItem, TreeRenderItemParams } from "@/components/ui/tree-view";
import { ChevronRight, File, Folder } from "lucide-react";
const data: TreeDataItem[] = [
{
id: "1",
name: "src",
children: [
{ id: "1-1", name: "components", children: [{ id: "1-1-1", name: "Button.tsx" }] },
{ id: "1-2", name: "utils.ts" },
],
},
];
function CustomTreeItem({ item, level, isLeaf, isSelected, isOpen, hasChildren }: TreeRenderItemParams) {
return (
{isLeaf ? (
) : (
)}
{item.name}
{hasChildren && (
{item.children?.length} items
)}
);
}
```
--------------------------------
### Tree Item Data Structure
Source: https://github.com/mrlightful/shadcn-tree-view/blob/main/README.md
Defines the structure for individual items within the Tree View data.
```APIDOC
## Tree Item Data Structure
```tsx
interface TreeDataItem {
id: string;
name: string;
icon?: React.ComponentType<{ className?: string }>;
selectedIcon?: React.ComponentType<{ className?: string }>;
openIcon?: React.ComponentType<{ className?: string }>;
children?: TreeDataItem[];
actions?: React.ReactNode;
onClick?: () => void;
draggable?: boolean;
droppable?: boolean;
disabled?: boolean;
className?: string;
}
```
```
--------------------------------
### Tree Data Item Interface Definition
Source: https://github.com/mrlightful/shadcn-tree-view/blob/main/README.md
Defines the structure for individual data items within the Tree View, including properties for hierarchy, icons, and interactivity.
```typescript
interface TreeDataItem {
id: string;
name: string;
icon?: React.ComponentType<{ className?: string }>;
selectedIcon?: React.ComponentType<{ className?: string }>;
openIcon?: React.ComponentType<{ className?: string }>;
children?: TreeDataItem[];
actions?: React.ReactNode;
onClick?: () => void;
draggable?: boolean;
droppable?: boolean;
disabled?: boolean;
className?: string;
}
```
--------------------------------
### Tree View Props Type Definition
Source: https://github.com/mrlightful/shadcn-tree-view/blob/main/README.md
Defines the properties available for the main Tree View component, including data input and event handlers.
```typescript
type TreeProps = React.HTMLAttributes & {
data: TreeDataItem[] | TreeDataItem;
initialSelectedItemId?: string;
onSelectChange?: (item: TreeDataItem | undefined) => void;
renderItem?: (params: TreeRenderItemParams) => React.ReactNode;
expandAll?: boolean;
defaultNodeIcon?: React.ComponentType<{ className?: string }>;
defaultLeafIcon?: React.ComponentType<{ className?: string }>;
};
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.