JSPM

  • Created
  • Published
  • Downloads 110289
  • Score
    100M100P100Q157327F
  • License MIT

React component for checkbox trees.

Package Exports

  • react-checkbox-tree
  • react-checkbox-tree/lib/react-checkbox-tree.css
  • react-checkbox-tree/src/less/react-checkbox-tree.less

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-checkbox-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-checkbox-tree

npm Dependency Status devDependency Status GitHub license

Checkbox treeview for React.

Demo

Installation

The easiest way to use react-checkbox-tree is to install from NPM and include it in your own React build process (e.g. using Webpack):

npm install react-checkbox-tree --save

Usage

A quick usage example is included below. Note that the react-checkbox-tree component is controlled. In other words, it is stateless. You must update its checked and expanded properties whenever a change occurs.

import CheckboxTree from 'react-checkbox-tree';

const nodes = [{
    value: 'node-1',
    title: 'Parent Node 1',
    children: [{
        value: 'node-1-1',
        title: 'Leaf Node 1-1',
    }, {
        value: 'node-1-2',
        title: 'Leaf Node 1-2'
    }],
}];

class Widget extends React.Component {
    constructor() {
        super();

        this.state = {
            checked: [],
            expanded: [],
        };

        this.onCheck = this.onCheck.bind(this);
        this.onExpand = this.onExpand.bind(this);
    }

    onCheck(checked) {
        this.setState({ checked });
    }

    onExpand(expanded) {
        this.setState({ expanded });
    }

    render() {
        const { checked, expanded } = this.state;

        return (
            <Tree
                name="tree_nodes"
                nodes={nodes}
                checked={checked}
                expanded={expanded}
                onCheck={this.onCheck}
                onExpand={this.onExpand}
            />
        );
    }
}

Properties

Property Type Description
nodes array Required. Specifies the tree nodes and their children.
checked array Required. An array of checked node values.
expanded array Required. An array of expanded node values.
onCheck function onCheck handler: function(checked) {}
onExpand function onExpand handler: function(expanded) {}
name string Optional name for the hidden <input> element.
nameAsArray bool If true, the hidden <input> will encode its values as an array rather than a joined string.