tree
domain-ui/treeFreeComponent
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.jsonSource
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";1516type 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};2829const TreeContext = createContext<TreeContextType | undefined>(undefined);3031const 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};3839type TreeNodeContextType = {40 nodeId: string;41 level: number;42 isLast: boolean;43 parentPath: boolean[];44};4546const TreeNodeContext = createContext<TreeNodeContextType | undefined>(47 undefined48);4950const 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};5758export 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};7172export 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 );9192 const isControlled =93 selectedIds !== undefined && onSelectionChange !== undefined;94 const currentSelectedIds = isControlled ? selectedIds : internalSelectedIds;9596 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
More from domain-ui
All 16 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| pan-inputpan-input | domain-ui | Components | Free | no deps | |
| pan-input-incrementalpan-input-incremental | domain-ui | Components | Free | no deps | |
| passport-inputpassport-input | domain-ui | Components | Free | no deps | |
| passport-input-incrementalpassport-input-incremental | domain-ui | Components | Free | no deps | |
| phone-inputphone-input | domain-ui | Components | Free | 2 deps | |
| portfolio-chartportfolio-chart | domain-ui | Components | Free | no deps | |
| regex-inputregex-input | domain-ui | Components | Free | no deps · 2 files | |
| regex-input-incrementalregex-input-incremental | domain-ui | Components | Free | no deps · 5 files |
