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

ink-quicksearch

v0.3.2

Published

Quicksearch Input Component for Ink

Downloads

4

Readme

Ink Quicksearch

QuickSearch Component for Ink

Install

$ npm install ink-quicksearch

Quickstart

npm install
npm start

Usage

const {h, render, Component} = require('ink');
const QuickSearch = require('ink-quicksearch');

class Demo extends Component {
    render() {
        const props = {
            items: [
                {value: 1, label: 'Animal'},
                {value: 3, label: 'Antilope'},
                {value: 2, label: 'Animation'},
                {value: 0, label: 'Animate'},
                {value: 4, label: 'Arizona'},
                {value: 5, label: 'Aria'},
                {value: 6, label: 'Arid'},
            ],
            onSelect: item => {
                // `item` = { label: 'First', value: 'first' }
            };,
        };

        return <QuickSearch {...props} />
    }
}

render(<Demo/>);

Props

items

Type: array Default: []

Items to display in a list. Each item must be an object and have at least a label prop.

onSelect

Type: function

Function to call when user selects an item. Item object is passed to that function as an argument.

focus

Type: boolean Default: true

Listen to user's input. Useful in case there are multiple input components at the same time and input must be "routed" to a specific component.

caseSensitive

Type: boolean Default: false

Whether or not quicksearch matching will be case sensitive

limit

Type: int Default: 0

Limit the number of rows to display. 0 is unlimited Use in conjunction with https://www.npmjs.com/package/term-size

forceMatchingQuery

Type: bool Default: false

If set to true, queries that return no results are not allowed. In particular, if previous query X returns at least one result and X + new_character would not, query will not update to X + new_character

clearQueryChars

Type: Array(char) Default: ['\u0015', '\u0017'] (Ctrl + u | Ctrl + w)

Key Combinations that will clear the query. ch follows the keypress API process.stdin.on('keypress', (ch, key) => {})

initialSelectionIndex

Type: int Default: 0

Selection index when the component is initially rendered or when props.items changes. Can be set together with new props.items to automatically select an option.

indicatorComponent

Type: Component Props:

  • isSelected: boolean
  • isHighlighted: boolean
  • item: Object - The corresponding object inside props.items

Custom component to override the default indicator component (default - arrow).

itemComponent

Type: Component Props:

  • isSelected: boolean
  • isHighlighted: boolean
  • item: Object - The corresponding object inside props.items
  • children: any

Custom component to override the default item style (default - selection coloring).

highlightComponent

Type: Component Props:

  • isSelected: boolean
  • isHighlighted: boolean
  • item: Object - The corresponding object inside props.items
  • children: any

Custom component to override the default highlight style (default - background highlight).

statusComponent

Type: Component Props:

  • hasMatch: boolean
  • children: any

Custom component to override the status component (default - current query).

Default Components

// For the following four, whitespace is important
const IndicatorComponent = ({isSelected}) => {
    return <Color hex="#00FF00">{isSelected ? '>' : ' '} </Color>;
};

const ItemComponent = ({isSelected, children}) => (
    <Color hex={isSelected ? '#00FF00' : ''}>{children}</Color>
);

const HighlightComponent = ({children}) => (
    <Color bgHex="#6C71C4">{children}</Color>
);

const StatusComponent = ({hasMatch, children}) => (
    <Color hex={hasMatch ? '#00FF00' : '#FF0000'}>{children}</Color>
);