0.5.0 • Published 4 years ago

@josros/autocomplete v0.5.0

Weekly downloads
6
License
BSD-3-Clause
Repository
gitlab
Last release
4 years ago

josros-autocomplete

A basic auto-completion Web Component.

Demo

Installation

  1. Install dependency

    npm install @josros/autocomplete --save

  2. ES6 import

    import "@josros/autocomplete";

  3. Use the component

    <josros-autocomplete
        label='Your label'
    ></josros-autocomplete>

Usage

Set data

Here is how you can set the items property on a normal website:

document.querySelectorAll('josros-autocomplete').forEach(element => {
    element.setAttribute('items', JSON.stringify([{'text': 'Hello'}, {'text': 'Hallo'}, {'text': 'Hola'}, {'text': 'Bonjour'}]));
})

Component Api

Properties

AttributeDescriptionTypeDefault
valueInitial value of the text fieldString""
labelLabel of the text fieldString""
itemsAuto completion items (suggestions)[{ text!: string, value?: any}][]
loadingToggles loading statebooleanfalse
max-suggestion-itemsMax. elements suggestednumber15
no-borderDisables borders around input text fieldbooleanfalse
outlineDisables outline around input text fieldbooleanfalse
highlight-bottom-lineEnables bottom line highlighting around input text field on focus (disabled if noBorder is defined)booleanfalse

Events

EventDescription
selectedFired as soon as a suggestion is selected (via keyboard or mouse)
autocomplete-inputFires on text changes
changedFires on internal input change event
blurredFires on internal input blur event
focussedFires on internal input focus event
enter-pressedFire as soon as enter is pressed on the input

CSS Custom Properties

NameDescriptionDefault
--josros-autocomplete--font-sizeThe font-size of the host1rem
--primary-colorPrimary color#000
--background-colorBackground colortransparent
--foreground-colorForeground colorrgba(0, 0, 0)
--item-background-colorBackground color of the suggestion itemslightgrey
--item-focus-colorBackground color of the suggestion items shown when input gets focus#e0e0e0
--loader-colorColor of the loading animationrgb(0, 136, 204)
--font-sizeFont size of the input text1.6em
--paddingPadding of the input1.2em 0em 0.4em 0em
--padding--labelPadding of the label above the input0em
--padding--suggestionPadding of a single suggestion box1.5em
--margin--suggestionsMargin of the whole suggestion container0em
--max-height--suggestionsMax height of the suggestion container20em
--input-default-borderBorder around the input text fieldnone
--input-default-border-bottomBottom border around the input text field0.1em solid var(--primary-color, grey)

Execution

# production build
npm run build

# run dev server at http://localhost:3000
npm run serve

# unit tests
npm run test:unit

# e2e tests
npm run test:e2e

# Lintting
npm run lint

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

BSD 3-Clause License

0.5.0

4 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago