Code Monkey home page Code Monkey logo

autosuggest-web-component's Introduction

autosuggest-web-component

Installation

npm install -- save autosuggest-web-component

Import

After installing the web component via package manager. Import it into your application.

import "autosuggest-web-component"

A polyfill (webcomponentjs) is applied along with the import.

Example Usage

The base requirement to use this component is to create the element, pass in an array of (string) words that you wish to autosuggest against, and append the element to the DOM.

import "autosuggest-web-component";
import words from "./words";

const autosuggest = document.createElement("bh-autosuggest");
autosuggest.words = words;
document.body.appendChild(autosuggest);

Configuration Options

Configuration can be passed in via the options property.

Default configuration options (can all be overridden):

autosuggest.options = {
  // input placeholder
  placeholder: "Type here...",

  // css template string for input field
  inputCss: `{
    border: 1px solid black;
    padding: 10px;
    font-size: 14px;
    box-shadow: 1px 1px 1px 1px;
    width: calc(100% - 20px);
    margin: 10px;
    margin-bottom: 0px;
  }`,

  // css template string for suggestion box
  suggestionCss: `{
    background-color: #f2f2f2;
    margin: 10px;
    margin-top: 0px;
  }`,

  // css template string for individual result
  resultCss: `{
    margin: 0;
    padding: 10px;
    overflow: hidden;
    border-bottom: 1px solid lightgray;
  }`,

  // debounce time in ms
  debounce: 0,
};

Disclaimer

Client side autosuggestion is great for small data sets but might not be the best solution for larger data sets (i.e. entire language dictionaries).

autosuggest-web-component's People

Contributors

boweihan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.