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

react-lazy-tree

v1.0.4

Published

A React Treeview Component

Downloads

32

Readme

react-lazy-tree

Recursively render tree data structures.

Control tree node markup, content and style.

Render lazily or greedily.

Specify vertical animation, CSS classes, initial active node, and more.

Demo

Please see demo site and example code.

Status

CircleCI Coverage Status dependencies Status npm License

Installation

npm install --save react-lazy-tree

Usage

import ReactLazyTree from 'react-lazy-tree'

...

<ReactLazyTree {...{
    data: tree,

    mapInitialActiveNode: (node) => node.label === 'Dresses',

    mapListClassName: ({ depth }) => {
        const exampleDepth = `example--depth-${depth}`;

        return `example ${exampleDepth}`;
    },

    mapListItemClassName: ({ isOnActivePath }) => {
        const modifier = isOnActivePath ? 'expanded' : 'contracted';
        const nodeIcon = `example__node--${modifier}`;

        return `example__node ${nodeIcon}`;
    },

    mapNodeContent: ({ depth, isActiveNode }) => {
        const labelDepth = `example__label--${depth}`;
        const isActive = isActiveNode ? 'example__label--active' : '';
        const className = `example__label ${labelDepth} ${isActive}`;

        return (
            <Label {...{
                className,
                text: node.label
            }}/>
        );
    },

    onActiveNodeChanged: activeNodeChangedHandler
}}/>

Props API

data - Tree data structure, or a collection of tree data structures.

  • Type: Object | Array
  • Required: Yes

mapNodeContent - Specify content, markup, and style for tree node presentation.

  • Type: Function
  • Required: Yes
  • Parameters:
    • depth: Number
    • index: Number
    • isActiveNode: Boolean
    • isLeafNode: Boolean
    • isOnActivePath: Boolean
    • node: Object
  • Return Type: String | JSX
  • Notes: Parameters are named (i.e. properties of an object).

childrenPropertyName - Specify data node children property name.

  • Type: String
  • Required: No
  • Default: children

mapListClassName - Specify HTML list (UL) class names.

  • Type: Function
  • Required: No
  • Parameters:
    • depth: Number
    • isOnActivePath: Boolean
    • node: Object
  • Return Type: String
  • Notes: Parameters are named (i.e. properties of an object).

mapListItemClassName - Specify HTML list-item (LI) class names.

  • Type: Function
  • Required: No
  • Parameters:
    • depth: Number
    • isActiveNode: Boolean
    • isLeafNode: Boolean
    • isOnActivePath: Boolean
    • node: Object
  • Return Type: String
  • Notes: Parameters are named (i.e. properties of an object).

mapInitialActiveNode - Specify a node that should be active initially.

  • Type: Function
  • Required: No
  • Parameters:
    • node: Object
  • Return Type: Boolean
  • Notes: Returns first match. Multiple active nodes not yet supported.

onActiveNodeChanged - Handle active node changes as a result of user interaction.

  • Type: Function
  • Required: No
  • Parameters:
    • activePath: String
    • depth: Number
    • e: Object
    • index: Number
    • node: Object
  • Notes: Parameters are named (i.e. properties of an object).

interactiveStartDepth - Specify at what depth the rendered tree should become interactive. Depth is zero based.

  • Type: Number
  • Required: No
  • Default: 0
  • Notes: To suppress interactivity entirely, specify -1.

shouldLazyRender - Specify should tree nodes be rendered when becoming visible or at mount time.

  • Type: Boolean
  • Required: No
  • Default: true

shouldShowAllNodes - Specify the entire tree should be rendered initially.

  • Type: Boolean
  • Required: No
  • Default : false
  • Notes: Overrides shouldLazyRender and mapInitialActiveNode

verticalAnimationConfig - Specify CSS transition duration and timing.

  • Type: Object
  • Required: No
  • Properties:
  • Default:
    • durationInMs: 300
    • timing: ease-in

Support

Please open an issue.

Examples

git clone https://github.com/ethanselzer/react-lazy-tree.git
cd react-lazy-tree/example
npm install
npm start

Development

git clone https://github.com/ethanselzer/react-lazy-tree.git
cd react-lazy-tree
npm install

See available commands:

npm run

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

You are awesome! ✨💫

License

MIT