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

@latticejs/tree

v1.0.1-beta.2

Published

List your data using a tree hierarchy.

Downloads

16

Readme

@latticejs/tree

List your data using a tree hierarchy.

Install

npm install @latticejs/tree

Usage

import React, { Component } from "react";
import Tree from "@latticejs/tree";

class App extends Component {
  state = {
    treeData: [
      {
        label: "index.js"
      },
      {
        label: "demo",
        children: [
          {
            label: "file1.txt"
          },
          {
            label: "file2.txt"
          },
          {
            label: "examples",
            children: [
              {
                label: "example1.js"
              }
            ]
          }
        ]
      }
    ]
  };

  render() {
    const { treeData } = this.state;
    return (
      <Tree
        data={treeData}
        onCheckItem={item => console.log("Check: ", item)}
        onUnfoldItem={item => console.log("Unfold: ", item)}
        onFoldItem={item => console.log("Fold: ", item)}
      />
    );
  }
}

API

treeData

array<object> | required

The data that will be parsed by the component used to render the tree structure. Input data is expected to have a tree-like structure (ie: to have children). This is the only required parameter.

expandedAll

boolean | defaults to false

Used to show all the item containers unfolded by default.

cascadeCheck

boolean | defaults to false

Used to indicate if check action should be dispatched to all the childrens recursively.

markUnfoldedParent

boolean | defaults to false

Used to indicate if unfolded parent(s) item(s) should be shown as selected.

showChecks

boolean | defaults to true

Set to false to hide checkboxes.

onCheckItem

function(check: boolean, items: [object]) | defaults to: noOp

Used as callback function to be called after one item is checked. It receives a boolean indicating checkbox state and the array of items affected (it can be recursive).

onUnfoldItem

function(item: object) | defaults to: noOp

The callback to be called after an unfold action happens. The function will be called with the affected item as a parameter.

onFoldItem

function(item: object) | defaults to: noOp

The callback to be called after a fold action happens. The function will be called with the affected item as a parameter.

secondaryActions

Array<Function> | defaults to: []

Used to display Material UI secondary actions on every item. Every function will be called with the current item as a parameter.

renderGenericItemCreator

function(props) | defaults to: renderGenericCreator

Used to control how to parse input data and render parent/childrens. Default fn renderGenericCreator, uses a recursive approach calling other two default functions for rendering child (TreeChild) and parents (TreeParent).

renderChildItem

function(props) | defaults to: TreeChild

Used to control how an item is rendered.

renderParentItem

function(props) | defaults to: TreeParent

Used to control how to render parent elements.

renderItemIcon

function({item: object, lvl: number, isExpanded: boolean}) | defaults to: TreeItemIcon

Used to control which icon render.

getItemKey :rotating_light:

function({item: object, lvl: number}) | defaults to: lattice-tree-${item.label}-${lvl}

Every item needs to have a unique key for maintaining sanity on the component internal state (checked and expanded). You can use this fn to overwrite the default key if your data structure is different to what is expected (see JSON Tree story).

FAQs

TBD