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

v1.2.0

Published

Light-weight quick-select menu with fuzzy search. Inspired by the vs-code command palette.

Downloads

14

Readme

React Quick-Select Menu

Light-weight quick-select menu with fuzzy search. Inspired by the vs-code command palette.

react-qsm demo

Table of Contents

Usage

The code below creates the demo you see above.

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import QuickSelectMenu from 'react-qsm';
import './react-qsm.css';

const sections = [
  {
    label: 'recently opened',
    items: [{ label: 'demo.js' }, { label: 'index.html' }]
  },
  {
    prefix: '>',
    label: 'recently used',
    items: [{ label: 'Preferences: Open User Settings' }, { label: 'Sync: Upload Settings' }]
  },
  {
    prefix: '>',
    label: 'other commands',
    items: [{ label: 'Add Cursor Above' }, { label: 'Add Cursor Below' }]
  },
  {
    prefix: '?',
    label: 'help',
    items: [{ label: '... Go to file' }, { label: '# Go to symbol in workspace' }]
  }
];

const onMenuItemSelect = item => console.log(item);

ReactDOM.render(
  <QuickSelectMenu defaultValue=">" onMenuItemSelect={onMenuItemSelect} menuSections={sections} />,
  document.getElementById('root')
);

Installation

yarn add react-qsm or npm install --save react-qsm

Props

| Prop | Type | Required | default | Description | | :---------------- | :------------------- | :-------------------------: | :------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | menuSections | array[menuSection] | ✓ | | Array of menuSections. These contain all of the data for the menuItems as well. | | onMenuItemSelect | function | | | Callback to fire when a menu item is selected. A menuItem will be passed into this callback as the only argument. | | onMenuItemFocus | function | | | Callback to fire when a menu item is focused. A menuItem will be passed into this callback as the only argument. | | defaultValue | string | | '' | Initial text value of the input. If provided, this would likely be a section prefix. | | maxItemsToDisplay | number | | Infinity | Maximum number of items to display in the quick select menu at once . | | renderInput | function | | | Custom input to render. If this prop is specified, you MUST also make use of the value prop(see below) and pass along the given props to the callback function of renderInput for react-qsm to function properly. IE: renderInput={props => <input {...myProps} {...props} />} | | value | string | if renderInput is specified | | The current value of the custom input supplied to renderInput. This should only be used when rendering a custom input. |

| className | string | | 'react-qsm' | Class name for the menu wrapper (div) | | inputClassName | string | | 'qsm-input' | Class name for the menu input (input) | | menuSectionWrapperClassName | string | | 'qsm-menu-sections-wrapper' | Class name for the menu sections wrapper (div) | | menuSectionClassName | string | | 'qsm-menu-section' | Class name for a menu section (div) | | menuSectionLabelClassName | string | | 'qsm-menu-section-label' | Class name for a menu label (h2) | | menuItemClassName | string | | 'qsm-menu-item | Class name for a menu item (li) |

menuSection Properties

| Prop | Type | Required | Description | | :----- | :-------------- | :------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | items | array[object] | ✓ | Array of item objects, which will be passed to onMenuItemSelect when selected. The only required property in these objects is label, but you can put whatever you want in here (ie id). | | label | string | | A label to display for your section. | | prefix | string | | A prefix to match at the beginning of the input field in order to display this section. If a prefix for a section is provided, the input box must match the prefix to display this section. If a prefix is provided for any section, sections without a prefix will not match when the input box matches the provided prefix. |

Styling

  • There is a minimal and clean stylesheet to get you on your feet quickly located at react-qsm/src/react-qsm.css.
  • If you have questions on ways to import a stylesheet, consult the documentation of your build system.

Future Plans

  • Ability to add components to both the left and right side of a menu item. This would allow things like icons to be displayed next to a label.