npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tree-render-viewer

v0.2.7

Published

Just render a recursion nodes

Downloads

57

Readme

js-standard-style

Tree-render-viewer

This component is used to render data in a tree structure. Better known as TreeMenu

Usage

To install run this command on terminal, need to have node and npm

$ npm install --save tree-render-viewer

Later import tree to your project

import { TreeWithSearchBar } from 'tree-render-viewer'

There are two kinds of components that you can export, <TreeWithSearchBar /> and <Tree />, the first contains a search toolbar with an expand/collapse all button, and the second only renders a tree.

It also imports this StyleSheet with predefined styles to show the tree, you want to change the style overwrite the classes.

import 'tree-render-viewer/build/_tree.css'

Props

<TreeWithSearchBar />

| Name | Function | |--|--| | treeData | Tree data is an array of objects, it must contain the necessary information of the tree, it is recommended that each object always have these attributes {id, name, children, parentId} those 4 are necessary for the rendering | | onNodeClick | onNodeClick is a function that receives the information of each node of the tree, by clicking on the label of some of the components that are rendered. onNodeClick (node: object) | | toggleAll | toggle All is a function, which changes the state of the collapsible, it is recommended to have a state called collapseAll: false and that this function changes to the new state. toggleAll () {this.setState ((prevState) => ({collapseAll: !prevState.collapseAll}))} | | idAttr | idAttr is a string, which suggests to the tree, to know what the key ID is on the tree | | labelAttr | labelAttr is a string, which suggests to the tree, to know what the key label is on the tree | | childrenAttr | childrenAttr is a string, which suggests to the tree, to know what the key children is in the tree | | collapseAll | collapseAll should be a state, in the implementation component. It is used to change the state of collapsables. | | handleChangeTextFilter | handleChangeTextFilter is a function, which returns the text that is changed in the input of the search bar. In this function the text that is obtained is returned, ideal to make a search in the tree, using some function of the handlers, or one of its own. | | contextual | contextual is a bool enabled the contextual menus for the nodes. | | ctxMenuItems | ctxMenuItems is an array of objects, you can pass handler functions for actions with contextual menus, they always receive an event and the data for the node. Example const add = (e, data) => console.log(data) // data is all the node info that is clicked | | labelForPlaceHolder | labelForPlaceHolder is an string, useful to change the label for placeholder of the searchbar input. |

Utils

There are added functions that can also be called, we call them handlers.

mapTree(@treeData: arrayOf(Object), @structure: Object)

This function receives the data, and a structure object from which to find the data and assign it a new key. First map a node, and added to the tree.

mapNode(@node: object, @structure: Object)

This function map a node for the tree

appendChildToFather(treeData: arrayOf(Object), child: Object, structure: Object)

This function, take all the array, and search by Id to ParentId the new child, mapped the node, and return a new tree with the new child append.

find(node: { name: root, children: arrayOf(Object) }, text)

This function return the path to the node is matched with the text.

forthebadge