Folder Structure

A tree-like component for displaying file and directory structures with smart file type detection and smooth animations.

Usage

The component provides an interactive way to display hierarchical file structures with automatic file type icons and expandable folders.

my-project
1import { FolderStructure } from "aviris-components";23const tree = [4  {5    name: "project-root",6    children: [7      {8        name: "src",9        children: [10          { name: "components" },11          { name: "pages" },12          { name: "styles" },13        ],14      },15      { name: "package.json" },16      { name: "README.md" },17    ],18  },19];2021export default function FolderStructureDemo() {22  return <FolderStructure tree={tree} />;23}

Customization

The component automatically detects file types and displays appropriate icons, but you can also provide custom icons for any file or folder. It supports various file extensions including code files, images, videos, and configuration files.

my-project
src
components
Button.tsx
Card.tsx
styles.css
pages
assets
package.json
README.md
1import { FolderStructure } from "aviris-components";23// Custom SVG icons as React components4function ProjectIcon(props) {5  return (6    <svg7      xmlns="http://www.w3.org/2000/svg"8      viewBox="0 0 24 24"9      fill="none"10      stroke="currentColor"11      strokeWidth="2"12      strokeLinecap="round"13      strokeLinejoin="round"14      {...props}15    >16      <path d="M3 3h18v18H3z" />17      <path d="M3 9h18" />18      <path d="M9 21V9" />19    </svg>20  );21}2223function ComponentIcon(props) {24  return (25    <svg26      xmlns="http://www.w3.org/2000/svg"27      viewBox="0 0 24 24"28      fill="none"29      stroke="currentColor"30      strokeWidth="2"31      strokeLinecap="round"32      strokeLinejoin="round"33      {...props}34    >35      <path d="M4 7v10c0 2.2 3.6 4 8 4s8-1.8 8-4V7" />36      <path d="M20 7c0 2.2-3.6 4-8 4s-8-1.8-8-4" />37      <path d="M12 3c4.4 0 8 1.8 8 4s-3.6 4-8 4-8-1.8-8-4 3.6-4 8-4" />38    </svg>39  );40}4142const customTree = [43  {44    name: "my-project",45    icon: ProjectIcon, // Custom SVG icon for root46    children: [47      {48        name: "src",49        children: [50          {51            name: "components",52            icon: ComponentIcon, // Custom SVG icon for components53            children: [54              { name: "Button.tsx" },55              { name: "Card.tsx" },56              { name: "styles.css" },57            ],58          },59          { name: "pages" },60          { name: "assets" },61        ],62      },63      { name: "package.json" },64      { name: "README.md" },65    ],66  },67];6869export default function CustomFolderStructureDemo() {70  return (71    <FolderStructure72      tree={customTree}73      className="border rounded-lg p-4 bg-muted/5"74      defaultExpanded75    />76  );77}

Custom Icons

While the component provides automatic file type detection, you can override any file or folder icon using the icon property. Icons can be custom SVG components or Lucide icons that follow the same interface.

Icon Requirements

  • Icons should be SVG components that accept standard props (size, className, stroke, etc.)
  • SVGs should use currentColor for stroke/fill to support theming
  • Icons should have a viewBox of "0 0 24 24" for consistent sizing
  • Icons are rendered at 16x16 pixels by default

Props

PropTypeDefaultDescription
treeTreeNode[]-Required. The tree data structure to display.
showIconsbooleantrueWhether to show file/folder icons.
expandablebooleantrueWhether to allow expanding/collapsing folders.
defaultExpandedbooleanfalseWhether all folders should be expanded by default.
animatebooleantrueWhether to animate folder expansion/collapse.
size"sm" | "default" | "lg""default"The size variant of the component.
variant"default" | "muted""default"The color variant of the component.
density"compact" | "default" | "comfortable""default"The spacing density between items.
classNamestring-Additional CSS classes to apply.

TreeNode Interface

PropertyTypeDescription
namestringRequired. The name of the file or folder.
childrenTreeNode[]Optional. Array of child nodes for folders.
iconLucideIconOptional icon override for the node.