1.1.0 • Published 2 years ago
simple-react-checkbox-tree v1.1.0
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
Nodes
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 |
renderOnCheck | Node | A Node to render whenever the node label is checked | null |