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-awesome-combobox

v1.1.0

Published

A combobox for React

Downloads

4

Readme

React-Awesome-Combobox · GitHub license npm version Build Status

React-Combobox is a React library for building autocomplete searchbox in an easy and fully customizable way.

Installation

npm install --save react-awesome-combobox

Preview

Usage

import { Combobox } from 'react-awesome-combobox';
const data=[
    {name: 'Marouen Mhiri', age: 40, car: {carMake: 'VW', year: '2018'}},
    {name: 'Tanja Bernhardt', age: 35, car: {carMake: 'Audi', year: '2017'}},
    {name: 'Adam Mhiri', age: 5, car: {carMake: 'Mercedes', year: '2018'}},
    {name: 'Hanna Miriam Mhiri', age: 3, car: {carMake: 'VW', year: '2016'}},
    {name: 'Jasmin Gallas', age: 12, car: {carMake: 'Skoda', year: '2018'}},
    {name: 'Sofia M`hiri', age: 10, car: {carMake: 'Seat', year: '2015'}},
    {name: 'Sofiene Attia', age: 20, car: {carMake: 'Skoda', year: '2018'}},
];
return (
    <Combobox
        placeholder='Placeholder'
        bgColor='cadetBlue'
        data={data}
        filterProperty='car/carMake'
        display={{
            seperator: ',',
            fields: ['name', 'age', 'car/carMake', 'car/year']
        }}
        highlight
        itemHeight={40}
        visibleItems={4}
        onSelectItem={(sugg) => console.log(sugg)}
    />
);

or (with a simple array of strings)

import { Combobox } from 'react-awesome-combobox';
const names = ['John', 'Marouen', 'Tanja', 'Hanna', 'Sofia', 'Adam', 'Rafif'];
return (
    <Combobox
        placeholder='Search for name...'
        bgColor='green'
        data={names}
        itemHeight={50}
        visibleItems={3}
        onSelectItem={(sugg) => console.log(sugg)}/>
    </div>
);

Props

| Prop | Type | Required | Description | | :--- | :--- | :---: | :--- | | data | Array | ✓ | These are the suggestions that will be displayed. Items can take an arbitrary shape. | | plaeholder | String | | will display the placeholder of the input field. | | bgColor | String | | When set it will style the background color of the suggestions when moved using keyboard arrows. Default is "#6B9FCE". | | filterProperty | String | ✓* | When Implement it to teach Autosuggest what should be the input value when suggestion is clicked. | | display | Object | | Gives the possibility to customize the suggestions. If your data is an array of objects and you filter for a specific property but want to display others. With this property it is possible (See Example here) | | highlight | Boolean | | highlights the occurences in the suggestions using the mark tag. | | itemHeight | Number | | specifies the items height of the suggestions dropdown. | | visibleItems | Number | | sets the limit of the suggestions to see and make the dropdown scrollable. | | onSelectItem | Function | | A Callback function that will be triggered after selecting a suggestion. This function has as parameter the selected object.

data [REQUIRED] the list of the suggestions to filter. This can be a simple array of i.e. strings, numbers, booleans... or an array of objects. This property is REQUIRED.

placeholder [OPTIONAL] the placeholder to show in the input field.

bgColor [OPTIONAL] the Background color of the suggestions when visited with keyboard up/down-arrows.

filterProperty [OPTIONAL] the Property to search for in the list of the suggestions. This property works with the property data when it's an array of objects. filterProperty can contain '/'-sign to specify the property levels to search for.

display [OPTIONAL] Object specifying which property of the searched object should appear in the search result and how they should be seperated. display property when used should have this shape:

display = {{
    // or any other sign '|', ':', ' '...
    seperator: ',', 
    // Array of existing object properties
    fields: ['name', 'car/year'] 
}}

highlight [OPTIONAL] when true the found search string will be highlighted using the <mark />-html Tag

itemHeight [OPTIONAL] a number specifies the height of the suggestions boxes (this number will be used as pixel height) - default = 40

visibleItems [OPTIONAL] a maximum number of suggestions to see. The rest will be reached when scrolled or by tapping UP/Down Keys. Default = 4

onSelectItem [OPTIONAL] a callback function which will be called after a selection of a suggestion took place. this function recieves a suggestion item as parameter. I.e. use onSelectItem={(sugg) => console.log(sugg)} to see the result.

License

React-awesome-combobox is MIT licensed.