Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-arborist

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-arborist

A full-featured tree component for React.

  • 0.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40K
decreased by-1.09%
Maintainers
1
Weekly downloads
 
Created
Source

React Arborist

A full-featured tree component for React.

The tree is a ubiquitous UI component in software applications. There are already many libraries that provide this componet for React apps, but none were full-featured enough to stand on their own.

This libraries provides all the common features expected in a tree viewer. You can select one or many nodes to drag and drop into new positions, open and close folders, render an inline form for renaming, efficiently show thousands of items with virtualization, and provide your own node renderer to control the style.

Demo

Installation

yarn add react-arborist
npm install react-arborist

Features

  • sortable
  • virtualized
  • multi-selectable
  • collapsible
  • renameable
  • style-less

Example

Render the tree data structure.

const data = {
  id: "The Root",
  children: [{id: "Node A"}, {id: "Node B"}]
}

function App() {
  return (
    <Tree
      data={data}
      width={300}
      height={500}
      indent={24}
    >
      {Node}
    </Tree>
  );
}

function Node({ node, props, indent, handlers }) {
  return (
    <div {...props}>
      <div style={{ paddingLeft: indent }}>{node.model.id}</div>
    </div>
  );
}

The data prop must be an object with an id property. Any child nodes must be put in the array property children.

Open and Close

Add a boolean property isOpen to any of the nodes to display it open or closed. If no property exists, it will default to false.

const data = {
  id: "The Root",
  isOpen: true,
  children: [...]
}

To toggle the isOpen field attach the handlers.toggleOpen callback to a event in your Node component, then add the onOpen/onClose handlers to the Tree component.

function MyApp() {
  const onOpen = (id) => {
    // Change the data however you want...
    setData(mutate(id, (n) => n.isOpen = true))
  }

  return <Tree
    onOpen={onOpen}
    onClose={onClose}
    ...
}

function Node({ props, handlers }) {
  return (
    <div {...props} onClick={handlers.toggleOpen}>
    // ...
    </div>
  );
}

FAQs

Package last updated on 14 Sep 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc