react-treeview-semantic

1.0.5 • Public • Published

react-treeview

React Tree View Component, Configurable, Customizable.

How To Use ?


// install
npm install --save react-treeview-semantic;

// import
import SourceTree from 'react-treeview-semantic';

// instantiation
<SourceTree
  setActiveItem={this.setActiveItem}
  baseIcon={null}
  baseColor={null}
  checkable={true}
  singleChecked={true}
  treeData={treeData}
  getChecked={this.getChecked}
/>

Attributes


  1. treeData - [Array] - isRequired

data the component needs to build the tree view.

  1. baseIcon - [String]

you can customize icon of the base-item(which flag is 'base' or not declared in treeData, also called default icon, all icon you can found in semantic.

  1. baseColor - [String]

you can customize icon color for baseIcon.

  1. checkable - [Bool]

the component supports selection for all tree nodes, default it's multiselect status, also it can be singleselect by singleChecked attr below.

  1. singleChecked - [Bool]

both checkable and singleChecked attr need to be true if you want to use single checkbox, only tree nodes which flag attr is not 'base' and none can be chosen.

  1. getChecked - [Function callback]

if the component is in single or multi status, the getChecked fuction(you define) will be called when user select or deselect any tree nodes. in your own getChecked func, just 'console.log(arguments)', and you can get checkedArray(all seleced item) data and rootItem(the root node of the checked) data.

  1. setActiveItem - [Function callback]

any time, you click the tree nodes, the setActiveItem func(you define) will be called. in your own getChecked func, just 'console.log(arguments)', and you can get item(item you clicked) data, flag(see some flag in 'treeData example' below) data and root(the root of item you clicked) data.

treeData


  1. flag - [base | file | table]

default it's 'base', other choises: 'file', 'table'(just three current), different flag has different icon, lick 'base', it's a folder(default). in setActiveItem func you can get the flag of tree node.

  1. name

name is isRequired, it doesn't matter whether repeat name exits.

  1. children

the children nodes of curren node.

  1. example
treeData: [
  {
    name: 'index',
    flag: 'base',
    children: [
      {name: 'solej'},
      {
        name: 'sdfds',
        children: [
          {name: 'exits', children: [{name: 'lalal', flag: 'table'}]},
          {name: '_default_', flag: 'file'},
          {name: 'exits2', children: [{name: 'lalal2', flag: 'table'}]},
        ]
      }
    ]
  },

  {
    name: '23qe2jewrjsdf-sdfjksdfsjdf-sdfkjsdfjsd',
    flag: 'base',
    children: [
      {name: 'sdf'},
      {
        name: 'dkdkdkd',
        children: [
          {name: 'cayman-sdfjksdfjkdk-sdfsdfkdkd-dk',flag: 'table'},
          {name: '_default_', flag: 'table'}
        ]
      }
    ]
  }
]

Package Sidebar

Install

npm i react-treeview-semantic

Weekly Downloads

34

Version

1.0.5

License

ISC

Unpacked Size

64.6 kB

Total Files

12

Last publish

Collaborators

  • nojsja