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

search-react-input

v1.2.4

Published

A lightweight customizable search component for react with a built in filter function.

Downloads

7

Readme

search-react-input

About

The motivation for making search-react-input came when I couldn't find a pre-made search bar for react that looked clean, was customizable, and worked well. I decided to make one myself and this is the result. The component is modeled after the search bar's of Google and Reddit and makes it incredibly easy to dynamically render routes, capture the search term, or anything else you'd like to do.

Installation

To install search-react-input run the following command in your terminal.

npm install search-react-input --save

Demo

https://codesandbox.io/s/search-react-input-demo-wkhj5

Example

import React from "react";
import { useState } from "react";
import Search from "search-react-input";

const countries = [
  { label: "Madagascar", value: "MG" },
  { label: "Malawi", value: "MW" },
  { label: "Malaysia", value: "MY" },
  { label: "Maldives", value: "MV" },
  { label: "Mali", value: "ML" },
  { label: "Malta", value: "MT" },
  { label: "Marshall Islands", value: "MH" },
  { label: "Martinique", value: "MQ" },
  { label: "Mauritania", value: "MR" },
  { label: "Mauritius", value: "MU" },
  { label: "Mayotte", value: "YT" },
  { label: "Mexico", value: "MX" },
];

const App = () => {
  const [capturedSearch, setCapturedSearch] = useState(null);

  return (
    <div className="App">
      <div
        className="container"
        style={{ marginTop: "5vh", display: "flex", justifyContent: "center" }}
      >
        <Search
          options={countries}
          onChange={(option, e) => setCapturedSearch(option)}
        />
      </div>
      <div style={{ marginTop: "25vh", textAlign: "center" }}>
        <h1>
          {capturedSearch && "Hello and welcome to " + capturedSearch.label}
        </h1>
      </div>
    </div>
  );
};

export default App;

Props

  • options - an array of label, value objects that the search bar filters through
  • onChange(option, e) - a function that returns the event and the selected option. If the option selected isn't in the option list, option.value will be null
  • placeholder - default text for the search bar, default is "Search"
  • className - apply a className to the input container, default is "search-bar-container"
  • width - specify a width for the search bar and the dropdown list, must be a string, default is "50vw"
  • spellcheck - specify whether the search bar includes red underlines for misspelled words, default is false
  • inputClassName - apply a className to the input, default is "search-bar"
  • hoverColor - specifies the color of the highlighted option, defualt is "#e9e9e9"
  • font - specifies the font, default is "Georama"
  • caseSensitive - specifies whether or not the search filter takes into account the case of characters, default is false

Styles

search-react-input comes with default styles that can be overridden by the creation of a new css files. Classnames for the respective jsx elements can be found in the github repository.

License

MIT Licensed. Copyright (c) Malachi Ashley 2021.