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-autocomplete-suggestion

v1.0.0

Published

React autocomplete component providing some default behaviors based on react-autosuggest.

Downloads

13

Readme

react-autocomplete-suggestion

React autocomplete component providing some default behaviors based on react-autosuggest.

NPM JavaScript Style Guide

Behavior

  • The component can notify when an exact match has been found even if the user did not select a suggestion

  • The exact match search for suggestion can be done in case sensitive or not

  • The component can keep the entered value even if no suggestion has been selected or clear it if free text functionality is disabled

  • The component does not filter the suggestions, it is developer's responsibility to implement the way it has to be filtered

  • A timer of default 200ms is set on fetch of new suggestions to avoid making the request on type of each letter (useful when the filtering of the suggestions is made in the backend)

  • An error property can be set to put the input component in red

  • A helper text can be set (useful to display error messages)

  • A custom theme can be set

  • A suggestion can be selected by click, enter or tab key

Install

npm install --save react-autocomplete-suggestion

Usage

import React, { Component } from 'react'

import Autocomplete from 'react-autocomplete-suggestion'

class Autocomplete extends Component {
  render () {
    return (
      <Autocomplete
        placeholder="Search for a country"
        label="country"
        freeTextEnabled
        ignoreCase={false}
        suggestions={suggestions}
        value={value}
        onFetchSuggestions={this.onFetchSuggestions}
        onSuggestionsClearRequested={this.onSuggestionsClearRequested}
        onChange={this.onChange}
        onSuggestionSelected={this.onSuggestionSelected}
        onExactMatchFound={this.onExactMatchFound}
        onBlur={this.onBlur}
        onFocus={this.onFocus}
        isInError
        helperText="An error occured"
        fetchTimeoutTimer={300}
        theme={{
          suggestionHighlighted: {
              transition: "all 300ms ease-in-out",
              backgroundColor: "#EBEBEB"
          }
        }}
       />
    )
  }
}

Props

| Prop | Type | Required | Default value | Description | | :--- | :--- | :--- | :---: | :--- | | theme | Object | | default theme | Prop to add or override the default theme | | placeholder | String | | | Add a placeholder to the input component | | label | String | | | Add a label to the input component | | value | String | | | Value to be displayed in the input component (useful when an autocomplete has already a value on page load for example) | | freeTextEnabled | Bool | | false | Avoid clearing the value of the input component if the user does not select a suggestion otherwise the value will be cleared | | ignoreCase | Bool | | true | Specify if the component should not ignore the case during his search for an exact match suggestion | | isInError | Bool | | false | Specify if the input component has to be in error, displayed in red | | helperText | Bool | | false | Display an helper text for the input component. Combined with isInError the helper text would be in red aswell | | fetchTimeoutTimer | Number | | 200 | The timer for the component to wait until calling the onFetchSuggestions function | | onSuggestionsClearRequested | Function | | | Function called when the suggestions has to be cleared | | onSuggestionSelected | Function | | | Function called when a suggestion has been selected | | onChange | Function | | | Function called when a change of value has been triggered | | onBlur | Function | | | Function called when a blur event has been triggered | | onFocus | Function | | | Function called when a focus event has been triggered | | onExactMatchFound | Function | | | Function called on initialization of the props inside the component and when an exact match has been found | | suggestions | Array | ✓ | [] | The suggestions, array of type { key: , value: "string } |

Default theme

  container: {
    position: 'relative'
  },

  suggestionsContainerOpen: {
    position: 'absolute',
    zIndex: 1,
    marginTop: 0,
    left: 0,
    right: 0
  },

  suggestion: {
    display: 'block',
    padding: 10,
    textAlign: 'left',
    cursor: 'pointer'
  },

  suggestionsList: {
    margin: 0,
    padding: 0,
    listStyleType: 'none'
  },

  suggestionHighlighted: {
    transition: 'all 300ms ease-in-out',
    backgroundColor: '#EBEBEB'
  },

  highlight: {
    fontWeight: 'bold'
  }

Possible theme properties

  container: {},
  containerOpen: {},
  input: {},
  inputOpen: {},
  inputFocused: {},
  suggestionsContainer: {},
  suggestionsContainerOpen: {},
  suggestionsList: {},
  suggestion: {},
  suggestionFirst: {},
  suggestionHighlighted: {},
  suggestionHighlighted: {},
  sectionContainer: {},
  sectionContainerFirst: {},
  sectionTitle: {}

Development - example project

For easy development you may use the example project:

  cd react-autocomple-suggestion && npm start    
  cd react-autocomple-suggestion/example && npm start    

License

MIT © Sukmanov Bogdan