npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gp-tree-view

v1.0.1

Published

A powerful, feature-rich Angular tree component with expand/collapse, search, lazy loading, and selection capabilities

Downloads

44

Readme

🌳 gp-tree-view

npm version License: MIT Angular

A powerful, feature-rich Angular tree component with expand/collapse, search, lazy loading, and selection capabilities. Built with love and lots of coffee ☕

✨ Features

  • 🌳 Hierarchical Tree Structure - Display nested data in a clean, organized tree format
  • 🔍 Smart Search - Real-time search with highlighting and filtering
  • 📦 Lazy Loading - Load children on-demand for better performance
  • ☑️ Flexible Selection - Single or multiple selection with checkboxes
  • 🎨 Customizable Styling - Modern, responsive design with easy customization
  • Performance Optimized - Built with Angular's OnPush change detection
  • 🎯 TypeScript Support - Full type safety with comprehensive interfaces
  • 📱 Responsive Design - Works seamlessly on desktop and mobile devices
  • 🎮 Programmatic Control - Control tree behavior via code
  • 🛠️ Highly Configurable - Show/hide controls and customize behavior

🚀 Quick Start

Installation

npm install gp-tree-view

Basic Usage

import { NgxTreeComponent, TreeNode, TreeConfig } from 'gp-tree-view';

@Component({
  selector: 'app-example',
  imports: [NgxTreeComponent],
  template: `
    <ngx-tree
      [nodes]="treeData"
      [config]="treeConfig"
      (nodeClick)="onNodeClick($event)"
      (nodeExpand)="onNodeExpand($event)"
      (nodeSelect)="onNodeSelect($event)"
      (lazyLoad)="onLazyLoad($event)"
    ></ngx-tree>
  `
})
export class ExampleComponent {
  treeData: TreeNode[] = [
    {
      id: '1',
      label: 'My Projects',
      icon: '🚀',
      hasChildren: true,
      children: [
        { id: '1-1', label: 'Awesome Project', icon: '⭐' },
        { id: '1-2', label: 'Another Project', icon: '💎' }
      ]
    }
  ];

  treeConfig: TreeConfig = {
    showCheckboxes: true,
    showIcons: true,
    allowMultipleSelection: true,
    searchable: true,
    lazyLoad: true
  };

  onNodeClick(event: TreeNodeClickEvent) {
    console.log('Clicked:', event.node.label);
  }

  onLazyLoad(event: LazyLoadEvent) {
    // Load more data from your API
    this.apiService.getChildren(event.node.id).subscribe(children => {
      event.callback(children);
    });
  }
}

📚 API Reference

TreeNode Interface

interface TreeNode {
  id: string | number;           // Unique identifier
  label: string;                 // Display text
  children?: TreeNode[];         // Child nodes
  expanded?: boolean;            // Initial expansion state
  loading?: boolean;             // Loading state for lazy loading
  hasChildren?: boolean;         // Whether node has children
  data?: any;                    // Custom data
  icon?: string;                 // Icon (emoji, HTML, etc.)
  disabled?: boolean;            // Disable interaction
  selectable?: boolean;          // Allow selection
  selected?: boolean;            // Selection state
}

TreeConfig Interface

interface TreeConfig {
  // Basic options
  showCheckboxes?: boolean;      // Show selection checkboxes
  showIcons?: boolean;           // Show node icons
  allowMultipleSelection?: boolean; // Allow multiple selections
  searchable?: boolean;          // Enable search functionality
  searchPlaceholder?: string;    // Search input placeholder
  lazyLoad?: boolean;            // Enable lazy loading
  expandOnClick?: boolean;       // Expand nodes on click
  selectOnClick?: boolean;       // Select nodes on click
  animation?: boolean;           // Enable animations
  maxDepth?: number;             // Maximum tree depth
  
  // Control panel options
  showControls?: boolean;        // Show control panel
  showExpandAll?: boolean;       // Show expand all button
  showCollapseAll?: boolean;     // Show collapse all button
  showClearSelection?: boolean;  // Show clear selection button
}

Events

nodeClick

interface TreeNodeClickEvent {
  node: TreeNode;
  event: MouseEvent;
}

nodeExpand

interface TreeNodeExpandEvent {
  node: TreeNode;
  expanded: boolean;
}

nodeSelect

interface TreeNodeSelectEvent {
  node: TreeNode;
  selected: boolean;
  selectedNodes: TreeNode[];
}

lazyLoad

interface LazyLoadEvent {
  node: TreeNode;
  callback: (children: TreeNode[]) => void;
}

🎮 Programmatic Control

Control the tree programmatically using these methods:

// Get reference to tree component
@ViewChild(NgxTreeComponent) treeComponent!: NgxTreeComponent;

// Global controls
expandAll() {
  this.treeComponent.expandAllProgrammatically();
}

collapseAll() {
  this.treeComponent.collapseAllProgrammatically();
}

clearSelection() {
  this.treeComponent.clearSelectionProgrammatically();
}

// Specific node controls
expandNode() {
  this.treeComponent.expandNodeById('1-1');
}

selectNode() {
  this.treeComponent.selectNodeById('1-1-1');
}

// Get selected nodes
getSelected() {
  const selected = this.treeComponent.getSelectedNodes();
  console.log('Selected:', selected);
}

🎨 Customization

CSS Custom Properties

.ngx-tree-container {
  --tree-border-color: #e1e5e9;
  --tree-background: #fff;
  --tree-hover-background: #f3f4f6;
  --tree-selected-background: #dbeafe;
  --tree-selected-color: #1e40af;
}

Advanced Configuration

treeConfig: TreeConfig = {
  showCheckboxes: true,
  showIcons: true,
  allowMultipleSelection: true,
  searchable: true,
  searchPlaceholder: 'Search files...',
  lazyLoad: true,
  expandOnClick: false,
  selectOnClick: false,
  animation: true,
  
  // Control panel customization
  showControls: true,
  showExpandAll: true,
  showCollapseAll: false,  // Hide collapse all button
  showClearSelection: true
};

🌟 Advanced Examples

Lazy Loading

onLazyLoad(event: LazyLoadEvent): void {
  // Simulate API call
  setTimeout(() => {
    const children: TreeNode[] = [
      { id: `${event.node.id}-1`, label: 'Child 1', icon: '📄' },
      { id: `${event.node.id}-2`, label: 'Child 2', icon: '📄' }
    ];
    event.callback(children);
  }, 1000);
}

Dynamic Tree Updates

// Add new node
addNode() {
  const newNode: TreeNode = {
    id: Date.now(),
    label: 'New Node',
    icon: '✨'
  };
  this.treeData = [...this.treeData, newNode];
}

// Remove node
removeNode(nodeId: string) {
  this.treeData = this.treeData.filter(node => node.id !== nodeId);
}

🌐 Live Demo

Check out the interactive demo: https://gayanprasanna.github.io/angular-tree-library/

📋 Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support

If you have any questions or need help:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue

Made with ❤️ by Gayan Prasanna