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
Popular Frameworks Wrappers
Install
npm i -S infinite-autocomplete
Usage
import InfiniteAutocomplete from 'infinite-autocomplete';
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 }) => {
}
}, document.getElementById('app'));
InfiniteAutocomplete({
value: 'test',
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);
})
});
const firstCities = citiesInfinite(DOM1);
citiesInfinite(DOM2);
firstCities.setState({ fetchSize: 15 });
firstCities.destroy();
Options
{
value?: string;
data?: IOption[] | (inputText: string, fetchSize: number, page: number) => Promise<IOption[]>;
fetchSize?: number,
onSelect?(IOption);
}
Where IOption
stands for =>
interface IOption {
id: number | string;
text: string;
}