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

@crave/farmblocks-search-field

v3.8.25

Published

Search input with results dropdown list

Downloads

1,947

Readme

logo-farmblocks

Farmblocks Search Field

Search input with results dropdown list.
The main difference between this and the Select component is that while Select searches among the available items, this component gives you the ability to fetch for new items on an external API.

Installation

npm install @crave/farmblocks-search-field

Usage

import React, { Component } from "react";
import { render } from "react-dom";
import Select from "@crave/farmblocks-search-field";

const items = [
  { value: "1", label: "Apple" },
  { value: "2", label: "Banana" },
  { value: "3", label: "Pear" },
];

class App extends Component {
  render() {
    return (
      <Select
        placeholder="Select fruit"
        label="Fruit"
        items={items}
        onSearchChange={value => console.log("onSearchChange", value)}
        onChange={value => console.log("onChange", value)}
      />
    );
  }
}

render(<App />, document.getElementById("root"));

API

  • items (Array)

    Items to be rendered as options The elements of the array should follow this shape: { value: String, label: String, image: String(optional) }

  • value (String)

    Selected option. It's expected that items have an element with the same value

  • footer (React node)

    Component to render at the menu bottom

  • width (Number or String) = 200

    Width of the component

  • maxMenuHeight (Number or String) = 353

    Maximum height of the menu. After that, the menu will have a scroll bar

  • debounceDelay (Number) = 500

    Time in milliseconds to wait for new key presses before dispatching onSearchChange

  • onSearchChange ((value:String) => void) = noop

    Function to handle changes in the search term. It usually uses the value to search in an external API and updates the items prop with the received results

  • onScrollReachEnd (() => void) = noop

    Function to handle the end of the scroll. Useful for pagination

  • onBeforeChange ((args:Object) => void) = noop

    Function that runs before onChange. It has the ability to decide wether onChange will be triggered or not. When this prop is not defined, onChange will trigger immediately

    The arguments are sent as an Object, so you can destructure it to get only the needed ones. It wil contain:

    • value (String)

      The value for the selected item

    • selectedItem (Object)

      The whole selected item

    • inputDOMElement (Element)

      The input element. You can use it to give back the focus after the uses click on an item

    • proceed ((item: Object) => void)

      Function to trigger the onChange handler. Optionally, you can modify the item that onChange will pass

  • onChange ((value:String, item:Object) => void) = noop

    Function to handle selection of an item

  • valueKey (String) = "value"

    Custom name to be used as the items value key

  • labelKey (String) = "label"

    Custom name to be used as the items label key

  • imageKey (String) = "image"

    Custom name to be used as the items image key

Note: to listen to clicks on items or footer, use onMouseDown event over onClick.

License

MIT