Docs
Code Folder
Code Folder
A component that displays a file and folder structure in a collapsible tree view, wrapped in a card.
Installation
Install the following dependencies:
npm install framer-motion lucide-reactCopy and paste the cn util code into your project.
import { ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Update tailwind.config.js
Add the following animations to your tailwind.config.js file:
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
color: {
panel: {
background: "hsl(var(--background))",
border: "hsl(var(--border))",
},
},
},
},
}Copy and paste the Generate Text code into your project.
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | DirectoryItem[] | "undefined" | An array of directory items to render in the tree view. |
className | string | undefined | Additional CSS classes to apply to the inner div of the card. |
containerClassName | string | undefined | Additional CSS classes to apply to the root element of the card. |
id | string | undefined | An ID for the root card element, useful for linking or :target styling. |
Data Structure (DirectoryItem)
The data prop must be an array of objects, where each object conforms to the DirectoryItem type.
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | "undefined" | Required. The name of the file or folder. |
githubUrl | string | undefined | An optional URL. If provided, a link icon will appear on hover. |
isLocked | boolean | undefined | If true, the folder cannot be expanded and shows a lock icon. |
children | DirectoryItem[] | undefined | An optional array of child items to create a nested folder structure. |
Usage
import CodeFloder from "@/components/ui/code-floder";
// Define your directory structure
const myProjectData = [
{
name: "my-awesome-app",
githubUrl: "https://github.com/user/my-awesome-app",
children: [
{
name: "src",
children: [
{ name: "components", children: [{ name: "Button.tsx" }] },
{ name: "app", children: [{ name: "page.tsx" }] },
]
},
{ name: "node_modules", isLocked: true },
{ name: "package.json" },
],
},
];
export default function MyPage() {
return (
<CodeFloder
data={myProjectData}
containerClassName="w-full max-w-md"
/>
);
}