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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-rich-tree

v0.1.1

Published

A feature-rich, extensible tree component for React

Downloads

3

Readme

React Rich Tree

A full featured tree component for React

We've built so many projects that required a tree component, and could never find a library that supported all features. And building your own tree component is not an easy task.

So, we decided to build one for React, with all the features you can think of:

  • Simple to use
  • Well Documented
  • Customizable & Extensible (override field names, custom templates, etc...)
  • Keyboard navigation
  • Async data
  • Drag & Drop
  • Select & Multiselect
  • Filtering
  • Virtual Scrolling
  • Save & restore tree state
  • Event callbacks
  • API for accessing & altering the tree state
  • Easily styled (comes with very minimal styling)

Getting started

npm i -S react-rich-tree

import { Tree } from 'react-rich-tree';

nodes = [{
  id: 1,
  name: 'root',
  children: [{
    id: 2,
    name: 'child'
  }, {
    id: 4,
    name: 'child2'
  }]
}, {
  id: 5,
  name: 'root2'
}];

options = {}

onEvent = (event) => console.log(event)

<Tree nodes={ nodes } options={ options } onEvent={ onEvent }/>

Full example

import { Tree, TreeNode, TreeModel, TREE_ACTIONS } from 'react-rich-tree';

nodes = [{
  id: 1,
  name: 'root',
  type: 'folder',
  children: [{
    id: 2,
    type: 'file',
    name: 'child'
  }, {
    id: 4,
    type: 'file',
    name: 'child2'
  }]
}, {
  id: 5,
  type: 'folder',
  name: 'root2',
  hasChildren: true // async
}];

options = {
  childrenField: 'children',
  displayField: 'name',
  idField: 'id',
  getChildren: (node: TreeNode) => http.get(`/children/${node.id}`), // async load children - to be used with `hasChildren` property on the node
  actionMapping: { // override key and mouse actions
    mouse: {
      click: TREE_ACTIONS.TOGGLE_SELECTED,
      dblClick: (tree: TreeModel, node: TreeNode, $event: any) => node.toggleExpanded(),
      contextMenu: null,
      expanderClick: TREE_ACTIONS.TOGGLE_EXPANDED,
      drop: TREE_ACTIONS.MOVE_NODE
    },
    keys: {
      [KEYS.RIGHT]: TREE_ACTIONS.DRILL_DOWN,
      [KEYS.LEFT]: TREE_ACTIONS.DRILL_UP,
      [KEYS.DOWN]: TREE_ACTIONS.NEXT_NODE,
      [KEYS.UP]: TREE_ACTIONS.PREVIOUS_NODE,
      [KEYS.SPACE]: TREE_ACTIONS.TOGGLE_SELECTED,
      [KEYS.ENTER]: TREE_ACTIONS.TOGGLE_SELECTED
    }
  },
  allowDrag: (node: TreeNode) => node.isLeaf, // boolean or function. isLeaf is a function on TreeNode wrapper class
  allowDrop: (node: TreeNode) => node.data.type === 'folder', // data is the original data supplied by nodes
  levelPadding: 4, // to be used for whole row selection (instead of putting padding on children)
  nodeClass: (node: TreeNode) => node.type, // for styling
  useVirtualScroll: true,
  nodeHeight: 30,
  dropSlotHeight: 3,
  animateExpand: true,
  animateSpeed: 50,
  animateAcceleration: 1.1,
  scrollOnSelect: true,
  getNodeClone: (node: TreeNode) => ({ ...node.data, id: uuid.v4() }), // for dragging with ctrl pressed
  TreeNodeComponent: ({ node }) => <span>{ node.data.name } ({node.children.length})</span>
  TreeNodeWrapperComponent: MyCustomNodeWrapper, // a component class that extends NodeWrapper component (or replaces it)
  TreeNodeFullComponent: MyCustomFullNode, // a component class that extends Node component (or replaces it)
  LoadingComponent: ({ node }) => <img src="loading.gif"/>
}

<Tree
  nodes={ nodes }
  options={ options }
  onToggleExpanded={ onToggleExpanded }
  onActivate={ onActivate }
  onDeactivate={ onDeactivate }
  onFocus={ onFocus }
  onBlur={ onBlur }
  onInitialized={ onInitialized }
  onUpdateData={ onUpdateData }
  onMoveNode={ onMoveNode }
  onCopyNode={ onCopyNode }
  onEvent={ onEvent }
  onLoadNodeChildren={ onLoadNodeChildren }
  onChangeFilter={ onChangeFilter }
  onStateChange={ onStateChange }
/>

Storybook

coming soon

Docs

coming soon

What's next

We would always love to hear suggestions for features & improvements - just open an issue.

Some things on our mind down the road:

  • Context menu
  • Checkbox & master checkbox support
  • Add Demo & StoryBook
  • Add Tests

Contributing

Run once: npm run setup

Run after changing code: npm run build npm run start:example

Please check the issues / project before starting to work on a feature / bug to make sure it's not already in progress.