1.4.0 • Published 6 years ago

@opuscapita/react-treeview v1.4.0

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

react-tree-component

Description

React Tree Component for showing simple hiearchy structures on the UI. Component is based on rc-tree (https://github.com/react-component/tree) component.

Installation

npm install @opuscapita/react-tree-component

Demo

View the DEMO

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

Prop nameTypeDefaultDescription
treeIdstringdefaultTreeTree identifier
classNamestring''Tree container custom class for styling
iconClassstring'carets'FontAwesome content based indicators:
chevronnodes as chevrons
caretsnodes as carets
arrownodes as arrows
defaultExpandedKeysArray[]Array of item ids to expand by default
defaultSelectedKeysArray[]Array of item ids selected by default
defaultCheckedKeysArray[]Array of item ids checked by default
onExpandFunction() => {}Handling the node expand. Takes 'expandedKeys' as parameter jsx onExpand(expKeys) { console.log(expKeys, arguments); }
onSelectFunction() => {}Handling the item select. Takes 'selectedKeys' and 'info' (event object to get node)as parameter jsx onSelect(selKeys, info) { console.log(selKeys, info); }
onCheckFunction() => {}Handling the item checked
onDragDropFunction() => {}Fires when item is dragged and dropped
isDragDropLegalFunctionundefinedThis callback is executed before completing drag n' drop action. Function should return a bool

| | | | Takes 'checkedKeys' and info' (event object to get node) as parameter jsx onCheck (chkKeys, info) { console.log(chkKeys, info); } | | showLine | Boolean | false | Whether show or hide node guide lines | | showIcon | Boolean | false | Whether show or hide node guide lines | | checkable | Boolean | false | Whether show or hide checkboxes from tree| | selectable | Boolean | false | Whether item can be selected. | | disabled | Boolean | false | Disables all node items checkboxes. | | draggable | Boolean | false | Whether item can be dragged around. | | defaultExpandAll | Boolean | false | Expand all nodes by default. | | | | | Note! For better performance do not | | | | | enable this for large dataSets. | | treeData | Array | [] | Array of node objects. | | dataLookUpKey | String | 'key' | Unique identifier of data item. | | dataLookUpValue | String | 'parent' | Representative value of data item. | | dataLookUpChildren | String | 'children' | Data item property to identifiy subitems | | selectedKeys | Array | [] | Array of selected item (ids) |

Code example

import React from 'react';
import { OCTreeView } from '@opuscapita/react-tree-component';   

export default class TreeView extends React.Component {
  const familyData = [
    {
      personId: '100',
      name: 'John Doe',
      siblings: [
        { personId: '100100', name: 'Martha Doe', siblings: [] },
        { personId: '100200', name: 'Jonathan Doe', siblings: [ { personId: '100200100', name: 'Mike Doe', siblings: [] }] },
      ], 
    },
    {
      personId: '200',
      name: 'Haley Miley',
      siblings: [
        { personId: '200100', name: 'Cyrus Miley', siblings: [] },
      ],
    },
  ]; 
  const treeConfig = {
    treeData: exampleData,
    treeId: 'FamilyTree',
    checkable: true,
    selectable: false,
    defaultExpandAll: false,
    showLine: true,
    showIcon: false,
    dataLookUpKey: 'personId',
    dataLookUpValue: 'name',
    dataLookUpChildren: 'siblings',
    disableCheckbox: true,
  };
  render() {
    return (
      <OCTreeView {...treeConfig} />
    );
  }
}
1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago