File Tree
unlumen-ui/file-treeFreeComponent
Animated file-tree component with animated hover highlight, spring folder expand/collapse, and automatic file-type icons.
Live preview
live · rendered by the registry
Rendered by Unlumen Ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.unlumen.com/r/file-tree.jsonSource
1"use client";23import * as React from "react";4import {5 Folder,6 FolderOpen,7 File,8 FileText,9 FileCode,10 FileJson,11 FileImage,12 FileCog,13} from "lucide-react";14import { AnimatePresence, motion } from "motion/react";15import { cn } from "@/lib/utils";1617// ─── Types ─────────────────────────────────────────────────────────────────────1819export type FileTreeElement = {20 id: string;21 name: string;22 /** Omit or set to "file" for a leaf node; "folder" renders a collapsible branch. */23 type?: "folder" | "file";24 children?: FileTreeElement[];25 /** Custom icon component (receives a `className` prop). */26 icon?: React.ComponentType<{ className?: string }>;27 /** Pink-tints the item to mark it as newly added / relevant. */28 highlight?: boolean;29 /** Whether this folder starts expanded. */30 defaultOpen?: boolean;31};3233// ─── Context ───────────────────────────────────────────────────────────────────3435type FileTreeCtx = {36 highlightColor: string;37 indentSize: number;38 showIcons: boolean;39 defaultOpenIds: Set<string>;40 containerRef: React.RefObject<HTMLDivElement | null>;41 highlightBounds: HighlightBounds | null;42 setHighlightBounds: React.Dispatch<43 React.SetStateAction<HighlightBounds | null>44 >;45};4647type HighlightBounds = {48 top: number;49 left: number;50 width: number;51 height: number;52};5354const FileTreeContext = React.createContext<FileTreeCtx | null>(null);5556function useFileTree() {57 const context = React.useContext(FileTreeContext);58 if (!context) {59 throw new Error("File tree components must be used within <FileTree />");60 }61 return context;62}6364type FolderCtx = {65 isOpen: boolean;66 toggle: () => void;67};6869const FolderContext = React.createContext<FolderCtx | null>(null);7071function useFolder() {72 const context = React.useContext(FolderContext);73 if (!context) {74 throw new Error("Folder components must be used within a folder item");75 }76 return context;77}7879// ─── Icon resolution ───────────────────────────────────────────────────────────8081// … truncated
What it pulls in
npm packages
Files it writes
More from Unlumen Ui
All 233 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AI Chatai-chat | Unlumen Ui | Components | Paid | 2 deps | |
| Vercel Animate Countanimate-count | Unlumen Ui | Components | Free | 1 dep | |
| Animate Digitsanimate-digits | Unlumen Ui | Components | Free | 1 dep | |
| Animated Inputanimate-text-input-typing | Unlumen Ui | Components | Paid | 1 dep | |
| Animated Listanimated-list | Unlumen Ui | Components | Free | 1 dep | |
| Apple Switchapple-switch | Unlumen Ui | Components | Free | 1 dep | |
| Aurora Barsaurora-bars | Unlumen Ui | Components | Free | 1 dep | |
| Aurora Bluraurora-blur | Unlumen Ui | Components | Free | 2 deps |
