Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

infinite-autocomplete

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

infinite-autocomplete

infinite-autocomplete

  • 4.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
71
increased by57.78%
Maintainers
1
Weekly downloads
 
Created
Source

infinite-autocomplete

The infinite-autocomplete component is like all these autocomplete out there, except that he is "Infinite" - which means that scrolling will fetch more data

Ease of use, written totally in Pure Functional Programming mindset!

Live Demo

Install

npm i -S infinite-autocomplete

Usage

import InfiniteAutocomplete from 'infinite-autocomplete';

// Static data source
InfiniteAutocomplete({
    data: [
        { text: 'Islam Attrash', value: 1},
        { text: 'Shai Reznik', value: 2},
        { text: 'Uri Shaked', value: 3},
        { text: 'Salsabel Eawissat', value: 4}
    ],
    onSelect: ({ id, text }) => {
        // do something useful!
    }
}, document.getElementById('app'));

// Dynamic data source
InfiniteAutocomplete({
    value: 'test', // input initial value
    data: (text, page, fetchSize) => {
        return new Promise(function(resolve) {
            fetch(`http://localhost:5000/data?text=${text}&page=${page}&fetchSize=${fetchSize}`)
            .then((response) => response.json())
            .then((options) => resolve(options))
        });
    }
}, document.getElementById('app'));

InfiniteAutocomplete function is also a curried function! which means that we can set a specific configuration and render the autocomplete with these configurations for multiple DOM nodes!

const citiesInfinite = InfiniteAutocomplete({
    data: () => new Promise((resolve) => {
        ...
        resolve(cities);
    })
});

// Some page
const firstCities = citiesInfinite(DOM1);

// Another page
citiesInfinite(DOM2);

// You can update the options by passing the new slice into setState
firstCities.setState({ fetchSize: 15 });

// You can destroy the component by calling destroy
firstCities.destroy();

Options

{
    /**
     * current value
     */
    value?: string;
    /**
     * data source
     */
    data?: IOption[] | (inputText: string, fetchSize: number, page: number) => Promise<IOption[]>;
    /**
     * Chunk fetch size
     */
    fetchSize?: number,
    /**
     * on-select event output handler when choosing an option
     */
    onSelect?(IOption);
}

Where IOption stands for =>

interface IOption {
    id: number | string;
    text: string;
}

FAQs

Package last updated on 03 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc