0.0.2-development • Published 6 years ago

react-abstract-tree v0.0.2-development

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

AbstractTree

A simple way create hierarchical components in React JS.

Hierarchical ui-components are ubiquitous in interfaces. Every time it takes much efforts to build and walking the tree. Different ui elements under the hood may contain the same hierarchical structure. Therefore the universal AbstractTree component is created. It doesn't depend on the view. You decide how it will look!

You can create CheckboxTree component and so on based on AbstractTree.

Examples

Checkout the examples (add examples) how creates yours components.

About

As you already know, stateless React component is pure function which depends on props and return view:

f(props) -> view 

AbstractTree is also pure function, but you should define renderTree callback which return your view (jsx):

A(props, renderTree) -> renderTree(tree, handleClick) -> view

You can read about renderTree below.

Props

PropertyTypeDescriptionDefault
nodesArrayRequired. Specifies the tree nodes and their children.
renderTreeFunctionRequired. (tree, handleNodeClick) => React.Node. It render your hierarchical component
valueArrayAn array of checked nodes ids.[]
nameStringA Tree nametree
onChangeFunction({event, value}) => void. value has array of new checked nodes idsundefined
onErrorFunction({suggestedValue, message, type}) => void. Error handlerundefined

Node Type

Individual nodes within the nodes property can have the following structure:

PropertyTypeDescription
labelstirngRequired. The node's label.
idstringRequired. The node's id.
childrenarrayAn array of child nodes.

renderTree

add docs