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-tree-browser

v1.0.2

Published

React component allowing to browse tree structure

Downloads

4

Readme

react-tree-browser

React component allowing to browse tree structure

NPM pipeline status coverage report JavaScript Style Guide

react-tree-browser is a library that allows the user to browse a tree structure (for example directory tree) and perform actions on selected nodes.

Install

npm install --save react-tree-browser

or

yarn add react-tree-browser

Usage

import React, { Component } from 'react'

import { TreeBrowser } from 'react-tree-browser'

const tree = {
    id: 'root',
    children: [
        {
            id: 'browsableChild',
            children: [],
        },
        {
            id: 'unbrowsableChild',
        }
    ]
};

config = {
    childrenAttribute: 'children', // default
};

class Example extends Component {
  render () {
    return (
      <DirectoryBrowser tree={tree} config={config} />
    )
  }
}

Or as a HOC providing props:

import React, { Component } from 'react'

import { withTreeBrowser } from 'react-tree-browser'

const tree = {
    id: 'root',
    children: [
        {
            id: 'browsableChild',
            children: [],
        },
        {
            id: 'unbrowsableChild',
        }
    ]
};

config = {
    childrenAttribute: 'children', // default
};

class Example extends Component {
  render () {
    return (
      <div></div>
    )
  }
}

export default withTreeBrowser(Example, tree, config);

Reference

Tree browser configuration (config)

Config option is expected to be a simple JS object with following props:

resolver
  • function(node, path)
  • Default: null
  • Function that resolves children of a given node. It expects the children to be an array of objects. Is provided by the tree browser with following attributes:
    • node - Current node, which children should be resolved
    • path - Path from tree root to given node. (See: Properties - path, section path)
forceChildrenReFetch
  • bool
  • Default: false
  • Flag that orders the browser to fetch children of the current node even if they are already fetched. By default, children are cached in the tree structure.
  • WARNING: This will result in pruning of "children of children".
childrenAttribute
  • string
  • Default: children
  • Which attribute of the node should be treated as collection of nodes children.

Initial tree (tree)

Can be a full static tree or just the root node even without children fetched.

Properties passed to the wrapped component

path
  • array
  • An array of node elements (excluding root) that ends on current node. Has two properties:
    • index - Index of path node in it's parents array of children
    • metaData - Any meta-data passed while opening this node
tree
  • object
  • Whole tree from root to all fetched leaves. Do not edit this structure as the library depends on it's immutability!
loading
  • bool
  • Indicates that the resolver is working on resolving children of current node. Display a progress bar for the user?
currentNode
  • object
  • Currently open node of the tree.
childrenAttribute
  • string
  • Name of the attribute containing collection of children of the current node.
onGoToParent
  • function():void
  • Tells the tree browser to go to parent of the current node.
onOpenNode
  • function(index, metaData):void
  • Tells the tree browser to go to specified node. Expects two parameters:
    • index - index of the node in it's parent collection
    • metaData - Any metadata you need to pass (for example name of the node).

<TreeBrowser /> component

Its a very basic tree browser. Additionally it accepts following parameters:

mimeTypes
  • object
  • Default: {}
  • A key-value object of mime-types and their respective icons.
getDisplayName
  • function(node):string
  • Default: (node) => node.name
  • Resolves display name for given node. Takes following parameters:
    • node - Tree node
getMimeType
  • function(node):string
  • Default: (node) => node.mimeType
  • Resolves mimeType key for given node. Takes following parameters:
    • node - Tree node

License

MIT © Bartosz 'Wunsz' Jabłoński | Code in the Cup