infinite-autocomplete [CORE]
Pluggable infinite-autocomplete component that can accept any implementations of yours.
This autocomplete is like all these autocomplete out there, except that he is "Infinite" - which means that scrolling will fetch more data
Ease of use, flexable and written with TypeScript following the SOLID principles to guarantee a plug-in implementations so you can customize it's behaviours and inject it in any environment you want.
Popular Frameworks Wrappers
Live Demo (Default Style)
Install
npm i --save infinite-autocomplete
Basic Usage (Minimum Configuration)
import { InfiniteAutocomplete } from 'infinite-autocomplete';
new InfiniteAutocomplete(document.getElementById('test'), {
data: [
{ text: 'Islam Attrash', value: 1},
{ text: 'Shai Reznik', value: 2},
{ text: 'Uri Shaked', value: 3},
{ text: 'Salsabel Eawissat', value: 4}
]
});
new InfiniteAutocomplete(document.getElementById('test'), {
getDataFromApi: function(text, page, fetchSize) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve([ ..... ]);
}, 500);
})
}
});
Configurations
The configuration object will be exposed when initializing the infinite-autocomplete component as the second argument in the type-system typings, so it can help you know what configuration to apply.
value?: string;
data?: IOption[];
fetchSize?: number,
customizedInput?: IInputCompoenentConstructor;
customizedOptions?: IOptionsComponentConstructor;
onSelect?(selectedElement: EventTarget, selectedData: IOption);
onLoadingStateChange?(loadingState: boolean);
onError?(error: Error);
maxHeight?: string;
getDataFromApi?(text: string, page: number, fetchSize: number): Promise<any[]>;
customizedInput/customizedOptions Advanced configuration
Regards the custom implementations, they're targeting the two main component of this plugin, which is: InputComponent, OptionsComponent (The result)
For that you've two classes exported to help you manage correctly extending with your own classes
The Defaults implements these interfaces:
The IInputComponent interface can be defined as:
export interface IInputComponent {
render():string;
onInputChange?(inputElement:HTMLInputElement, value:string);
}
The IOptionsComponent interface can be defined as:
export interface IOptionsComponent {
listElementSelector:string;
render():string;
renderOption(option:IOption):string;
}
Examples
OR read Codes in "Examples" folder
Developer section
In the package.json scripts we've 4 basic tasks:
build
- Build the code once
build:watch
- Build the code and watch for changes [developement]
test
- Run tests once
test:watch
- Run tests and watch for changes [developement]