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-treeviewselect

v1.0.4

Published

A react based select control where the drop down is a tree view.

Downloads

21

Readme

react-treeviewselect

A react based select control where the drop down is a tree view.

React/JS is not my first language, so open to suggestions for improvements as I have not seen a useful version of this control elsewhere, so I want this to be robust.

Features

  • Attempts to be WAI-ARIA compliant compliant although not thoroughly tested. Support for ARIA attributes and keyboard interactions. Issues welcome
  • Mobile friendly
  • Full control over item rendering.
  • Can use with any structure, as it uses callbacks for composing tree.
  • Typescript typings.

Installation

yarn add react-treeviewselect

or

npm install react-treeviewselect --save

Basic Usage

import { TreeViewSelect } from "react-treeviewselect";

function renderManagerLink(manager) {
    return <span
        key={manager.id}
    >
        {manager.name}
    </span>;
}

function renderSelectedManager(manager) {
    return <div className="d-inline-block">{manager.name}</div>;
}

function getChildren(item) {
    return item.reports;
}

function getParent(item) {
    return item.manager;
}

function getKey(item) {
    return item.id;
}

function onSelectedItemChange(item: IManager) {
    console.log(item.name);
}

class Example extends React.Component {
  constructor(props) {
        super(props);

        this.state = {};
        this.onSelectedItemChange = this.onSelectedItemChange.bind(this);
    }

  render() {

    return (
      <TreeViewSelect
                        style={{ width: "20rem" }}
                        defaultCollapsed={1}
                        renderSelectedItem={renderSelectedManager}
                        selectedItem={manager}
                        item={hierarchy.manager}
                        getChildren={getChildren}
                        getParent={getParent}
                        getKey={getKey}
                        renderItem={renderManagerLink}
                        onSelectedItemChange={onSelectedItemChange}
                    />
    );
  }
}

Props

| Prop | Type | Required | Description | | :--- | :--- | :---: | :--- | | className | String | | Set a class name for outer TreeViewSelect element. | | style | Object | | Sets a style for TreeViewSelect, can be useful to set a fixed width. | | defaultCollapsed | Number | | Use this to define what level should default to collapsed. Can be useful for big trees to keep just the first few levels open by default. | | renderSelectedItem | Function | ✓ | How do we render the selected item. | | selectedItem | Object | ✓ | Currently selected item. | | item | Object | ✓ | Root node of the tree. | | getChildren | Function | ✓ | Used on a node to get the children. This allows a flexible data structure as input. | | getParent | Function | ✓ | Get parent for an item. This is used to make sure that selected items are not collapsed. | | getKey | Function | ✓ | Get the key for a node. Used for item equivalency as well as for React key. | | renderItem | Function | ✓ | Used to render an item in the treeview. | | onSelectedItemChange | Function | ✓ | Callback when the selected item changes. |

License

MIT