All Projects → orbita-center → react-dadata-box

orbita-center / react-dadata-box

Licence: MIT License
React component for use DaData service API (suggestions)

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to react-dadata-box

autocomplete
Simple accessible autocomplete for vanilla javacript with support for remote & local data, ~3KB gzip
Stars: ✭ 38 (+52%)
Mutual labels:  autocomplete
Alter-Entity-Autocomplete
Drupal 8 module to alter Entity Autocomplete suggestion list.
Stars: ✭ 38 (+52%)
Mutual labels:  autocomplete
svelecte
Selectize-like component written in Svelte, also usable as custom-element 💪⚡
Stars: ✭ 121 (+384%)
Mutual labels:  autocomplete
tabnine-vim
Vim client for TabNine. https://vimawesome.com/plugin/tabnine-vim
Stars: ✭ 652 (+2508%)
Mutual labels:  autocomplete
vue-thailand-address
🇹🇭 Thai address input for Vue.
Stars: ✭ 44 (+76%)
Mutual labels:  autocomplete
AutoAddProblem
qduoj自动化加题-该项目已经停止更新
Stars: ✭ 23 (-8%)
Mutual labels:  autocomplete
prosemirror-autocomplete
Autocomplete suggestions for ProseMirror
Stars: ✭ 23 (-8%)
Mutual labels:  autocomplete
autocompletex
redis autocomplete for elixir
Stars: ✭ 22 (-12%)
Mutual labels:  autocomplete
vanilla-place-picker
Simple(vanilla) yet 'Do it all' place picker for your place picking needs in Android
Stars: ✭ 113 (+352%)
Mutual labels:  autocomplete
anaconda go
AnacondaGO adds autocompletion, linting and IDE features for Golang to your Sublime Text 3
Stars: ✭ 39 (+56%)
Mutual labels:  autocomplete
nama
Namespaced Aliases: organize and easily find aliases using autocomplete & namespacing
Stars: ✭ 26 (+4%)
Mutual labels:  autocomplete
autocomplete
Efficient and effective query auto-completion in C++.
Stars: ✭ 28 (+12%)
Mutual labels:  autocomplete
ng-sq-ui
Flexible and easily customizable UI-kit for Angular 11+
Stars: ✭ 99 (+296%)
Mutual labels:  autocomplete
clui
A command system with extra steps
Stars: ✭ 18 (-28%)
Mutual labels:  autocomplete
Elasticsearch-Autocomplete-API-Sample
Building Autocomplete API with Completion Suggester in ASP.NET Core sample project
Stars: ✭ 20 (-20%)
Mutual labels:  autocomplete
frontal
An Angular select/dropdown component
Stars: ✭ 20 (-20%)
Mutual labels:  autocomplete
pico8-emmylua-definitions
EmmyLua intellisense definitions for PICO-8
Stars: ✭ 25 (+0%)
Mutual labels:  autocomplete
idea-php-advanced-autocomplete
Plugin for PhpStorm IDE. Adds auto-completion support for various built-in PHP functions, where parameter is a string literal.
Stars: ✭ 57 (+128%)
Mutual labels:  autocomplete
mongoose-graphql-pagination
GraphQL cursor pagination (Relay-like) for Mongoose models.
Stars: ✭ 29 (+16%)
Mutual labels:  autocomplete
vue-single-select
single select dropdown with autocomplete
Stars: ✭ 43 (+72%)
Mutual labels:  autocomplete

react-dadata-box

GitHub npm react-dadata-box react-dadata-box npm npm peer dependency version npm peer dependency version code style: prettier

README LANGUAGE

Russian | English


React component for use DaData service API (suggestions) implemented as input with dropdown suggestions list, with auto-fetch data at user input. It provides user-friendly navigation from keyboard in addition to mouse click.

DaData service oriented to Russian Federation and russian-speaking users with russian queries. It use FIAS and KLADR and other national registry's and datasets, it provides suggestions only on russian language.

Demo

(at top of demo showed keystrokes captured by keycastr MacOS application)

DatData service is shareware, to use API you need token (person/organization). For personal use, you need to have Account, your token lets you to have 10000 free API call's per day.

Installation

npm install react-dadata-box

Usage

import ReactDadataBox from 'react-dadata-box';

// ...

<ReactDadataBox token="API_KEY" query="Москва" />

Properties

allowClear

allowClear?: boolean;

show 'clear value' ui control's (at clear - change handlers are called)


autocomplete

autocomplete?: 'on' | 'off';

autocomplete prop for input primitive


customActions

function that returns node (or nodes array) to place that as 'custom action' (each component from result placed in separated block at the end of list)

at v1.3.4 variant 'React.ReactNode' deprecated at types definition
since v1.3.5 variant 'React.ReactNode' will be deprecated from functionality

// {ResponseType<T>} where 'T' is one of FetchType (value placed at 'type' prop):
// {AddressQueryMode} 'address' | {PartyQueryMode} 'party' | {BankQueryMode} |
// {EmailQueryMode} 'email' | {FioQueryMode} 'fio' | {FmsUnitQueryMode} 'fms_unit';
// it determines DaData response object type
customActions?: ((suggestions: SpecificQueryModeResponse<T>[]) => React.ReactNode);

at versions < v1.3.4

// {DadataSuggestion} always typed responce as 'address' query { AddressResponseType }
customActions?: ((suggestions: DadataSuggestion[]) => React.ReactNode) | React.ReactNode;

customStyles

custom styling for embedded nodes: suggestion list, single suggestion, note and custom-action. Map-object, where key is native css classname of target node, and value is string interpreted as additional class name, or object with styles to place it into style property of target node primitive

  customStyles?: {
    'react-dadata__custom-action'?: string | React.CSSProperties;
    'react-dadata__suggestion'?: string | React.CSSProperties;
    'react-dadata__suggestion-note'?: string | React.CSSProperties;
    'react-dadata__suggestions'?: string | React.CSSProperties;
  }

customEndpoint

custom URI for fetching DaData service (when that placed behind the proxy, or service deployed locally in your infrastructure). It may be string that interpreted as path where available DaData service root (api call will added automatically) or it may be a object with 'host' or/and 'api' properties that interpreted respectively as DaData service root and api-call replacement

customEndpoint?: string | { host?: string; api?: string };

{
  host: 'https://suggestions.dadata.ru',
  api: 'suggestions/api/4_1/rs/suggest'
}

customInput

function that get as argument user input, for replace embedded input primitive by custom or other component with compatible props signature

interface BaseInputProps<T = HTMLInputElement> {
  autoComplete: boolean | 'off';
  className: string;
  onBlur: React.FocusEventHandler<T>;
  onChange: React.ChangeEventHandler<T>;
  onFocus: React.FocusEventHandler<T>;
  onKeyDown: React.KeyboardEventHandler<T>;
  placeholder: string;
  value: string;
}
...
customInput?: (props: BaseInputProps) => React.ReactNode;

debounce

debouncing interval for fetching data at user input in miliseconds

debounce?: number;

onChange

change/select event handler, called when user select suggestion by mouse click or Enter key from keyboard. Handler gets suggestion object as argument

onChange?: (suggestion: DadataSuggestion) => void;

onIdleOut

handler called when by current query, service return nothing variants of suggestion. Handler gets current query string as argument

 onIdleOut?: (query: string) => void;

payloadModifier

patch for payload object (that sended to DaData service). It may be function that returns patch object that will be spread on native generated payload, or it may be object that permanently spread on native payload at each call. (it allows use difficult filters and additional parameters available for DaData API but not implemented in interface of this component)

interface BasePayload {
  query: string;
  count?: number;
}
...
object | ((payload: BasePayload) => BasePayload & object);

placeholder

placeholder text for input (it placed into relevant prop of target input)

placeholder?: string;

query

query string for fetch suggestion from DaData service

query?: string;

showNote

show at the top of suggestions list with help note about available keyboard actions

showNote?: boolean;

silentQuery

special query string alternative that used when directly query prop is undefined or is empty string. It query will not be show in input node, but it determine of available suggestions in list at component on focus. (if directly query defined and not empty, this is ignored)

silentQuery?: string;

silentInit

function that may be used to autoselect from preventive fetched (by placed query or silentQuery), it called with list of fetched suggestions, and if it will return index, appropriate suggestion will be selected (all handlers fire as at user select)

silentInit?: (suggestions: DadataSuggestion[]) => number | undefined;

token

auth token for DaData service

token: string;

type

fetched suggestions type (declarative in DaData service terms).

It may be 'address', 'bank', 'email', 'fio' (last/first/middle names + gender detection), 'fms_unit' (branch/unit that issued Russian pasport)

type?: 'address' | 'party' | 'bank' | 'email' | 'fio' | 'fms_unit';

For correct infer types results of fetching, you need to manually setup type string to component generic parameter: 'address' is default typing it not need to be placed patently

// for example if we need to fetch 'party'
import { PartyResponseType } from 'react-dadata-box';
...
// if you setup 'party' as generic param - handlers as 'onChange' will be typed accordingly
// (suggestion: PartyResponseType) => void  in this sample
<ReactDadataBox<'party'>
    token={testToken}
    type='party'
    onChange={(suggestion: PartyResponseType) => setSample2(suggestion)}
    customActions={(suggestions) =>
        !suggestions.length && (
            <a href=" " onClick={idleAction}>
              произвольное действие
            </a>
        )
    }
/>

exported bulit-in types accordingly to type parameter

type param built-in type
'address' AddressResponseType (default)
'party' PartyResponseType
'bank' BankResponseType
'email' EmailResponseType
'fio' FioResponseType
'fms_unit' FmsUnitResponseType

forceOpenList

this property force the suggestions list will be permanently open (usually needed for debug)

forceOpenList?: boolean;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].