GithubHelp home page GithubHelp logo

alaev / react-checkbox-tree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakezatecky/react-checkbox-tree

0.0 2.0 0.0 1.18 MB

A simple and elegant checkbox tree for React.

Home Page: https://jakezatecky.github.io/react-checkbox-tree/

License: MIT License

JavaScript 90.40% CSS 9.60%

react-checkbox-tree's Introduction

react-checkbox-tree

npm Build Status Dependency Status devDependency Status GitHub license

A simple and elegant checkbox tree for React.

Demo

Usage

Installation

Install the library using your favorite dependency manager:

yarn add react-checkbox-tree

Using npm:

npm install react-checkbox-tree --save

Note โ€“ This library makes use of Font Awesome styles and expects them to be loaded in the browser.

Include CSS

For your convenience, the library's styles can be consumed utilizing one of the following files:

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

Either include one of these files in your stylesheets or utilize a CSS loader:

import 'react-checkbox-tree/lib/react-checkbox-tree.css';

Render Component

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 React from 'react';
import CheckboxTree from 'react-checkbox-tree';

const nodes = [{
    value: 'mars',
    label: 'Mars',
    children: [
        { value: 'phobos', label: 'Phobos' },
        { value: 'deimos', label: 'Deimos' },
    ],
}];

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

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

    render() {
        return (
            <CheckboxTree
                nodes={nodes}
                checked={this.state.checked}
                expanded={this.state.expanded}
                onCheck={checked => this.setState({ checked })}
                onExpand={expanded => this.setState({ expanded })}
            />
        );
    }
}

All node objects must have a unique value. This value is serialized into the checked and expanded arrays and is also used for performance optimizations.

Properties

Property Type Description Default
nodes array Required. Specifies the tree nodes and their children.
checked array An array of checked node values. []
disabled bool If true, the component will be disabled and nodes cannot be checked. false
expandDisabled bool If true, the ability to expand nodes will be disabled. false
expanded array An array of expanded node values. []
name string Optional name for the hidden <input> element. undefined
nameAsArray bool If true, the hidden <input> will encode its values as an array rather than a joined string. false
noCascade bool If true, toggling a parent node will not cascade its check state to its children. false
optimisticToggle bool If true, toggling a partially-checked node will select all children. If false, it will deselect. true
showNodeIcon bool If true, each node will show a parent or leaf icon. true
onCheck function onCheck handler: function(checked) {} () => {}
onExpand function onExpand handler: function(expanded) {} () => {}

Node Properties

Individual nodes within the nodes property can have the following structure:

Property Type Description
label mixed Required. The node's label.
value mixed Required. The node's value.
children array An array of child nodes.
className string A className to add to the node.
disabled bool Whether the node should be disabled.
icon mixed A custom icon for the node.

react-checkbox-tree's People

Contributors

jakezatecky avatar lucas-issa avatar williamboman avatar rusalex avatar karaxuna avatar

Watchers

James Cloos avatar Michael Alaev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.