All Projects → jakezatecky → React Checkbox Tree

jakezatecky / React Checkbox Tree

Licence: mit
A simple and elegant checkbox tree for React.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Checkbox Tree

react-tree
Hierarchical tree component for React in Typescript
Stars: ✭ 174 (-63.52%)
Mutual labels:  tree, treeview
Bosket
Collection of tree view components for front-end frameworks. 🌳
Stars: ✭ 457 (-4.19%)
Mutual labels:  tree, treeview
tree-tree
No description or website provided.
Stars: ✭ 15 (-96.86%)
Mutual labels:  tree, treeview
vue-virtualised
Blazing fast scrolling and updating for any amount of list and hierarchical data.
Stars: ✭ 18 (-96.23%)
Mutual labels:  tree, treeview
Ngx Treeview
An Angular treeview component with checkbox
Stars: ✭ 312 (-34.59%)
Mutual labels:  tree, treeview
android-thinkmap-treeview
Tree View; Mind map; Think map; tree map; custom view; 自定义;关系图;树状图;思维导图;组织机构图;层次图
Stars: ✭ 314 (-34.17%)
Mutual labels:  tree, treeview
react-native-nested-listview
A UI component for React Native for representing nested arrays of N levels
Stars: ✭ 163 (-65.83%)
Mutual labels:  tree, treeview
Wmztreeview
类似前端elementUI的树形控件,可自定义节点内容,支持无限极节点,可拖拽增删节点等等,非递归实现
Stars: ✭ 118 (-75.26%)
Mutual labels:  tree, treeview
Gijgo
Gijgo - Free Javascript Controls
Stars: ✭ 424 (-11.11%)
Mutual labels:  tree, treeview
Thinkmap
Draw a tree in Android。在 Android 上绘制思维导图控件,让思维更简单。
Stars: ✭ 285 (-40.25%)
Mutual labels:  tree, treeview
vuejs-tree
A highly customizable and blazing fast Vue tree component ⚡🌲
Stars: ✭ 310 (-35.01%)
Mutual labels:  tree, treeview
Ng2 Tree
Angular tree component
Stars: ✭ 350 (-26.62%)
Mutual labels:  tree, treeview
Vuejs Tree
A highly customizable and blazing fast Vue tree component ⚡🌲
Stars: ✭ 211 (-55.77%)
Mutual labels:  tree, treeview
comment tree
Render comment tree like facebook comment - reply
Stars: ✭ 37 (-92.24%)
Mutual labels:  tree, treeview
Graphview
Flutter GraphView is used to display data in graph structures. It can display Tree layout, Directed and Layered graph. Useful for Family Tree, Hierarchy View.
Stars: ✭ 152 (-68.13%)
Mutual labels:  tree, treeview
react-treefold
A renderless tree component for your hierarchical React views
Stars: ✭ 37 (-92.24%)
Mutual labels:  tree, treeview
Bootstraptable Treeview
bootstrapTable extension of treeView
Stars: ✭ 57 (-88.05%)
Mutual labels:  tree, treeview
Vue Finder
📁 A Vue.js component to display hierarchical data (like the MacOS X finder)
Stars: ✭ 87 (-81.76%)
Mutual labels:  tree, treeview
select2-to-tree
Select2-to-Tree extends Select2 to support arbitrary level of nesting...
Stars: ✭ 71 (-85.12%)
Mutual labels:  tree, treeview
Liquor Tree
Tree component based on Vue.js
Stars: ✭ 348 (-27.04%)
Mutual labels:  tree, treeview

react-checkbox-tree

npm Build 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, 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 {
    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.

Changing the Default Icons

By default, react-checkbox-tree uses Font Awesome 4 for the various icons that appear in the tree. To utilize Font Awesome 5 icons, simply pass in iconsClass="fa5":

<CheckboxTree
    ...
    iconsClass="fa5"
/>

To change the rendered icons entirely, simply pass in the icons property and override the defaults. Note that you can override as many or as little icons as you like:

<CheckboxTree
    ...
    icons={{
        check: <span className="rct-icon rct-icon-check" />,
        uncheck: <span className="rct-icon rct-icon-uncheck" />,
        halfCheck: <span className="rct-icon rct-icon-half-check" />,
        expandClose: <span className="rct-icon rct-icon-expand-close" />,
        expandOpen: <span className="rct-icon rct-icon-expand-open" />,
        expandAll: <span className="rct-icon rct-icon-expand-all" />,
        collapseAll: <span className="rct-icon rct-icon-collapse-all" />,
        parentClose: <span className="rct-icon rct-icon-parent-close" />,
        parentOpen: <span className="rct-icon rct-icon-parent-open" />,
        leaf: <span className="rct-icon rct-icon-leaf" />,
    }}
/>

If you are using the react-fontawesome library, you can also directly substitute those icons:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

...

<CheckboxTree
    ...
    icons={{
        check: <FontAwesomeIcon className="rct-icon rct-icon-check" icon="check-square" />,
        uncheck: <FontAwesomeIcon className="rct-icon rct-icon-uncheck" icon={['fas', 'square']} />,
        halfCheck: <FontAwesomeIcon className="rct-icon rct-icon-half-check" icon="check-square" />,
        expandClose: <FontAwesomeIcon className="rct-icon rct-icon-expand-close" icon="chevron-right" />,
        expandOpen: <FontAwesomeIcon className="rct-icon rct-icon-expand-open" icon="chevron-down" />,
        expandAll: <FontAwesomeIcon className="rct-icon rct-icon-expand-all" icon="plus-square" />,
        collapseAll: <FontAwesomeIcon className="rct-icon rct-icon-collapse-all" icon="minus-square" />,
        parentClose: <FontAwesomeIcon className="rct-icon rct-icon-parent-close" icon="folder" />,
        parentOpen: <FontAwesomeIcon className="rct-icon rct-icon-parent-open" icon="folder-open" />,
        leaf: <FontAwesomeIcon className="rct-icon rct-icon-leaf-close" icon="file" />
    }}
/>

Properties

Property Type Description Default
nodes array Required. Specifies the tree nodes and their children.
checkModel string Specifies which checked nodes should be stored in the checked array. Accepts 'leaf' or 'all'. 'leaf'
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
expandOnClick bool If true, nodes will be expanded by clicking on labels. Requires a non-empty onClick function. false
expanded array An array of expanded node values. []
icons object An object containing the mappings for the various icons and their components. See Changing the Default Icons. { ... }
iconsClass string A string that specifies which icons class to utilize. Currently, 'fa4' and 'fa5' are supported. 'fa4'
id string A string to be used for the HTML ID of the rendered tree and its nodes. null
lang object An object containing the language mappings for the various text elements. { ... }
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
nativeCheckboxes bool If true, native browser checkboxes will be used instead of pseudo-checkbox icons. false
noCascade bool If true, toggling a parent node will not cascade its check state to its children. false
onlyLeafCheckboxes bool If true, checkboxes will only be shown for leaf nodes. false
optimisticToggle bool If true, toggling a partially-checked node will select all children. If false, it will deselect. true
showExpandAll bool If true, buttons for expanding and collapsing all parent nodes will appear in the tree. false
showNodeIcon bool If true, each node will show a parent or leaf icon. true
showNodeTitle bool If true, the label of each node will become the title of the resulting DOM node. Overridden by node.title. false
onCheck function onCheck handler: function(checked, targetNode) {} () => {}
onClick function onClick handler: function(targetNode) {}. If set, onClick will be called when a node's label has been clicked. () => {}
onExpand function onExpand handler: function(expanded, targetNode) {} () => {}

onCheck and onExpand

Node Properties

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

Property Type Description Default
label mixed Required. The node's label.
value mixed Required. The node's value.
children array An array of child nodes. null
className string A className to add to the node. null
disabled bool Whether the node should be disabled. false
icon mixed A custom icon for the node. null
showCheckbox bool Whether the node should show a checkbox. true
title string A custom title attribute for the node. null
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].