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-query-assist

v1.2.0

Published

A smart search bar for React

Downloads

38

Readme

React Query Assist

Travis npm package

A smart search bar for React that comes with built-in autocomplete and token visualization.

demo animation

What is a token?

A token is a key-value in a search query that contains an attribute and a value separated by a colon. e.g. some_attribute:some_enumeration

Getting Started

$ npm install -S react-query-assist emotion react-emotion

emotion is a peer dependency of this library to allow for easy custom styling.

import QueryAssist from 'react-query-assist'

const data = [
  {
    name: 'some_attribute',
    type: 'string',
    enumerations: ['enum1', 'enum2', 'enum3' /* ... */ ]
  }
]

export default function () {
  return (
    <QueryAssist
      data={data}
      onSubmit={console.log} />
  )
}

Autocomplete Data

The data prop should have the full list of autocomplete values. The data structure should be an array of attributes, and each attribute should have a name, type and enumerations of available values:

[
  {
    name: String,
    type: String,
    enumerations: Array or null
  }
]
  • name The value of the attribute in the token
  • type The data type of the enumerations (this determines available operators)
  • enumerations A list of available attribute values in the token

Wildcards and quoted values

If the attribute type is a string, there are two additional autocomplete values that may be suggested:

  • An appended wildcard will be suggested if the value is not blank
  • Wrapping the value in quotes will be suggested if there are no enumerations for the attribute

When will the dropdown open?

The autocomplete dropdown will automatically open when it detects a new word is being typed or an existing token is being edited. Note: Tokens are only valid if the attribute and value match an attribute and enumeration in the autocomplete data.

Operators

Each token in the query can have a number of operators, depending on the data type of the enumerations. They will change based on the type of the active attribute. The operator buttons in the dropdown will automatically update as you type, but they can also be clicked to toggle/update the value.

Available to all tokens

  • NEGATE -

Available to int or float tokens

  • GT >
  • LT <
  • GTE >=
  • LTE <=

Themes

The default styling is intentionally neutral so you can customize the look based on your own style guide. You can add custom styling to each specific element by using the inputProps, dropdownProps, selectorProps and listProps props. These objects will be merged into the props of each component. See the documentation for styled-system on how to customize styles with props.

Input Prop Extras

A few extra props are accepted for further styling on inputProps:

  • placeholderColor The placeholder text color for the input field
  • tokenColor The highlight color of the valid tokens

Keyboard

By default, keyboard helpers for the dropdown are enabled. Meaning when the dropdown is open, pressing the following keys will result in action:

  • up/down Will navigate through the autocomplete values
  • enter Will select the currently highlighted value and insert into the query
  • escape Will close the dropdown

Props

| Prop Name | Prop Type | Description | Default Value | | -----------| --------- | ----------- | ------------- | | data | object | Should return an array with the autocomplete data. | - | | onChange | function | Called with the updated value when the input changes. | - | | onSubmit | function | Called with the final value of the query when the enter key is pressed. Pressing enter will submit the query, but shift+enter will create a new line. | - | | defaultValue | string | The default value to pass to the input component. Will parse this value when mounted for any existing tokens. | - | | nameKey | string | The key to use for the attribute name in the data object. | name | | nameKeyIncludes | array | Keys to look at when determining a valid attribute name (e.g. if you want to display short names, but keep long names valid.) | ['name'] | | placeholder | string | The placeholder text to use for the input field. | Search | | collapseOnBlur | boolean | The input field automatically expands to fit the text, but if this is true, will collapse to one line when it is not in focus. | - | | keyboardHelpers | boolean | Whether to enable the keyboard helpers for the dropdown. | true | | inputProps | object | The props to use for the input component. See the themes section. | - | | dropdownProps | object | The props to use for the dropdown component. See the themes section. | - | | selectorProps | object | The props to use for the dropdown selector component. See the themes section. | - | | listProps | object | The props to use for the dropdown list component. See the themes section. | - | | footerComponent | function | Optionally append a footer component to the dropdown. Useful for adding a link to search documentation, etc. | - | | debug | boolean | Enables styling useful for debugging. | false |