0.0.4 • Published 6 years ago

@inthepocket/itp-rcc-autocomplete v0.0.4

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

ITP AutoComplete component

Built on downshift. For now, this is a controlled component only. You'll have to pass the input value and handle the changes and manage the autocomplete items.

Usage

$ npm install @inthepocket/itp-rcc-autocomplete

Import (Typescript)

import { default as AutoComplete } from '@inthepocket/itp-rcc-autocomplete';

Import (ES)

import AutoComplete from '@inthepocket/itp-rcc-autocomplete';

JSX

<AutoComplete
  items={[{ value: 'Amsterdam' }, { value: 'Brussels' }]}
  name="city"
  onChange={({ value }) => { ... }}
  placeholder="City"
  size="small"
  type="search"
  value="Amsterdam"
/>

API documentation

AutoComplete

<AutoComplete
  items={[{ value: 'Amsterdam' }, { value: 'Brussels' }]}
  name="city"
  onChange={({ value }) => { ... }}
  placeholder="City"
  size="small"
  type="search"
  value="Amsterdam"
/>
PropertyDescriptionTypeDefaultRequired
autoCompletetranslates into autocomplete attribute on input elementboolean'new-password'No
hasRandomizedNamerandomizes the input's name attribute as a workaround for Chrome's stubborn autofill / autocompletionbooleantrueNo
InputComponentInput componentReact.ReactNode<input />No
isDisabledDisabled statebooleanfalseNo
isLoadingLoading statebooleanfalseNo
itemsDropdown itemsArrayundefinedNo
itemsToStringList item toString methodFunctionitem => (item && item.value)'',No
LoaderLoading state componentReact.ReactNode<span>Loading</span>No
onChangeonChange event handlerFunctionundefinedNo
placeholderinput element placeholder textString''No
prefixCssPrefix for css classNamesString'auto-complete'No
size'small''default''large'String'default'No
stylesimported css module (if passed, prefixed classNames will be disabled), see styles propertyObjectnullNo
typeinput element type: 'email''text''search'String'text'No
valueinput element valueString''No

Classnames (when not using the styles property - css module)

.itp-autocomplete { ... } // container
.itp-autocomplete--isLoading { ... } // container loading state
.itp-autocomplete--isOpen { ... } // container dropdown-opened state
.itp-autocomplete__input { ... } // text input container
.itp-autocomplete__list { ... } // dropdown list
.itp-autocomplete__listItem { ... } // dropdown list item
.itp-autocomplete__listItem--isHighlighted { ... } // dropdown list item highlighted state
.itp-autocomplete__listItem--isSelected { ... } // dropdown list item selected state
.itp-autocomplete__loader { ... } // loader element (mounted when isLoading property is true)

Styles property (when using the styles property - css module)

PropertyDescriptionTypeDefaultRequired
autoCompleteAutocomplete containerstring-No
inputText input containerstring-No
isHighlightedDropdown list item highlighted statestring-No
isLoadingAutocomplete container loading statestring-No
isOpenAutocomplete container dropdown-opened statestring-No
isSelectedDropdown list item selected statestring-No
listDropdown liststring-Yes
listItemDropdown list itemstring-Yes
loaderLoader componentstring-No

The css module should look like this:

.autoComplete { ... }
.input { ... }
.isHighlighted { ... }
.isLoading { ... }
.isOpen { ... }
.isSelected { ... }
.list { ... }
.listItem { ... }
.loader { ... }

DisableBrowserAutoComplete

Disables html form input autocomplete and autofill for every child on Chrome and Firefox. Based on https://gist.github.com/niksumeiko/360164708c3b326bd1c8

import { DisableBrowserAutoComplete } from '@inthepocket/itp-rcc-autocomplete';

usage:

<DisableBrowserAutoComplete>
  <AutoComplete />
  <input />
</DisableBrowserAutoComplete>

Development

Installation

$ npm install

Test

$ npm run test

Build

Compiles the TypeScript source to ES5.

$ npm run build