UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: add file tree component
Dillion Vermaafb078321079
diff --git a/components/ui/popover.tsx b/components/ui/popover.tsxnew file mode 100644index 00000000..29c7bd2a--- /dev/null+++ b/components/ui/popover.tsx@@ -0,0 +1,33 @@+"use client"++import * as React from "react"+import * as PopoverPrimitive from "@radix-ui/react-popover"++import { cn } from "@/lib/utils"++const Popover = PopoverPrimitive.Root++const PopoverTrigger = PopoverPrimitive.Trigger++const PopoverAnchor = PopoverPrimitive.Anchor++const PopoverContent = React.forwardRef<+ React.ElementRef<typeof PopoverPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>+>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (+ <PopoverPrimitive.Portal>+ <PopoverPrimitive.Content+ ref={ref}+ align={align}+ sideOffset={sideOffset}+ className={cn(+ "z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",+ className+ )}+ {...props}+ />+ </PopoverPrimitive.Portal>+))+PopoverContent.displayName = PopoverPrimitive.Content.displayName++export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }diff --git a/config/docs.ts b/config/docs.tsindex b8a5bda3..16bce723 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -158,11 +158,6 @@ export const docsConfig: DocsConfig = {href: `/docs/components/animated-beam`,items: [],},- // {- // title: "Animated Lines",- // href: `/docs/components/animated-lines`,- // items: [],- // },{title: "Border Beam",href: `/docs/components/border-beam`,@@ -194,12 +189,23 @@ export const docsConfig: DocsConfig = {title: "Confetti",href: `/docs/components/confetti`,items: [],- label: "New",+ label: "",},{title: "Particles",href: `/docs/components/particles`,items: [],+ label: "",+ },+ ],+ },+ {+ title: "Dev",+ items: [+ {+ title: "File Tree",+ href: `/docs/components/file-tree`,+ items: [],label: "New",},],@@ -311,13 +317,13 @@ export const docsConfig: DocsConfig = {title: "Sparkles Text",href: `/docs/components/sparkles-text`,items: [],- label: "New",+ label: "",},{title: "Cool Mode",href: `/docs/components/cool-mode`,items: [],- label: "New",+ label: "",},],},@@ -339,7 +345,7 @@ export const docsConfig: DocsConfig = {title: "Animated Subscribe Button",href: `/docs/components/animated-subscribe-button`,items: [],- label: "New",+ label: "",},],},@@ -386,7 +392,7 @@ export const docsConfig: DocsConfig = {title: "Wavy Dot Pattern",href: `/docs/components/wavy-dot-pattern`,items: [],- label: "New",+ label: "",},],},diff --git a/content/docs/components/file-tree.mdx b/content/docs/components/file-tree.mdxnew file mode 100644index 00000000..102849e0--- /dev/null+++ b/content/docs/components/file-tree.mdx@@ -0,0 +1,80 @@+---+title: File Tree+date: 2023-07-20+description: A component used to showcase the folder and file structure of a directory.+author: dillionverma+published: true+---++<ComponentPreview name="file-tree-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx magicui-cli add file-tree+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="file-tree" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Props++### Tree++| Prop | Type | Default | Description |+| ---------------------- | ------------------- | ------- | ------------------------------------------------------------ |+| `initialSelectedId` | `string` | - | The ID of the initially selected item. |+| `indicator` | `boolean` | `true` | Whether to show the tree indicator line. |+| `elements` | `TreeViewElement[]` | - | An array of tree view elements to render. |+| `initialExpandedItems` | `string[]` | - | An array of IDs for items that should be initially expanded. |+| `openIcon` | `React.ReactNode` | - | Custom icon for open folders. |+| `closeIcon` | `React.ReactNode` | - | Custom icon for closed folders. |+| `dir` | `"rtl" \| "ltr"` | `"ltr"` | The text direction of the tree. |++### Folder++| Prop | Type | Default | Description |+| -------------- | --------- | ------- | ----------------------------------------- |+| `element` | `string` | - | The name of the folder. |+| `value` | `string` | - | The unique identifier for the folder. |+| `isSelectable` | `boolean` | `true` | Whether the folder can be selected. |+| `isSelect` | `boolean` | - | Whether the folder is currently selected. |++### File++| Prop | Type | Default | Description |+| -------------- | ----------------- | ------- | --------------------------------------- |+| `value` | `string` | - | The unique identifier for the file. |+| `isSelectable` | `boolean` | `true` | Whether the file can be selected. |+| `isSelect` | `boolean` | - | Whether the file is currently selected. |+| `fileIcon` | `React.ReactNode` | - | Custom icon for the file. |++### CollapseButton++| Prop | Type | Default | Description |+| ----------- | ------------------- | ------- | ------------------------------------------ |+| `elements` | `TreeViewElement[]` | - | An array of tree view elements to control. |+| `expandAll` | `boolean` | `false` | Whether to expand all elements initially. |diff --git a/package.json b/package.jsonindex 8b69cac8..41c00966 100644--- a/package.json+++ b/package.json@@ -32,6 +32,7 @@"@radix-ui/react-hover-card": "^1.0.7","@radix-ui/react-icons": "^1.3.0","@radix-ui/react-label": "^2.0.2",+ "@radix-ui/react-popover": "^1.1.1","@radix-ui/react-scroll-area": "^1.0.5","@radix-ui/react-separator": "^1.0.3","@radix-ui/react-slot": "^1.0.2",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 256fc96d..f5ac08ad 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -38,6 +38,9 @@ importers:'@radix-ui/react-label':specifier: ^2.0.2version: 2.0.2(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-popover':+ specifier: ^1.1.1+ version: 1.1.1(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])'@radix-ui/react-scroll-area':specifier: ^1.0.5version: 1.0.5(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])@@ -1679,6 +1682,9 @@ packages:'@radix-ui/[email protected]':resolution: {integrity: sha512-yQ8oGX2GVsEYMWGxcovu1uGWPCxV5BFfeeYxqPmuAzUyLT9qmaMXSAhXpb0WrspIeqYzdJpkh2vHModJPgRIaw==}+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-4Z8dn6Upk0qk4P74xBhZ6Hd/w0mPEzOOLxy4xiPXOXqjF7jZS0VAKk7/x/H6FyY2zCkYJqePf1G5KmkmNJ4RBA==}+'@radix-ui/[email protected]':resolution: {integrity: sha512-fDG7jcoNKVjSK6yfmuAs0EnPDro0WMXIhMtXdTBWqEioVW206ku+4Lw07e+13lUkFkpoEQ2PdeMIAGpdqEAmDg==}peerDependencies:@@ -1718,6 +1724,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-FmlW1rCg7hBpEBwFbjHwCW6AmWLQM6g/v0Sn8XbP9NvmSZ2San1FpQeyPtufzOMSIx7Y4dzjlHoifhp+7NkZhw==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-kVK2K7ZD3wwj3qhle0ElXhOjbezIgyl2hVvgwfIdexL3rN6zJmy5AqqIf+D31lxVppdzV8CjAfZ6PklkmInZLw==}peerDependencies:@@ -1771,6 +1790,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-b4inOtiaOnYf9KWyO3jAeeCG6FeyfY6ldiEPanbUjWd+xIk5wZeHa8yVwmrJ2vderhu/BQvzCrJI0lHd+wIiqw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-1pVM9RfOQ+n/N5PJK33kRSKsr1glNxomxONs5c49MliinBY6Yw2Q995qfBUUo0/Mbg05B/sGA0gkgPI7kmSHBg==}peerDependencies:@@ -1785,6 +1813,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-OKrckBy+sMEgYM/sMmqmErVn0kZqrHPJze+Ql3DzYsDDp0hl0L62nx/2122/Bvps1qz645jlcu2tD9lrRSdf8A==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-Yn9YU+QlHYLWwV1XfKiqnGVpWYWk6MeBVM6x/bcoyPvxgjQGoeT35482viLPctTMWoMw0PoHgqfSox7Ig+957Q==}peerDependencies:@@ -1832,6 +1869,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-/UovfmmXGptwGcBQawLzvn2jOfM0t4z3/uKffoBlj724+n3FvBbZ7M0aaBOmkp6pqFYpO4yx8tSVJjx3Fl2jig==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-i6TuFOoWmLWq+M/eCLGd/bQ2HfAX1RJgvrBQ6AQLmzfvsLdefxbWu8G9zczcPFfcSPehz9GcpF6K9QYreFV8hA==}peerDependencies:@@ -1859,6 +1909,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-w6XZNUPVv6xCpZUqb/yN9DL6auvpGX3C/ee6Hdi16v2UUy25HV2Q5bcflsiDyT/g5RwbPQ/GIT1vLkeRb+ITBw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-C4SWtsULLGf/2L4oGeIHlvWQx7Rf+7cX/vKOAD2dXW0A1b5QXwi3wWeaEgW+wn+SEVrraMUk05vLU9fZZz5HbQ==}peerDependencies:@@ -1878,6 +1937,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-200UD8zylvEyL8Bx+z76RJnASR2gRMuxlgFCPAe/Q/679a/r0eK3MBVYMb7vZODZcffZBdob1EGnky78xmVvcA==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-OcUN2FU0YpmajD/qkph3XzMcK/NmSk9hGWnjV68p6QiZMgILugusgQwnLSDs3oFSJYGKf3Y49zgFedhGh04k9A==}peerDependencies:@@ -1910,6 +1982,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-EJUrI8yYh7WOjNOqpoJaf1jlFIH2LvtgAl+YcFqNCa+4hj64ZXmPkAKOFs/ukjz3byN6bdb/AVUqHkI8/uWWMA==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-N5ehvlM7qoTLx7nWPodsPYPgMzA5WM8zZChQg8nyFJKnDO5WHdba1vv5/H6IO5LtJMfD2Q3wh1qHFGNtK0w3bQ==}peerDependencies:@@ -1936,6 +2017,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-3y1A3isulwnWhvTTwmIreiB8CF4L+qRjZnK1wYLO7pplddzXKby/GnZ2M7OZY3qgnl6p9AodUIHRYGXNah8Y7g==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-cKpopj/5RHZWjrbF2846jBNacjQVwkP068DfmgrNJXpvVWrOvlAmE9xSiy5OqeE+Gi8D9fP+oDhUnPqNMY8/5w==}peerDependencies:@@ -1949,6 +2043,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-ZnRMshKF43aBxVWPWvbj21+7TQCvhuULWJ4gNIKYpRlQt5xGRhLx66tMp8pya2UkGHTSlhpXwmjqltDYHhw7Vg==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-a8qyFO/Xb99d8wQdu4o7qnigNjTPG123uADNecz0eX4usnQEj7o+cG4ZX4zkqq98NYekT7UoEQIjxBNWIFuqTA==}peerDependencies:@@ -1968,6 +2075,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-A3UtLk85UtqhzFqtoC8Q0KvR2GbXF3mtPgACSazajqq6A41mEQgo53iPzY4i6BwDxlIFqWIhiQ2G729n+2aw/g==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-A+6XEvN01NfVWiKu38ybawfHsBjWum42MRPnEuqPsBZ4eV7e/7K321B5VgYMPv3Xx5An6o1/l9ZuDBgmcmWK3w==}peerDependencies:@@ -1987,6 +2107,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-Gq6wuRN/asf9H/E/VzdKoUtT8GC9PQc9z40/vEr0VCJ4u5XvvhWIrSsCB6vD2/cH7ugTdSfYq9fLJCcM00acrQ==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-EyXe6mnRlHZ8b6f4ilTDrXmkLShICIuOTTj0GX4w1rp+wSxf3+TD05u1UOITC8VsJ2a9nwHvdXtOXEOl0Cw/zQ==}peerDependencies:@@ -2006,6 +2139,19 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-ZSpFm0/uHa8zTvKBDjLFWLo8dkr4MBsiDLz0g3gMUwqgLHz9rTaRRGYDgvZPtBJgYCBKXkS9fzmoySgr8CO6Cw==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-2mUg5Mgcu001VkGy+FfzZyzbmuUWzgWkj3rvv4yu+mLw03+mTzbxZHvfcGyFp2b8EkQeMkpRQ5FiA2Vr2O6TeQ==}peerDependencies:@@ -2059,6 +2205,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-FUCf5XMfmW4dtYl69pdS4DbxKy8nj4M7SafBgPllysxmdachynNflAdp/gCsnYWNDnge6tI9onzMp5ARYc1KNw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-mxm87F88HyHztsI7N+ZUmEoARGkC22YVW5CaC+Byc+HRpuvCrOBPTAnXgf+tZ/7i0Sg/eOePGdMhUKhPaQEqow==}peerDependencies:@@ -2125,6 +2280,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-CasTfvsy+frcFkbXtSJ2Zu9JHpN8TYKxkgJGWbjiZhFivxaeW7rMeZt7QELGVLaYVfFMsKHjb7Ak0nMEe+2Vfw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-FohDoZvk3mEXh9AWAVyRTYR4Sq7/gavuofglmiXB2g1aKyboUD4YtgWxKj8O5n+Uak52gXQ4wKz5IFST4vtJHg==}peerDependencies:@@ -2139,6 +2303,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-MtfMVJiSr2NjzS0Aa90NPTnvTSg6C/JLCV7ma0W6+OMV78vd8OyRpID+Ng9LxzsPbLeuBnWBA1Nq30AtBIDChw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-JwfBCUIfhXRxKExgIqGa4CQsiMemo1Xt0W/B4ei3fpzpvPENKpMKQ8mZSB6Acj3ebrAEgi2xiQvcI1PAAodvyg==}peerDependencies:@@ -2153,6 +2326,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-L7vwWlR1kTTQ3oh7g1O0CBF3YCyyTj8NmhLR+phShpyA50HCfBFKVJTpshm9PzLiKmehsrQzTYTpX9HvmC9rhw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-6Tpkq+R6LOlmQb1R5NNETLG0B4YP0wc+klfXafpUCj6JGyaUc8il7/kUZ7m59rGbXGczE9Bs+iz2qloqsZBduQ==}peerDependencies:@@ -2167,6 +2349,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-+FPE0rOdziWSrH9athwI1R0HDVbWlEhd+FR+aSDk4uWGmSJ9Z54sdZVDQPZAinJhJXwfT+qnj969mCsT2gfm5w==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-cV5La9DPwiQ7S0gf/0qiD6YgNqM5Fk97Kdrlc5yBcrF3jyEZQwm7vYFqMo4IfeHgJXsRaMvLABFtd0OVEmZhDw==}peerDependencies:@@ -2185,6 +2376,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-0Fmkebhr6PiseyZlYAOtLS+nb7jLmpqTrJyv61Pe68MKYW6OWdRE2kI70TaYY27u7H0lajqM3hSMMLFq18Z7nQ==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-ibay+VqrgcaI6veAojjofPATwledXiSmX+C0KrBk/xgpX9rBzPV3OsfwlhQdUOFbh+LKQorLYT+xTXW9V8yd0g==}peerDependencies:@@ -2194,6 +2394,15 @@ packages:'@types/react':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-XW3/vWuIXHa+2Uwcc2ABSfcCledmXhhQPlGbfcRXbiUQI5Icjcg19BGCZVKKInYbvUCut/ufbbLLPFC5cbb1hw==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-D4w41yN5YRKtu464TLnByKzMDG/JlMPHtfZgQAu9v6mNakUqGUI9vUrfQKz8NK41VMm/xbZbh76NUTVtIYqOMA==}peerDependencies:@@ -2210,6 +2419,9 @@ packages:'@radix-ui/[email protected]':resolution: {integrity: sha512-fyrgCaedtvMg9NK3en0pnOYJdtfwxUcNolezkNPUsoX57X8oQk+NkqcvzHXD2uKNij6GXmWU9NDru2IWjrO4BQ==}+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==}+'@react-native-community/[email protected]':resolution: {integrity: sha512-gUU29ep8xM0BbnZjwz9MyID74KKwutq9x5iv4BCr2im6nly4UMf1B1D+V225wR7VcDGzbgWjaezsJShLLhC5ig==}@@ -5641,6 +5853,16 @@ packages:'@types/react':optional: true+ resolution: {integrity: sha512-FnrTWO4L7/Bhhf3CYBNArEG/yROV0tKmTv7/3h9QCFvH6sndeFf1wPqOcbFVu5VAulS5dV1wGT3GZZ/1GawqiA==}+ engines: {node: '>=10'}+ peerDependencies:+ '@types/react': ^16.8.0 || ^17.0.0 || ^18.0.0+ react: ^16.8.0 || ^17.0.0 || ^18.0.0+ peerDependenciesMeta:+ '@types/react':+ optional: true+resolution: {integrity: sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA==}peerDependencies:@@ -8332,6 +8554,8 @@ snapshots:dependencies:'@babel/runtime': 7.24.0+ '@radix-ui/[email protected]': {}+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8375,6 +8599,15 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8430,6 +8663,12 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected]([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8442,6 +8681,12 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected](@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8519,6 +8764,19 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/primitive': 1.1.0+ '@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-use-callback-ref': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-escape-keydown': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8547,6 +8805,12 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+dependencies:'@babel/runtime': 7.24.0@@ -8568,6 +8832,17 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-use-callback-ref': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8604,6 +8879,13 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ '@radix-ui/react-use-layout-effect': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8641,6 +8923,29 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/primitive': 1.1.0+ '@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-dismissable-layer': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-focus-guards': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-focus-scope': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-id': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-popper': 1.2.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-portal': 1.1.1(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-presence': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-slot': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-controllable-state': 1.1.0(@types/[email protected])([email protected])+ aria-hidden: 1.2.3+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ react-remove-scroll: 2.5.7(@types/[email protected])([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8660,6 +8965,24 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-arrow': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-use-callback-ref': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-layout-effect': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-rect': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-size': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/rect': 1.1.0+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+dependencies:'@babel/runtime': 7.24.0@@ -8677,6 +9000,16 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-use-layout-effect': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+dependencies:'@babel/runtime': 7.24.0@@ -8696,6 +9029,16 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-layout-effect': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+dependencies:'@babel/runtime': 7.24.0@@ -8713,6 +9056,15 @@ snapshots:'@types/react': 18.2.12'@types/react-dom': 18.2.5+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-slot': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+ '@types/react-dom': 18.2.5+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8773,6 +9125,13 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ '@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8860,6 +9219,12 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected]([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8874,6 +9239,13 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ '@radix-ui/react-use-callback-ref': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected]([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8888,6 +9260,13 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ '@radix-ui/react-use-callback-ref': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected]([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8900,6 +9279,12 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+dependencies:'@babel/runtime': 7.24.0@@ -8915,6 +9300,13 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ '@radix-ui/rect': 1.1.0+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+dependencies:'@babel/runtime': 7.24.0@@ -8923,6 +9315,13 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ '@radix-ui/react-use-layout-effect': 1.1.0(@types/[email protected])([email protected])+ react: 18.2.0+ optionalDependencies:+ '@types/react': 18.2.12+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@babel/runtime': 7.24.0@@ -8937,6 +9336,8 @@ snapshots:dependencies:'@babel/runtime': 7.24.0+ '@radix-ui/[email protected]': {}+'@react-native-community/[email protected]':dependencies:'@react-native-community/cli-tools': 12.3.6@@ -13194,6 +13595,17 @@ snapshots:optionalDependencies:'@types/react': 18.2.12+ dependencies:+ react: 18.2.0+ react-remove-scroll-bar: 2.3.5(@types/[email protected])([email protected])+ react-style-singleton: 2.2.1(@types/[email protected])([email protected])+ tslib: 2.6.2+ use-callback-ref: 1.3.1(@types/[email protected])([email protected])+ use-sidecar: 1.1.2(@types/[email protected])([email protected])+ optionalDependencies:+ '@types/react': 18.2.12+dependencies:object-assign: 4.1.1diff --git a/registry/components/example/file-tree-demo.tsx b/registry/components/example/file-tree-demo.tsxnew file mode 100644index 00000000..be760c1e--- /dev/null+++ b/registry/components/example/file-tree-demo.tsx@@ -0,0 +1,111 @@+import { File, Folder, Tree } from "@/components/magicui/file-tree";++export default function FileTreeDemo() {+ return (+ <div className="relative flex h-[300px] w-1/2 flex-col items-center justify-center overflow-hidden rounded-lg border bg-background md:shadow-xl">+ <Tree+ className="p-2 overflow-hidden rounded-md bg-background"+ initialSelectedId="7"+ initialExpandedItems={[+ "1",+ "2",+ "3",+ "4",+ "5",+ "6",+ "7",+ "8",+ "9",+ "10",+ "11",+ ]}+ elements={ELEMENTS}+ >+ <Folder element="src" value="1">+ <Folder value="2" element="app">+ <File value="3">+ <p>layout.tsx</p>+ </File>+ <File value="4">+ <p>page.tsx</p>+ </File>+ </Folder>+ <Folder value="5" element="components">+ <Folder value="6" element="ui">+ <File value="7">+ <p>button.tsx</p>+ </File>+ </Folder>+ <File value="8">+ <p>header.tsx</p>+ </File>+ <File value="9">+ <p>footer.tsx</p>+ </File>+ </Folder>+ <Folder value="10" element="lib">+ <File value="11">+ <p>utils.ts</p>+ </File>+ </Folder>+ </Folder>+ </Tree>+ </div>+ );+}++const ELEMENTS = [+ {+ id: "1",+ isSelectable: true,+ name: "src",+ children: [+ {+ id: "2",+ isSelectable: true,+ name: "app",+ children: [+ {+ id: "3",+ isSelectable: true,+ name: "layout.tsx",+ },+ {+ id: "4",+ isSelectable: true,+ name: "page.tsx",+ },+ ],+ },+ {+ id: "5",+ isSelectable: true,+ name: "components",+ children: [+ {+ id: "6",+ isSelectable: true,+ name: "header.tsx",+ },+ {+ id: "7",+ isSelectable: true,+ name: "footer.tsx",+ },+ ],+ },+ {+ id: "8",+ isSelectable: true,+ name: "lib",+ children: [+ {+ id: "9",+ isSelectable: true,+ name: "utils.ts",+ },+ ],+ },+ ],+ },+];diff --git a/registry/components/magicui/file-tree.tsx b/registry/components/magicui/file-tree.tsxnew file mode 100644index 00000000..06734286--- /dev/null+++ b/registry/components/magicui/file-tree.tsx@@ -0,0 +1,391 @@+"use client";++import React, {+ createContext,+ forwardRef,+ useCallback,+ useContext,+ useEffect,+ useState,+} from "react";+import * as AccordionPrimitive from "@radix-ui/react-accordion";+import { FileIcon, FolderIcon, FolderOpenIcon } from "lucide-react";++import { cn } from "@/lib/utils";+import { Button } from "@/components/ui/button";+import { ScrollArea } from "@/components/ui/scroll-area";++type TreeViewElement = {+ id: string;+ name: string;+ isSelectable?: boolean;+ children?: TreeViewElement[];+};++type TreeContextProps = {+ selectedId: string | undefined;+ expandedItems: string[] | undefined;+ indicator: boolean;+ handleExpand: (id: string) => void;+ selectItem: (id: string) => void;+ setExpandedItems?: React.Dispatch<React.SetStateAction<string[] | undefined>>;+ openIcon?: React.ReactNode;+ closeIcon?: React.ReactNode;+ direction: "rtl" | "ltr";+};++const TreeContext = createContext<TreeContextProps | null>(null);++const useTree = () => {+ const context = useContext(TreeContext);+ if (!context) {+ throw new Error("useTree must be used within a TreeProvider");+ }+ return context;+};++interface TreeViewComponentProps extends React.HTMLAttributes<HTMLDivElement> {}++type Direction = "rtl" | "ltr" | undefined;++type TreeViewProps = {+ initialSelectedId?: string;+ indicator?: boolean;+ elements?: TreeViewElement[];+ initialExpandedItems?: string[];+ openIcon?: React.ReactNode;+ closeIcon?: React.ReactNode;+} & TreeViewComponentProps;++const Tree = forwardRef<HTMLDivElement, TreeViewProps>(+ (+ {+ className,+ elements,+ initialSelectedId,+ initialExpandedItems,+ children,+ indicator = true,+ openIcon,+ closeIcon,+ dir,+ ...props+ },+ ref,+ ) => {+ const [selectedId, setSelectedId] = useState<string | undefined>(+ initialSelectedId,+ );+ const [expandedItems, setExpandedItems] = useState<string[] | undefined>(+ initialExpandedItems,+ );++ const selectItem = useCallback((id: string) => {+ setSelectedId(id);+ }, []);++ const handleExpand = useCallback((id: string) => {+ setExpandedItems((prev) => {+ if (prev?.includes(id)) {+ return prev.filter((item) => item !== id);+ }+ return [...(prev ?? []), id];+ });+ }, []);++ const expandSpecificTargetedElements = useCallback(+ (elements?: TreeViewElement[], selectId?: string) => {+ if (!elements || !selectId) return;+ const findParent = (+ currentElement: TreeViewElement,+ currentPath: string[] = [],+ ) => {+ const isSelectable = currentElement.isSelectable ?? true;+ const newPath = [...currentPath, currentElement.id];+ if (currentElement.id === selectId) {+ if (isSelectable) {+ setExpandedItems((prev) => [...(prev ?? []), ...newPath]);+ } else {+ if (newPath.includes(currentElement.id)) {+ newPath.pop();+ setExpandedItems((prev) => [...(prev ?? []), ...newPath]);+ }+ }+ return;+ }+ if (+ isSelectable &&+ currentElement.children &&+ currentElement.children.length > 0+ ) {+ currentElement.children.forEach((child) => {+ findParent(child, newPath);+ });+ }+ };+ elements.forEach((element) => {+ findParent(element);+ });+ },+ [],+ );++ useEffect(() => {+ if (initialSelectedId) {+ expandSpecificTargetedElements(elements, initialSelectedId);+ }+ }, [initialSelectedId, elements]);++ const direction = dir === "rtl" ? "rtl" : "ltr";++ return (+ <TreeContext.Provider+ value={{+ selectedId,+ expandedItems,+ handleExpand,+ selectItem,+ setExpandedItems,+ indicator,+ openIcon,+ closeIcon,+ direction,+ }}+ >+ <div className={cn("size-full", className)}>+ <ScrollArea+ ref={ref}+ className="h-full relative px-2"+ dir={dir as Direction}+ >+ <AccordionPrimitive.Root+ {...props}+ type="multiple"+ defaultValue={expandedItems}+ value={expandedItems}+ className="flex flex-col gap-1"+ onValueChange={(value) =>+ setExpandedItems((prev) => [...(prev ?? []), value[0]])+ }+ dir={dir as Direction}+ >+ {children}+ </AccordionPrimitive.Root>+ </ScrollArea>+ </div>+ </TreeContext.Provider>+ );+ },+);++Tree.displayName = "Tree";++const TreeIndicator = forwardRef<+ HTMLDivElement,+ React.HTMLAttributes<HTMLDivElement>+>(({ className, ...props }, ref) => {+ const { direction } = useTree();++ return (+ <div+ dir={direction}+ ref={ref}+ className={cn(+ "h-full w-px bg-muted absolute left-1.5 rtl:right-1.5 py-3 rounded-md hover:bg-slate-300 duration-300 ease-in-out",+ className,+ )}+ {...props}+ />+ );+});++TreeIndicator.displayName = "TreeIndicator";++interface FolderComponentProps+ extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> {}++type FolderProps = {+ expandedItems?: string[];+ element: string;+ isSelectable?: boolean;+ isSelect?: boolean;+} & FolderComponentProps;++const Folder = forwardRef<+ HTMLDivElement,+ FolderProps & React.HTMLAttributes<HTMLDivElement>+>(+ (+ {+ className,+ element,+ value,+ isSelectable = true,+ isSelect,+ children,+ ...props+ },+ ref,+ ) => {+ const {+ direction,+ handleExpand,+ expandedItems,+ indicator,+ setExpandedItems,+ openIcon,+ closeIcon,+ } = useTree();++ return (+ <AccordionPrimitive.Item+ {...props}+ value={value}+ className="relative overflow-hidden h-full "+ >+ <AccordionPrimitive.Trigger+ className={cn(+ `flex items-center gap-1 text-sm rounded-md`,+ className,+ {+ "bg-muted rounded-md": isSelect && isSelectable,+ "cursor-pointer": isSelectable,+ "cursor-not-allowed opacity-50": !isSelectable,+ },+ )}+ disabled={!isSelectable}+ onClick={() => handleExpand(value)}+ >+ {expandedItems?.includes(value)+ ? openIcon ?? <FolderOpenIcon className="size-4" />+ : closeIcon ?? <FolderIcon className="size-4" />}+ <span>{element}</span>+ </AccordionPrimitive.Trigger>+ <AccordionPrimitive.Content className="text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down relative overflow-hidden h-full">+ {element && indicator && <TreeIndicator aria-hidden="true" />}+ <AccordionPrimitive.Root+ dir={direction}+ type="multiple"+ className="flex flex-col gap-1 py-1 ml-5 rtl:mr-5 "+ defaultValue={expandedItems}+ value={expandedItems}+ onValueChange={(value) => {+ setExpandedItems?.((prev) => [...(prev ?? []), value[0]]);+ }}+ >+ {children}+ </AccordionPrimitive.Root>+ </AccordionPrimitive.Content>+ </AccordionPrimitive.Item>+ );+ },+);++Folder.displayName = "Folder";++const File = forwardRef<+ HTMLButtonElement,+ {+ value: string;+ handleSelect?: (id: string) => void;+ isSelectable?: boolean;+ isSelect?: boolean;+ fileIcon?: React.ReactNode;+ } & React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>+>(+ (+ {+ value,+ className,+ handleSelect,+ isSelectable = true,+ isSelect,+ fileIcon,+ children,+ ...props+ },+ ref,+ ) => {+ const { direction, selectedId, selectItem } = useTree();+ const isSelected = isSelect ?? selectedId === value;+ return (+ <AccordionPrimitive.Item value={value} className="relative">+ <AccordionPrimitive.Trigger+ ref={ref}+ {...props}+ dir={direction}+ disabled={!isSelectable}+ aria-label="File"+ className={cn(+ "flex items-center gap-1 cursor-pointer text-sm pr-1 rtl:pl-1 rtl:pr-0 rounded-md duration-200 ease-in-out",+ {+ "bg-muted": isSelected && isSelectable,+ },+ isSelectable ? "cursor-pointer" : "opacity-50 cursor-not-allowed",+ className,+ )}+ onClick={() => selectItem(value)}+ >+ {fileIcon ?? <FileIcon className="size-4" />}+ {children}+ </AccordionPrimitive.Trigger>+ </AccordionPrimitive.Item>+ );+ },+);++File.displayName = "File";++const CollapseButton = forwardRef<+ HTMLButtonElement,+ {+ elements: TreeViewElement[];+ expandAll?: boolean;+ } & React.HTMLAttributes<HTMLButtonElement>+>(({ className, elements, expandAll = false, children, ...props }, ref) => {+ const { expandedItems, setExpandedItems } = useTree();++ const expendAllTree = useCallback((elements: TreeViewElement[]) => {+ const expandTree = (element: TreeViewElement) => {+ const isSelectable = element.isSelectable ?? true;+ if (isSelectable && element.children && element.children.length > 0) {+ setExpandedItems?.((prev) => [...(prev ?? []), element.id]);+ element.children.forEach(expandTree);+ }+ };++ elements.forEach(expandTree);+ }, []);++ const closeAll = useCallback(() => {+ setExpandedItems?.([]);+ }, []);++ useEffect(() => {+ console.log(expandAll);+ if (expandAll) {+ expendAllTree(elements);+ }+ }, [expandAll]);++ return (+ <Button+ variant={"ghost"}+ className="h-8 w-fit p-1 absolute bottom-1 right-2"+ onClick={+ expandedItems && expandedItems.length > 0+ ? closeAll+ : () => expendAllTree(elements)+ }+ ref={ref}+ {...props}+ >+ {children}+ <span className="sr-only">Toggle</span>+ </Button>+ );+});++CollapseButton.displayName = "CollapseButton";++export { CollapseButton, File, Folder, Tree, type TreeViewElement };diff --git a/registry/index.tsx b/registry/index.tsxindex ea8ca852..7c60a346 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -259,6 +259,11 @@ const ui: Registry = {type: "components:magicui",files: ["registry/components/magicui/cool-mode.tsx"],},+ "file-tree": {+ name: "file-tree",+ type: "components:magicui",+ files: ["registry/components/magicui/file-tree.tsx"],+ },};const example: Registry = {@@ -923,6 +928,14 @@ const example: Registry = {() => import("@/registry/components/example/cool-mode-custom"),),},+ "file-tree-demo": {+ name: "file-tree-demo",+ type: "components:example",+ files: ["registry/components/example/file-tree-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/file-tree-demo"),+ ),+ },};export const registry: Registry = {...ui,