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

checkbox-tree-react

v0.1.9

Published

[![npm version](https://badge.fury.io/js/checkbox-tree-react.svg)](https://badge.fury.io/js/checkbox-tree-react) [![Coverage Status](https://coveralls.io/repos/github/MarkusBansky/react-checkbox-tree/badge.svg?branch=master)](https://coveralls.io/github/M

Downloads

324

Readme

Create checkbox trees with react-checkbox-tree

npm version Coverage Status Build Status

Hi! I am a software developer and made this package to simplify life for some developers seeking similar solution for their react projects. This package let's you create a simple but custom checkbox tree from any data type you have, and implement it in your react project with a simple component.

Instalation

It is as simple as it looks like: npm install react-checkbox-tree

Depencies

This project depends on fontawesome and react.

Usage

You will need to do two steps first in order to get ready to use your data in the checkbox tree.

Data

First, get your data prepared:

const data = [
  { // These are your main root nodes
    'id': 1,
    'name': 'Group A',
    'subGroups': [
      { // These are the children of the main nodes
        'id': 1,
        'name': 'Sub group 1',
        'leaves': [
          { // These are leaves without nodes
            'id': 1,
            'name': 'Mark'
          },
          //...
        ]
      },
      //...
    ]
  },
  //...
]

This part of code above creates a simple tree with one root node, that has one childand that child has one leaf.

If needed you can set the checkedState field in each node to define its' initial checked state. The checkedState parameter can be set to checked or unchecked as a string.

Accessors

The accessor has a structure like this:

{
  label: '**enter the name of the field in your data element to display in the tree node**',
  value: '**enter the name of the value field for the node**',
  type: '**this is used to group your selection of checkboxes by tree levels**',
  leaves: '**this is a name of the field to get children for this node**'
}

Now you have to make accessors to each branch level in your data, so that the tree knows how to access your data. This can be done as follows for the above example:

const accessors = [
  {
    label: 'name',
    value: 'id',
    leaves: 'subGroups',
    type: 'root'
  },
  {
    label: 'name',
    value: 'id',
    leaves: 'leaves',
    type: 'group'
  },
  {
    label: 'name',
    value: 'id',
    type: 'leaf'
  }
]

Tree Element

Now you can use the tree element and add it to your view, notice that you are passing the data and accessors variables into the component:

<CheckboxTree data={data} accessors={accessors} />

The CheckboxTree element can also have onChange parameter that accepts a method(items) as value.

Api

CheckboxTree

A main element that holds the tree of checkboxes from the data that is build with accessors.

  • data A javascript structure that holds all the data and could be also retreived from API call or other methods. Must be an array.
  • accessors An array of structures that contain ccessors to the data levels for the tree. The data can contain a stacked tree with different parameters, here you define which parameters to choose for name, value and type, nd also how to select child nodes. { label: 'paramForLabel', value: 'paramForValue', type: 'anyTypeName', leaves: 'paramForChildren' }
  • onChange Accepts a function with a single parameter items which is a structure of tree types that represent different levels of the tree and values selected on that levels.

License

MIT