BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/domain-ui/tree

tree

domain-ui/tree
FreeComponent

domain-ui publishes no description for this item.

Install it

npx shadcn@latest add https://raw.githubusercontent.com/teurons/domain-ui/main/apps/web/public/r/tree.json

Source

components/domain-ui/tree.tsxraw.githubusercontent.com/teurons/domain-ui/main/apps/web/public/r/tree.json · first 6 KB
1"use client";
2import { ChevronRight, File, Folder, FolderOpen } from "lucide-react";
3import { AnimatePresence, motion } from "motion/react";
4import {
5 type ComponentProps,
6 createContext,
7 type HTMLAttributes,
8 type ReactNode,
9 useCallback,
10 useContext,
11 useId,
12 useState,
13} from "react";
14import { cn } from "@/lib/utils";
15
16type TreeContextType = {
17 expandedIds: Set<string>;
18 selectedIds: string[];
19 toggleExpanded: (nodeId: string) => void;
20 handleSelection: (nodeId: string, ctrlKey: boolean) => void;
21 showLines?: boolean;
22 showIcons?: boolean;
23 selectable?: boolean;
24 multiSelect?: boolean;
25 indent?: number;
26 animateExpand?: boolean;
27};
28
29const TreeContext = createContext<TreeContextType | undefined>(undefined);
30
31const useTree = () => {
32 const context = useContext(TreeContext);
33 if (!context) {
34 throw new Error("Tree components must be used within a TreeProvider");
35 }
36 return context;
37};
38
39type TreeNodeContextType = {
40 nodeId: string;
41 level: number;
42 isLast: boolean;
43 parentPath: boolean[];
44};
45
46const TreeNodeContext = createContext<TreeNodeContextType | undefined>(
47 undefined
48);
49
50const useTreeNode = () => {
51 const context = useContext(TreeNodeContext);
52 if (!context) {
53 throw new Error("TreeNode components must be used within a TreeNode");
54 }
55 return context;
56};
57
58export type TreeProviderProps = {
59 children: ReactNode;
60 defaultExpandedIds?: string[];
61 showLines?: boolean;
62 showIcons?: boolean;
63 selectable?: boolean;
64 multiSelect?: boolean;
65 selectedIds?: string[];
66 onSelectionChange?: (selectedIds: string[]) => void;
67 indent?: number;
68 animateExpand?: boolean;
69 className?: string;
70};
71
72export const TreeProvider = ({
73 children,
74 defaultExpandedIds = [],
75 showLines = true,
76 showIcons = true,
77 selectable = true,
78 multiSelect = false,
79 selectedIds,
80 onSelectionChange,
81 indent = 19,
82 animateExpand = true,
83 className,
84}: TreeProviderProps) => {
85 const [expandedIds, setExpandedIds] = useState<Set<string>>(
86 new Set(defaultExpandedIds)
87 );
88 const [internalSelectedIds, setInternalSelectedIds] = useState<string[]>(
89 selectedIds ?? []
90 );
91
92 const isControlled =
93 selectedIds !== undefined && onSelectionChange !== undefined;
94 const currentSelectedIds = isControlled ? selectedIds : internalSelectedIds;
95
96 const toggleExpanded = useCallback((nodeId: string) => {
97 setExpandedIds((prev) => {
98 const newSet = new Set(prev);
99 if (newSet.has(nodeId)) {
100 newSet.delete(nodeId);
101// … truncated

Files it writes

  • components/domain-ui/tree.tsx

Facts

Registry
domain-ui
Type
registry:component
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-01
Last confirmed
today

Go to the source

domain-ui.dev teurons/domain-ui on GitHub Raw registry item This item as JSON

More from domain-ui

All 16 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
pan-inputpan-inputdomain-uiComponentsFreeno deps
pan-input-incrementalpan-input-incrementaldomain-uiComponentsFreeno deps
passport-inputpassport-inputdomain-uiComponentsFreeno deps
passport-input-incrementalpassport-input-incrementaldomain-uiComponentsFreeno deps
phone-inputphone-inputdomain-uiComponentsFree2 deps
portfolio-chartportfolio-chartdomain-uiComponentsFreeno deps
regex-inputregex-inputdomain-uiComponentsFreeno deps · 2 files
regex-input-incrementalregex-input-incrementaldomain-uiComponentsFreeno deps · 5 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex