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

v0.1.1

Published

bootstrap4 style tree for react

Downloads

17

Readme

React Bootstrap4 Tree View

Bootstrap Tree View Default

Dependencies

The project has very few dependencies, but you will need the following.

Getting Started

Install

Npm:

$ npm install react-bootstrap4-tree

Usage

Include the correct styles, it's mainly just bootstrap but we add a few tweaks as well.

<!-- Required CSS -->
<link href="path/to/bootstrap.css" rel="stylesheet">

OR

npm install bootstrap

In index.js:

import 'bootstrap/dist/css/bootstrap.css'

Then, a basic initialization would look like.

React.render(
	<TreeView data={data} />,
	document.getElementById('treeview')
);

Data Structure

In order to define the hierarchical structure needed for the tree it's necessary to provide a nested array of JavaScript objects. You can define your custom data in the tree data.

Example

let data = [
    {
        text: 'a1',
        customData: {
            id: '1'
        },
        nodes: [
            {
                text: 'a1-a1',
                customData: {
                    id: '2'
                },
                nodes: []
            }
        ]
    },
    {
        text: 'a2',
        customData: {
            id: '3'
        },
        nodes: [
            {
                text: 'a2-a1',
                customData: {
                    id: '4'
                },
                nodes: [
                    {
                        text: 'a2-a1-a1'
                    },
                    {
                        text: 'a2-a1-a2'
                    }
                ]
            }
        ]
    }, 
    {
        text: 'a3',
        customData: {
            id: '7',
            other: 'other'
        },
        nodes: [
            {
                text: 'a3-a1',
                customData: {
                    id: '9',
                    another: 'another'
                },
                nodes: [
                    {
                        text: 'a2-a1-a1',
                        nodes: [
                            {
                                text: 'a2-a1-a1'
                            },
                            {
                                text: 'a2-a1-a2'
                            }
                        ]
                    },
                    {
                        text: 'a2-a1-a2'
                    }
                ]
            },
            {
                text: 'a3-a2'
            }
        ]
    },
];

If you want to do more, here's the full node specification

{
  text: "Text 1",
  color: "#000000",
  backgroundColor: "#FFFFFF",
  showBorder: true,
  showSelect: true,
  state: {
  	expanded: true,
  	selected: true
  },
  customData: {

  },
  nodes: [
    {},
    ...
  ]
}

Node Properties

The following properties are defined to allow node level overrides, such as node specific colors and border.

text

String Mandatory

The text value displayed for a given tree node.

color

String Optional

The foreground color used on a given node, overrides global color option.

backgroundColor

String Optional

The background color used on a given node, overrides global color option.

state

Object Optional

Describes a node's initial state.

state.expanded

Boolean Default: false

Whether or not a node is expanded i.e. open. Takes precedence over global option levels.

state.selected

Boolean Default: false

Whether or not a node is selected.

Options

Options allow you to customise the treeview's default appearance and behaviour. They are passed to the react component as properties on initialization.

// Example: initializing the treeview
// with a background color of green
// with onExpand and onSelect function

let onExpand = function(nodeData, treeData) {
    console.log(nodeData);
    console.log(treeData);
}

let onSelect = function(nodeData, treeData) {
    console.log(nodeData);
    console.log(treeData);
}

React.render(
	<TreeView data={data} backgroundColor="green" onExpand={onExpand} onSelect={onSelect} />,
	document.getElementById('treeview')
);

The following is a list of all available options.

data

Array of Objects. No default, expects data

This is the core data to be displayed by the tree view.

color

String, any legal color value. Default: inherits from Bootstrap.css.

Sets the default foreground color used by all nodes, except when overridden on a per node basis in data.

backgroundColor

String, any legal color value. Default: inherits from Bootstrap.css.

Sets the default background color used by all nodes, except when overridden on a per node basis in data.

showBorder

Boolean. Default: true

Whether or not to display a border around nodes.

showSelect

Boolean. Default: true

Whether or not to display a select icon.

onExpand

Function. Default: Undefined

When the tree node expand or collapse, this function will be call. It will pass the current node data and the whole tree data as parameter.

onSelect

Function. Default: Undefined

When the tree node is selected or unselected, this function will be call. It will pass the current node data and the whole tree data as parameter.

License

MIT license.