Coder Social home page Coder Social logo

attrash-islam / infinite-autocomplete Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 3.0 1.13 MB

infinite-autocomplete component - Written in Pure Functional Programming mindset

License: MIT License

JavaScript 95.22% HTML 4.78%
autocomplete infinite input auto-complete web-component infinite-scroll

infinite-autocomplete's Introduction

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';

// 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;
}

infinite-autocomplete's People

Contributors

attrash-islam avatar idanb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

infinite-autocomplete's Issues

Remove 100% width from infinite-autocomplete-options-wrapper

User may want to see the options based on the inner text length

Typeahead don't use full width in options (Not related to the input width)

Whenever user prefer to full width he can override the class infinite-autocomplete-options-wrapper

Support process.env.NODE_ENV

Plugins importing this plugin should import the debug.js (With sourcemaps) or index.js (Without sourcemaps) depends on:

webpack.DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify('production')
})

Think of exposing default for DX

Think of exposing default implementation so developer can extend it, without being forced to implement all the method that he don't want to override

For example: I'd want to override onInputChange without modifying the render default template. In 2.0.0 release you'll be forced to implement all interface again

set config changes

It should support dynamic changing dynamic input and optjons, with removing past DOM elements, and unbinding the bounded events

maxHeight may disable scrolling

Determining the max height for the options component is so important since we don't want to overflow from the scrollable area by configuring something bigger than the whole chunk height.

I think that the proper way is to calculate it based on the chunk element height.

This calculated height should be verified in buildOptions.. function, and if the passed maxHeight is bigger than the calculated then user receive warning message in console, and the calculated will override the wrong passed argument

Up/Down keys navigation

Allow press up/down keys to navigate through the options, and pressing enter will select the chosen one

Angry pushed div BUG

main wrapper with relative position, and results-wrapper (options-wrapper) with absolute position and width: 100%

Fix typo in IOptionsComponent.d.ts

or it can be a class selector (or id selector) .myClass/#myClass which is

Should be:

or it can be a class selector (or id selector) .myClass/#myId which is

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.