0.0.1-beta.34 • Published 4 years ago

react-hook-tree v0.0.1-beta.34

Weekly downloads
27
License
MIT
Repository
github
Last release
4 years ago

React Hook tree

Introduction

Get started with React Hook Tree. the most powerful Tree View React Component for building responsive, mobile-first lightweight Trees.

Full Features

  • Display hierarchical data in a tree-view structure.
  • Edit, Add and Delete nodes
  • Expand/Collapse
  • Custom & multiple node object attributes
  • Unlimited nesting
  • Fully customizable text content (you can deploy in any language)
  • RTL support
  • Fully customizable style

Demo and documentation : rht.now.sh

Quick start

Install

NPM

npm install --save react-hook-tree

YARN

yarn add react-hook-tree

Run on sandbox

Edit pedantic-curran-49riv

Example

import data from "./treeData.json";
import Tree from "react-hook-tree";

<Tree treeData={data} />

Demo And Documentation

rht.now.sh

Props

Data

OptiontypesrequireddefaultDescription
treeDataJson Objectyes-the data to render (please see json file in data folder)
checkboxBooleanno-Show check box and add select support for nodes
countBooleanno-Show children count on each node
langJson Objectyes-Text content, please see Lang Object Attribute
nodeJson Objectno-Node object attributes Attribute, please see Data Object Attribute
editBooleannofalseShow the edit button
addBooleannofalseShow the add button
removeBooleannofalseShow the remove button
onChangeFunctionno-Return the modified json data, if actions (edit, delete) are are enabled

Data Format : TreeData prop

{
    tree: [
	    {
	    _id: "",
	    children: []
	    item: { name: "", ... }
    }
]

See data example files in Data folder

Text, content & languages : Lang prop

{
    "rtl":true,
    "modal": {
				"add": {
					"title": "Add Modal",
					"warning": "Check carfully your data before saving !",
					"content": "You are Adding a new node",
					"button": "save"
				},
	    "edit": {
		    "title": "Edit Modal",
		    "warning": "Check carfully your data before saving !",
		    "content": "You are editing the %1 node",
		    "button": "save"
	    },
	    "delete": {
		    "title": "Are you absolutely sure?",
		    "warning": "Unexpected bad things will happen if you don’t read this!",
		    "content": "This action cannot be undone. This will permanently delete the %1, and remove all children associations. Please type confirmed to delete.",
		    "confirmation": "please type %1 to delete",
		    "verification": "confirm",
		    "button": "delete this node"
	    }
    }
}

See Lang example file in Lang folder

Add Edit action : node props

Each node has a name which is an unchanging attribute.

with node prop you can add more attribute to each node, here for example i will add a title and a checkbox.

Each node will be editable over an edit button which triggers a popup modal where you can edit node's data.

data edit node

you can configure what ever data you want in these types : input text and checkbox, more data types will be available in next updates.

each data configuration have these attributes : name, type, placeholder

[
    {
	    name: "title",
	    type: "text-input",
	    placeholder: "Title",
    },

    {
	    name: "active",
	    type: "checkbox",
	    value: 0,
	    datatype: "int",
	    label: "activé le type",
    },

]

enter image description here

as you can see the attributes are used to dynamically create a form to edit the node's data.

Remove Action

Each node can be removed,

by setting the remove props to true,

if a node is deleted all its children will be deleted, This action cannot be undone. This will permanently delete the node, and remove all children associations.

enter image description here

Style

OptiontypesrequiredDescription
iconTypeStringnoone of ("folder","rounded","thick") or leave empty for simple arrow
styleReact Style PropsnoGlobal container inline style
lineStyleReact Style PropsnoLine inline style
iconStyleReact Style PropsnoIcon inline style
compactBooleannoadd padding to line

Text, Content && Languages supports

all the text used have to be added using a JSON object, so you can deploy the component in any language you want. you can also add the attribute "rtl" as true, to deploy in any rtl languages.

Get the data

to get the data modified if you use the onChange props, you can simply do :

const [data, setData] = useState(json);

useEffect(() => {
    console.log(data);
}, [data]);

...

<Tree treeData={data} onChange={setData} lineStyle={{color: "blue" }} />

Coming Features

  • Add Json language files
  • Add storybook for better documentation
  • Jest test
  • Css module
  • Checkbox select
  • Add new nodes
  • Add Multiple node selection
  • Drag and drop in React Tree View/Tree List
  • Sorting tree nodes
  • Tree node with custom icons
  • Delete & Edit animation
  • Style modal
  • Lazy loading
  • Better Readme and fix the spelling errors :)
  • Create a dedicated website
  • Create a slack and provide free support
  • Codes & Algorithmes optimisation
  • Writing contributing guidelines
  • Pull request template
  • Issue templates

feel free to ask for any feature or report a bug buy add in a new issue add new issue

License

Copyright (c) 2020 Temkit Sidali. Licensed under the MIT license.

Icons from www.flaticon.com From :

Dependencies :

0.0.1-beta.32

4 years ago

0.0.1-beta.34

4 years ago

0.0.1-beta.33

4 years ago

0.0.1-beta.29

4 years ago

0.0.1-beta.31

4 years ago

0.0.1-beta.30

4 years ago

0.0.1-beta.28

4 years ago

0.0.1-beta.27

4 years ago

0.0.1-beta.21

4 years ago

0.0.1-beta.20

4 years ago

0.0.1-beta.23

4 years ago

0.0.1-beta.18

4 years ago

0.0.1-beta.17

4 years ago

0.0.1-beta.25

4 years ago

0.0.1-beta.14

4 years ago

0.0.1-beta.24

4 years ago

0.0.1-beta.16

4 years ago

0.0.1-beta.15

4 years ago

0.0.1-beta.12

4 years ago

0.0.1-beta.13

4 years ago

0.0.1-beta.11

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago