New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@aiquants/directory-tree

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aiquants/directory-tree

High-performance directory tree component for React with virtual scrolling and file selection

latest
npmnpm
Version
1.15.0
Version published
Maintainers
2
Created
Source

@aiquants/directory-tree

A high-performance React directory tree component with virtualization, file selection, and theming support.

Features

  • 🚀 High Performance: Built with @aiquants/virtualscroll to handle large directory structures efficiently with O(log n) operations
  • 🌀 Ultrafast Scrolling: Inherits adaptive tap scroll circle from VirtualScroll for navigating massive datasets
  • 📁 File Selection: Interactive file selection with visual feedback and multiple selection modes
  • 🎨 Theming: Customizable line colors with external theme control support
  • ♿ Accessibility: Full keyboard navigation and screen reader support
  • 📱 Responsive: Optimized for both desktop and mobile interfaces
  • 🔧 TypeScript: Complete TypeScript support with comprehensive type definitions
  • 💾 State Persistence: Automatic localStorage persistence for expansion states
  • 🎯 Flexible Selection: Support for none, single, or multiple selection modes

Installation

npm install @aiquants/directory-tree
# or
yarn add @aiquants/directory-tree
# or
pnpm add @aiquants/directory-tree

Peer Dependencies

This package requires the following peer dependencies:

npm install react react-dom @aiquants/virtualscroll tailwind-variants tailwind-merge

Quick Start

import React from 'react';
import { DirectoryTree, useDirectoryTreeState } from '@aiquants/directory-tree';
import { useTheme } from './hooks/useTheme'; // Your theme hook
import type { DirectoryEntry } from '@aiquants/directory-tree';

const sampleData: DirectoryEntry[] = [
  {
    name: 'src',
    absolutePath: '/src',
    relativePath: 'src',
    children: [
      {
        name: 'components',
        absolutePath: '/src/components',
        relativePath: 'src/components',
        children: [
          {
            name: 'App.tsx',
            absolutePath: '/src/components/App.tsx',
            relativePath: 'src/components/App.tsx',
            children: null
          }
        ]
      }
    ]
  }
];

export default function App() {
  const { theme } = useTheme();
  const {
    toggle,
    isExpanded,
    expandMultiple,
    collapseMultiple,
    isPending
  } = useDirectoryTreeState({
    storageKey: 'my-directory-tree'
  });

  // Calculate line color based on theme
  const lineColor = theme === "dark" ? "#4A5568" : "#A0AEC0";

  const handleFileSelect = (absolutePath: string, relativePath: string) => {
    console.log(`File selected: ${absolutePath} (${relativePath})`);
  };

  return (
    <div className="h-96 w-full border rounded-lg">
      <DirectoryTree
        entries={sampleData}
        expansion={{
          toggle,
          isExpanded,
          expandMultiple,
          collapseMultiple,
          isPending
        }}
        selection={{
          onFileSelect: handleFileSelect,
          selectedPath: null
        }}
        visual={{
          lineColor,
          className: "h-full"
        }}
      />
    </div>
  );
}

API Reference

DirectoryTree Component

The main component for rendering the directory tree.

Props

PropTypeRequiredDescription
entriesDirectoryEntry[]YesArray of root directory entries to display
expansionobjectYesConfiguration for tree expansion state and behavior
selectionobjectYesConfiguration for item selection
visualobjectNoVisual customization options
virtualScrollDirectoryTreeVirtualScrollOptionsNoPass-through options for the underlying VirtualScroll component

Expansion Options (expansion)

PropTypeRequiredDefaultDescription
toggle(path: string, relativePath: string) => voidYes-Function to toggle directory expansion state
isExpanded(path: string) => booleanYes-Function to check if a directory is expanded
expandMultiple(paths: string[]) => voidYes-Function to expand multiple directories
collapseMultiple(paths: string[]) => voidYes-Function to collapse multiple directories
isPendingbooleanNofalseWhether the tree is in a pending state
alwaysExpandedbooleanNofalseIf true, all directories are always expanded
doubleClickAction'recursive' | 'toggle'No'recursive'Action on double-clicking a directory

Selection Options (selection)

PropTypeRequiredDefaultDescription
onFileSelect(absolutePath: string, relativePath: string) => voidYes-Callback function triggered when a file is selected
selectedPathstring | nullNo-The currently selected file path
mode'none' | 'single' | 'multiple'No'none'Selection mode for items
selectedItemsSet<string>No-Set of paths for currently selected items
onSelectionChange(path: string, isSelected: boolean) => voidNo-Callback when item selection changes

Visual Options (visual)

PropTypeRequiredDefaultDescription
classNamestringNo-Optional CSS class name for the container
styleReact.CSSPropertiesNo-Optional inline styles for the container
lineColorstringNo'#A0AEC0'The color of the tree lines
showTreeLinesbooleanNotrueFlag indicating whether to render tree connector lines
showExpandIconsbooleanNotrueFlag indicating whether to render directory expand icons
showDirectoryIconsbooleanNotrueFlag indicating whether to render directory type icons
showFileIconsbooleanNotrueFlag indicating whether to render file type icons
iconOverridesDirectoryTreeIconOverridesNo-Icon overrides applied globally
expandIconSizenumberNo-Size of the expand icon
removeRootIndentbooleanNofalseIf true, removes the indentation and connector lines for root-level items

Virtual Scroll Options

virtualScroll lets you customize the embedded @aiquants/virtualscroll instance without re-implementing list rendering. Every option is optional and mirrors the VirtualScroll API.

  • overscanCount: Adjust how many items render beyond the viewport for smoother scrolling (default: 10).
  • scrollBarOptions: Configure scrollbar appearance and behavior (width, thumb drag, track click, arrow buttons, tap scroll circle).
  • behaviorOptions: Configure scrolling behavior (pointer drag, keyboard navigation, inertia, wheel speed).
  • onScroll, onRangeChange, className, background, initialScrollIndex, initialScrollOffset: Hook into scroll lifecycle or provide bespoke styling.

Example:

<DirectoryTree
  {...commonProps}
  virtualScroll={{
    overscanCount: 6,
    behaviorOptions: {
      enablePointerDrag: false,
    },
    scrollBarOptions: {
      width: 14,
      tapScrollCircleOptions: {
        radius: 32
      }
    }
  }}
/>;

useDirectoryTreeState Hook

A hook for managing directory tree state with localStorage persistence.

Parameters

ParameterTypeDescription
optionsUseDirectoryTreeStatePropsConfiguration options

Options

OptionTypeDescription
initialExpandedSet<string>Initially expanded directories
storageKeystringlocalStorage key for persistence (default: 'directory-tree-state')

Returns

PropertyTypeDescription
expandedSet<string>Currently expanded directories
toggle(path: string, relativePath: string) => voidToggle directory expansion
isExpanded(path: string) => booleanCheck if directory is expanded
expand(path: string) => voidExpand a directory
collapse(path: string) => voidCollapse a directory
expandMultiple(paths: string[]) => voidExpand multiple directories
collapseMultiple(paths: string[]) => voidCollapse multiple directories
collapseAll() => voidCollapse all directories
isPendingbooleanWhether a transition is pending

DirectoryEntry Type

type DirectoryEntry = {
  name: string;
  absolutePath: string;
  relativePath: string;
  children: DirectoryEntry[] | null;
};

Styling

The component uses Tailwind CSS for styling. Make sure you have Tailwind CSS configured in your project. The component supports both light and dark themes, but theme control is managed by the calling component.

Theme Control

The lineColor prop allows you to control the tree line color based on your application's theme:

import { useTheme } from './hooks/useTheme';

function MyComponent() {
  const { theme } = useTheme();

  // Calculate line color based on theme
  const lineColor = theme === "dark" ? "#4A5568" : "#A0AEC0";

  return (
    <DirectoryTree
      // ... other props
      visual={{
        lineColor: lineColor
      }}
    />
  );
}

Custom Styling

You can customize the appearance by overriding the default Tailwind classes:

<DirectoryTree
  visual={{
    className: "custom-directory-tree",
    style: { height: '400px' }
  }}
  // ... other props
/>
.custom-directory-tree {
  /* Your custom styles */
}

Advanced Usage

Large Datasets

The component is optimized for large datasets through virtualization:

import { DirectoryTree } from '@aiquants/directory-tree';

// Handle thousands of entries efficiently
<DirectoryTree
  entries={largeDataset}
  // ... other required props
  visual={{
    style: { height: '600px' }
  }}
/>

Multiple Selection Mode

Enable multiple selection for batch operations:

const [selectedItems, setSelectedItems] = useState(new Set<string>());

const handleSelectionChange = (path: string, isSelected: boolean) => {
  setSelectedItems(prev => {
    const newSet = new Set(prev);
    if (isSelected) {
      newSet.add(path);
    } else {
      newSet.delete(path);
    }
    return newSet;
  });
};

<DirectoryTree
  // ... other props
  selection={{
    mode: "multiple",
    selectedItems: selectedItems,
    onSelectionChange: handleSelectionChange,
    onFileSelect: handleFileSelect // Required prop
  }}
/>

Custom Double-Click Behavior

Control how directories behave on double-click:

<DirectoryTree
  // ... other props
  expansion={{
    // ... required expansion props
    doubleClickAction: "toggle" // Only toggle the clicked directory
    // or
    doubleClickAction: "recursive" // Expand/collapse all children (default)
  }}
/>

State Persistence

The useDirectoryTreeState hook automatically persists expansion state to localStorage:

const { toggle, isExpanded, expandMultiple, collapseMultiple } = useDirectoryTreeState({
  storageKey: 'myapp-directory-tree',
  initialExpanded: new Set(['/src', '/docs'])
});

TypeScript Support

This package is written in TypeScript and provides comprehensive type definitions. All components and hooks are fully typed for the best development experience.

Contributing

We welcome contributions! Please feel free to submit issues and pull requests.

License

MIT License - see the LICENSE file for details.

Author

Made with ❤️ by the AIQuants team.

Keywords

react

FAQs

Package last updated on 12 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts