1.0.6 • Published 2 years ago

@eunseu/react-hierarchy v1.0.6

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

react-hierarchy

React Hierarchy Component that can be easily customized.

Demo

demo

Install

yarn add @eunseu/react-hierarchy

or

npm install @eunseu/react-hierarchy

Usage

You can use this library in two ways. First, you can pass data as props

import { Hierarchy } from '@eunseu/react-hierarchy';

<Hierarchy data={items} />

Second, You can custom your own hierarchy.

import { HierarchyTree } from '@eunseu/react-hierarchy';

<HierarchyTree>
  <HierarchyTree.Folder>
    Folder1
    <HierarchyTree.Element>Element1</HierarchyTree.Element>
    
    <HierarchyTree.Folder>
      Folder2
      <HierarchyTree.Element>
        Element2
      </HierarchyTree.Element>
    </HierarchyTree.Folder>
    
    <HierarchyTree.Element>Element3</HierarchyTree.Element>
  </HierarchyTree.Folder>
</HierarchyTree>

Data Format

If you want to create hierarchy as data, you should input your data

  • required: id, content
  • optional: items
  • If you want to make folder, you should add items
  • example:
[
  {
    "id": 1,
    "content": "Folder1",
    "items": [
      {
        "id": 2,
        "content": "Element1",
      }
    ]
  },
  {
    "id": 3,
    "content": "Element2"
  }
]

Props

Hierarchy

NameTypeDefaultRequiredDescription
dataHierarchyItems[]nullYThe data set for react hierarchy to render
onToggleFolder(e: React.MouseEvent<HTMLDivElement>, id: string) => voidnullNEvent listener called on open some folder action
onClickElement(e: React.MouseEvent<HTMLDivElement>, id: string) => voidnullNEvent listener called on click element action
folderTemplate({content: string, isOpened: boolean}) => ReactElementnullNThe contents of the folder can be customized through React Element.
elementTemplate(content: string) => ReactElementnullNThe contents of the element can be customized through React Element.
folderClassNamestringnullNSpecify className in the folder
elementClassNamestringnullNSpecify className in the element
defaultIsFoldbooleantrueNWhether to put all folders folded by default
depthInLengthnumber20NIndent Length
animationbooleantrueNWhether to use animation

HierarchyTree

NameTypeDefaultRequiredDescription
defaultIsFoldbooleantrueNWhether to put all folders folded by default
depthInLengthnumber20NIndent Length
animationbooleantrueNWhether to use animation

Contributing

  • open issues and PRs and we'll work together!
1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago