1.0.11 • Published 6 years ago

react-immer-tree v1.0.11

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

react-immer-tree


license Scrutinizer Build

Easy to configure, customisable React tree component. Support drag and drop, check, search, etc.

中文README


Feature

  1. check
    • check only one node
    • check multiple node
    • check all node
    • disabled and close node after checked
    • check nodes which have same attribute
  2. drag and drop
  3. append new node
  4. edit node name
  5. delete node
  6. search node by name
  7. set different icon or other element on different node type

Usage

  1. npm install react-immer-tree
  2.  import React from 'react'
     import ReactDOM from 'react-dom'
     import Tree from 'react-immer-tree'
     import 'react-immer-tree/build/Tree.css'
     
     const data = [{
         name: 'a',
         children: [
             { name: 'b' }
             { name: 'c' }
             { name: 'd', children: [
                 { name: 'e' }            
                 { name: 'f' }            
             ]}
         ]
     }]
     
     ReactDOM.render(
       <div>
         <Tree data={data} />
       </div>,
       document.getElementById('app'))

API

Tree Props
propsdescriptiontypedefault
afterSelectNodeeffects after check nodedisabled:disabled node and close nodeall:check all children nodesone:only check itselfstring'disabled'
beforeAddcallback function before append child node in menu,need to return true,otherwise append action will failfunction() => true
beforeDeletecallback function before delete node in menu,need to return true,otherwise delete acton will failfunction() => true
beforeEditcallback function before edit node name in menu,need to return true,otherwise edit action will failfunction() => true
checkSameAttrcheck nodes which have same attribute(such as 'id')string''
datatree structure dataarray[]
hasOperatehas operate menu or notbooleanfalse
hasCheckboxhas checkbox or notbooleanfalse
hasSearchhas search ability or notbooleanfalse
isRadiois check only one or notbooleanfalse
isDraggableis draggable or notbooleanfalse
nodeTypestype(set in node data)-element object (maybe you can use it to set different node type with different icon)object{typename: reactElement}{}
noSearchDatareturn reactElement which will show when no data matchedfunction() => {}
onAddcallback function when append child node, return child node data -- {name: xxx, state: xxx}function() => ({})
onCheckedcallback function after check nodefunction(selected[])() => {}
onEditcallback function when edit node name, return edit namefunction() => 'edited name'
onUncheckedcallback function after uncheck nodefunction(selected[])() => {}
resultNodereturn reactElement,which will show in check result list. (check result list will show when afterSelectNode set 'disabled')function() => {}
Node JSON Data
[
    {
        name: xxx,          // node name(string/reactElement)
        type: xxx,          // node type(string/number)
        state: {            // node state
            isOpen: false,  // open or not
            isChecked: false, // check or not
            isDisabled: false, // disable or not
        },
        children: [{}, {}]
    }
]
1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago