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-panel-search

v1.5.0

Published

A fast and lightweight component for searching and selecting hierarchical tree data.

Downloads

84

Readme

react-panel-search

by the Growth Lab at Harvard's Center for International Development

A fast and lightweight component for searching and selecting hierarchical tree data.

This package is part of Harvard Growth Lab’s portfolio of software packages, digital products and interactive data visualizations. To browse our entire portfolio, please visit The Viz Hub at growthlab.app. To learn more about our research, please visit Harvard Growth Lab’s home page.

NPM JavaScript Style Guide

View live example ↗

Install

npm install --save react-panel-search

Usage

import React from 'react'
import PanelSearch from 'react-panel-search'

const App = () => {

  ...

  return <PanelSearch data={data} />
}

export default App

The only required prop for react-panel-search is data, which is an array of type Datum. Several additional props allow for greater control and customization, as outlined below.

  • data: Datum[] An array of type Datum -
    • id: number | string A unique identifier for this particular datum
    • title: string The title that will be rendered
    • level: number | string | null The hierarchal level of this datum. The order of levels is automatically calculated based on value going from numeric high-to-low then alphabetical A-Z. If the value is set to null it will be considered a top-level item.
    • parent_id: number | string | null The id of the parent value, one level higher than the current datum's level. For a top level datum, this should be null
    • keywords (optional): string[] An array of strings that will also be checked when returning results
  • topLevelTitle (optional): string The title text that will appear in the panel when at the highest tier
  • onTraverseLevel (optional): (value: Datum, direction: 'asc' | 'desc') => void Callback function for returning the value of the node being traversed.
  • onSelect (optional): (value: Datum | null) => void Callback function for returning the selected value.
  • onHover (optional): (value: Datum | null) => void Callback function for returning the hovered value.
  • selectedValue (optional): Datum | null This can be used to both set an initially selected value or to clear the current value with an external component
  • disallowSelectionLevels (optional): Array<number | string> An array of values corresponding to levels of datum that should only serve as a hierarchal category and not be selectable.
  • defaultPlaceholderText (optional): string Placeholder text that will appear in the search field when empty
  • showCount (optional): boolean Display the number of child elements next to the parent name. Defaults to false.
  • resultsIdentation (optional): number Value, in rem, of how much to indent each tier of search results. Defaults to 1.
  • neverEmpty (optional): boolean If true, the dropdown can never be null and will always be equal to an acceptable value in the dataset. If no initial value is given via selectedValue then the first acceptable value in the dataset will be used. Defaults to false.
  • maxResults (optional): number Set the maximum number of results to display when the user enters a search term. By default no limit is set.
  • focusOnRender (optional): boolean Focus the dropdown as soon as it is rendered. Defaults to false.
  • noResultsFoundFormatter (optional): (value: string) => React.ReactNode Callback that receives the current search query and returns a React.ReactNode that will be shown when no results are found. Defaults to a string of No results found for { query }
  • matchingKeywordFormatter (optional): (matched: string[], rest: string[], query: string) => React.ReactNode Callback that receives the any matched keywords as well as the rest of the unmatched keywords for a given item that matches a query and returns a React.ReactNode that will be displayed underneath the restult. Defaults to null
  • onClose (optional): () => void Callback function for when the dropdown is closed.

Optional top level items

Top-level items can easily be added to react-panel-search. Top-level items are items that appear above the dropdowns title and contain no child elements. See the live example for an idea of what this looks like. To include top-level items, an individual datum sent in the data prop should have both the level and parent_id set to null.

Styling

react-panel-search comes out of the box with generic styling. However static class names have been added to all of the elements that make up the component to allow for full customizability of its appearance.

License

MIT © The President and Fellows of Harvard College