0.0.3 • Published 7 months ago

@neui/react-treeview v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

React-Treeview

Features

  • Customization of tree node and icon.
  • Select / Unselect nodes.
  • Disabled nodes.
  • Performance

Getting started

npm install @neui/react-treeview

or

yarn add @neui/react-treeview

Prop types

Prop nameTypeDefault valueDescription
dataarray[node]requiredTree data
treeNodeRendererfuncnoopRender prop for the node (see below for more details)
iconRendererfuncnoopRender prop for the node (see below for more details)
onClickfuncnoopFunction called when a node is clicked
onSelectfuncnoopFunction called when a node is selected/deselected
enableSelectionboolfalseAllows nodes to be selected
showIconboolfalseShow icon for non-leaf and leaf node
showLineboolfalseShow line indicator to visualize depth of tree
defaultSelectedIdsarray[node.key][]Array with the ids of the default selected nodes
defaultSelectedIdsarray[node.key][]Array with the ids of the default expanded nodes
defaultSelectedIdsarray[node.key][]Array with the ids of the default disabled nodes

data (tree-node)

PropertyTypeDefaultDescription
namestringrequiredUsed to match on key press
childrenarray[node]undefinedAn array with the children nodes. If absent then node will be treated as leaf node
keystringrequiredA string that uniquely identifies the node

Example:

const data = [
  {
    label: "Folder 1",
    key: "1",
    children: [
      {
        label: "Folder 1.1",
        key: "1.1",
        children: [
          {
            label: "File 1.1.1",
            key: "1.1.1",
          },
          {
            label: "File 1.1.2",
            key: "1.1.2",
          },
          {
            label: "Folder 1.1.3",
            key: "1.1.3",
            children: [
              {
                label: "File 1.1.1.1",
                key: "1.1.1.1",
              },
            ],
          }
        ]
      },
      {
        label: "Folder 1.2",
        key: "1.2",
        children: [
          {
            label: "File 1.2.1",
            key: "1.2.1",
          },
          {
            label: "File 1.2.2",
            key: "1.2.2",
          }
        ]
      }
    ]
  }
];

treeNodeRenderer & iconRenderer

PropertyTypeDescription
nodeobjectThe object that represents the tree node
isLeafNodeboolWhether the rendered node is a tree leaf node
isSelectedboolWhether the rendered node is selected
isExpandedboolWhether the rendered node is expanded
isDisabledboolWhether the rendered node is disabled
handleSelectfunctionFunction to assign to the onClick event handler of the element(s) that will toggle the selected state
handleExpandfunctionFunction to assign to the onClick event handler of the element(s) that will toggle the expanded state

onClick

onClick({ node, isSelected, isExpanded, isDisabled })

onSelect

onClick({ node, isSelected, isExpanded, isDisabled })