1.1.0 • Published 2 years ago

simple-react-checkbox-tree v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

simple-react-checkbox-tree

A simple checkbox tree for React.

Demo

live demo https://codesandbox.io/s/simple-react-checkbox-tree-02c9d?file=/src/App.js

Installation

Install with npm

  npm install simple-react-checkbox-tree

Usage/Examples

import React, { useState } from 'react';
import CheckBox from 'simple-react-checkbox-tree/lib';

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

function App() {
  const [checked, setChecked] = useState([]);
  const [expanded, setExpanded] = useState([]);

  return (
    <CheckboxTree
      nodes={nodes}
      checked={checked}
      expanded={expanded}
      onCheck={checked => setChecked(checked)}
      onExpand={expanded => setExpanded(expanded)}
    />
  )
}

All node objects must have a unique value. This value is serialized into the checked and expanded arrays.

By default this package loads material icons through CDN link in css file.

Properties

PropertyTypeDescriptionDefault
nodesarrayRequired. Specifies the tree nodes and their children.
checkedarrayAn array of checked node values.
expandedarrayAn array of expanded node values.
expandDisabledboolIf true, the ability to expand nodes will be disabled.false
disabledboolAn array of expanded node values.
expandedarrayIf true, the component will be disabled and nodes cannot be checked.false
namestringOptional name for the hidden <input> element.undefined
noCascadeboolIf true, toggling a parent node will not cascade its check state to its children.false
showExpandToggleButtonsboolIf true, buttons for expanding and collapsing all parent nodes will appear in the tree.false
expandAllboolIf true, all nodes will be expanded by defaultfalse
folderIconsboolIf true, all nodes will have folder icon or file icon based on if it is a parent or childfalse
onCheckfunctiononCheck handler: function(checked) {}() => {}
onExpandfunctiononExpand handler: function(expanded) {}() => {}

Nodes

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

PropertyTypeDescriptionDefault
labelmixedRequired. The node's label.
valuemixedRequired. The node's value.
childrenarrayAn array of child nodes..null
renderOnCheckNodeA Node to render whenever the node label is checkednull
1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago