2.3.5 • Published 4 years ago

@opuscapita/react-tree-component v2.3.5

Weekly downloads
2
License
MIT
Repository
github
Last release
4 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
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
onOrderButtonClickFunctionundefinedFires when ordering arrows are clicked
isDragDropLegalFunctionundefinedThis callback is executed before completing drag n' drop action. Function should return a bool
showIconBooleanfalseWhether show or hide node guide lines
checkableBooleanfalseWhether show or hide checkboxes from tree
selectableBooleanfalseWhether item can be selected.
disabledBooleanfalseDisables all node items checkboxes.
draggableBooleanfalseWhether item can be dragged around.
defaultExpandAllBooleanfalseExpand all nodes by default.
Note! For better performance do not
enable this for large dataSets.
treeDataArray[]Array of node objects.
dataLookUpKeyString'key'Unique identifier of data item.
dataLookUpValueString'parent'Representative value of data item.
dataLookUpLeafValueStringundefinedRepresentative value of leaf data item (if differs from dataLookUpValue).
dataLookUpChildrenString'children'Data item property to identifiy subitems
checkedKeysArray[]Array of checked items (ids)
expandedKeysArray[]Array of expanded items (ids)
defaultExpandedKeysArray[]Array of items that are expanded by default (ids). Use expandedKeys instead, if you're using 'handleExpandedKeysManually'
selectedKeysArray[]Array of selected items (ids)
deselectOnContainerClickBooleantrueDeselects all selected keys when not clicking on any particular item
showExpandAllBooleanfalseShow expand all toggle
titleStringundefinedTree title
headerRightNodeundefinedContent displayed on the right side of the header
showOrderingArrowsBooleanfalseShows arrows for reordering the tree items. (if you don't want to use (flawed) drag n' drop)
handleExpandedKeysManuallyBooleanfalseUse this, if you want a full control of expanded keys. Don't use this, if you want rc-tree to handle node expansion automatically

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,
    showIcon: false,
    dataLookUpKey: 'personId',
    dataLookUpValue: 'name',
    dataLookUpChildren: 'siblings',
    disableCheckbox: true,
  };
  render() {
    return (
      <OCTreeView {...treeConfig} />
    );
  }
}
2.3.5

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago