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-expandable-treeview

v1.0.1

Published

A simple and fully customizable tree view React component

Downloads

1,304

Readme

react-expandable-treeview

npm version

A simple and fully customizable tree view React component

Check out the live demo!

Quick start

  1. Install the package using yarn add react-expandable-treeview or npm install react-expandable-treeview

  2. Import the TreeView component

import TreeView from 'react-expandable-treeview';
  1. Define the data you want to pass to TreeView. It should be a recursive array of elements with an unique id and a children optional prop for children elements. Each one of them will be rendered as a tree node. Here is the base object model:
    {
        id: 0,
        children: [
            //...all the children elements*/
        ],
        // ...other user-defined object properties
    }

And an example of the data prop o be passed to TreeView component.

const data = [
    {
        id: 0,
        children: [
            {
                id: 1
            },
            {
                id: 2
            }
        ],
        id: 3,
        children: [
            {
                id: 4,
                children: [
                    {
                        id: 5
                    }
                ]
            }
        ]
    }
]
  1. The TreeView component has two required props: data and renderNode. The renderNode prop is a function that allows you to represent the nodes of the tree as fully customizable React components: you can define their structure. In the example we add a custom label attribute to our data elements and we want it to be rendered.
const data = [
    {
        id: 0,
        label: 'A Father'
        children: [
            {
                id: 1,
                label: 'A Son'
            },
            {
                id: 2,
                label: 'Another Son'
            }
        ],
        id: 3,
        label: 'Another Father',
        children: [
            {
                id: 4,
                children: [
                    {
                        id: 5,
                        label: 'Yet Another Son',
                    }
                ]
            }
        ]
    }
]

Now we can render the component inside our application:

<TreeView
    data={data}
    renderNode={({ label }) => <div>{label}</div>}
/>

Props

Here are the props you can pass to TreeView.

| Prop Name | Type | Is Required | Default Value | Description | |-|-|-|-|-| | data| array| required|- | The data to display. | | renderNode| func| required | - | The node render function | | lineColor| string| optional | '#4B6DAA' | The color of the tree lines | | lineWidth| number| optional | 0.5 | Thickness of the tree lines | | lineStyle| string| optional | 'solid' | Style of the tree lines. Can be 'solid', 'dotted', etc. (all the possible values for 'border-style' CSS attribute) | | lineAlpha| number| optional | 0.4 | The alpha value of the tree lines | | expandButtonColor | string| optional | '#4B6DAA' | The color of the expand button | | nodeSize| number| optional | 20 | The size of the tree leaf icons |