Skip to content

Commit 13fdabe

Browse files
authored
Merge pull request #64 from orbita-center/v1.3.7
V1.3.7
2 parents 39a98fa + 35f62e7 commit 13fdabe

File tree

9 files changed

+329
-384
lines changed

9 files changed

+329
-384
lines changed

README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,19 @@ function that returns node (or nodes array) to place that as 'custom action'
6666
at v1.3.4 variant 'React.ReactNode' deprecated at types definition
6767
since v1.3.5 variant 'React.ReactNode' will be deprecated from functionality
6868
```typescript
69-
// {ResponseType<T>} where 'T' is one of FetchType (value placed at 'type' prop):
70-
// {AddressQueryMode} 'address' | {PartyQueryMode} 'party' | {BankQueryMode} |
71-
// {EmailQueryMode} 'email' | {FioQueryMode} 'fio' | {FmsUnitQueryMode} 'fms_unit';
72-
// it determines DaData response object type
73-
customActions?: ((suggestions: SpecificQueryModeResponse<T>[]) => React.ReactNode);
69+
import { SpecificQueryModeResponse, FetchType } from 'react-dadata-box';
70+
71+
// {SpecificQueryModeResponse<T>} where 'T' is one of FetchType (value placed at 'type' prop):
72+
// {AddressQueryMode} 'address' | {CountryQueryMode} 'country' | {PartyQueryMode} 'party' |
73+
// {BankQueryMode} 'bank' | {EmailQueryMode} 'email' | {FioQueryMode} 'fio' |
74+
// {FmsUnitQueryMode} 'fms_unit';
75+
76+
// SpecificQueryModeResponse<FetchType> is generic that returned one of corresponding AbstractResponseType
77+
// AbstractResponseType and any of response types is built-in and may be impoted from library
78+
type AbstractResponseType = CountryResponseType | PartyResponseType | BankResponseType | EmailResponseType | FioResponseType | FmsUnitResponseType
79+
80+
// type of 'suggestions' wiil be infered automaticaliy from fetch type and it will be SpecificQueryModeResponse<T>[]
81+
customActions?: ((suggestions: SpecificQueryModeResponse<FetchType>[]) => React.ReactNode);
7482
```
7583
at versions < v1.3.4
7684
```typescript
@@ -129,8 +137,22 @@ debounce?: number;
129137
___
130138
#### onChange ![](https://img.shields.io/badge/optional-green)
131139
change/select event handler, called when user select suggestion by mouse click or Enter key from keyboard. Handler gets suggestion object as argument
140+
132141
```typescript
133-
onChange?: (suggestion: DadataSuggestion) => void;
142+
import { SpecificQueryModeResponse, FetchType } from 'react-dadata-box';
143+
144+
// {SpecificQueryModeResponse<T>} where 'T' is one of FetchType (value placed at 'type' prop):
145+
// {AddressQueryMode} 'address' | {CountryQueryMode} 'country' | {PartyQueryMode} 'party' |
146+
// {BankQueryMode} 'bank' | {EmailQueryMode} 'email' | {FioQueryMode} 'fio' |
147+
// {FmsUnitQueryMode} 'fms_unit';
148+
149+
// SpecificQueryModeResponse<FetchType> is generic that returned one of corresponding AbstractResponseType
150+
// AbstractResponseType and any of response types is built-in and may be impoted from library
151+
152+
type AbstractResponseType = CountryResponseType | PartyResponseType | BankResponseType | EmailResponseType | FioResponseType | FmsUnitResponseType
153+
154+
// type of 'suggestion' wiil be infered automaticaliy from fetch type and it will be SpecificQueryModeResponse<T>[]
155+
onChange ? : (suggestion: SpecificQueryModeResponse<FetchType>) => void;
134156
```
135157
___
136158
#### onIdleOut ![](https://img.shields.io/badge/optional-green)
@@ -189,24 +211,30 @@ ___
189211
#### type ![](https://img.shields.io/badge/optional-green) ![](https://img.shields.io/badge/default-"address"-lightgrey)
190212
fetched suggestions type (declarative in DaData service terms).
191213

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

194216
```typescript
195-
type?: 'address' | 'party' | 'bank' | 'email' | 'fio' | 'fms_unit';
217+
type FetchType = AddressQueryMode | CountryQueryMode | PartyQueryMode | BankQueryMode | EmailQueryMode | FioQueryMode | FmsUnitQueryMode;
218+
// => 'address' (default) | 'country' | 'party' | 'bank' | 'email' | 'fio' | 'fms_unit'
219+
type?: FetchType;
196220
```
197221
![](https://img.shields.io/badge/ATTENTION-red) [![](https://img.shields.io/badge/TypeScript-types-blue?logo=typescript)](https://www.typescriptlang.org/)
198222
For correct infer types results of fetching, you need to manually setup type string to component generic parameter:
199223
*'address'* is default typing it not need to be placed patently
224+
225+
[![](https://img.shields.io/badge/CodeSandbox-playground-black?logo=codesandbox)](https://codesandbox.io/s/react-dadata-box-example-customactions-ox2li)
200226
```typescript
201227
// for example if we need to fetch 'party'
202-
import { PartyResponseType } from 'react-dadata-box';
228+
import { SpecificQueryModeResponse } from 'react-dadata-box';
203229
...
204230
// if you setup 'party' as generic param - handlers as 'onChange' will be typed accordingly
205231
// (suggestion: PartyResponseType) => void in this sample
206232
<ReactDadataBox<'party'>
207233
token={testToken}
208234
type='party'
209-
onChange={(suggestion: PartyResponseType) => setSample2(suggestion)}
235+
// 'suggestion' type will be automatically infered as : SpecificQueryModeResponse<'party'>
236+
onChange={(suggestion) => setSample2(suggestion)}
237+
// 'suggestion' type will be automatically infered as : SpecificQueryModeResponse<'party'>
210238
customActions={(suggestions) =>
211239
!suggestions.length && (
212240
<a href=" " onClick={idleAction}>
@@ -221,6 +249,7 @@ exported bulit-in types accordingly to type parameter
221249
| **type param** | **built-in type** |
222250
| ------------- | ------------- |
223251
| 'address' | AddressResponseType (default) |
252+
| 'country' | CountryResponseType |
224253
| 'party' | PartyResponseType |
225254
| 'bank' | BankResponseType |
226255
| 'email' | EmailResponseType |

README.ru.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ ___
6666
в версии v1.3.4 вариант определения как 'React.ReactNode' упразднен в определении типов
6767
насиная с версии v1.3.5 вариант определения как 'React.ReactNode' будет упразднен технически
6868
```typescript
69-
// {ResponseType<T>} где 'T' это один из FetchType (значение передаваемое в пропс 'type'):
70-
// {AddressQueryMode} 'address' | {PartyQueryMode} 'party' | {BankQueryMode} |
71-
// {EmailQueryMode} 'email' | {FioQueryMode} 'fio' | {FmsUnitQueryMode} 'fms_unit';
69+
import { SpecificQueryModeResponse, FetchType } from 'react-dadata-box';
70+
71+
// {SpecificQueryModeResponse<T>} где 'T' это один из FetchType (значение передаваемое в пропс 'type'):
72+
// {AddressQueryMode} 'address' | {CountryQueryMode} 'country' | {PartyQueryMode} 'party' |
73+
// {BankQueryMode} | {EmailQueryMode} 'email' | {FioQueryMode} 'fio' |
74+
// {FmsUnitQueryMode} 'fms_unit';
7275
// это определяет типизацию структуры соотв. ответа от DaData по специфическому type
73-
customActions?: ((suggestions: SpecificQueryModeResponse<T>[]) => React.ReactNode);
76+
77+
// SpecificQueryModeResponse<FetchType> дженерик который выводит один из AbstractResponseType
78+
// AbstractResponseType и любой их отдельных типов этого Union являются встроенными типами и могут быть импортированы под нужды описания типов из библиотеки
79+
type AbstractResponseType = CountryResponseType | PartyResponseType | BankResponseType | EmailResponseType | FioResponseType | FmsUnitResponseType
80+
81+
// тип 'suggestions' будет выведен автоматически на основе установленного типа запроса (type property)
82+
// и он будет являться SpecificQueryModeResponse<T>[] где 'T' соотв. (type property: FetchType)
83+
customActions?: ((suggestions: SpecificQueryModeResponse<FetchType>[]) => React.ReactNode);
7484
```
7585
at versions < v1.3.4
7686
```typescript
@@ -131,7 +141,21 @@ ___
131141
#### onChange ![](https://img.shields.io/badge/optional-green)
132142
обработчик события выбора подсказки пользователем (клик по элементу в списке или Enter для элемента который в данный момент выделен), принимает объект отражающий выбранную 'подсказку' в качестве аргумента
133143
```typescript
134-
onChange?: (suggestion: DadataSuggestion) => void;
144+
import { SpecificQueryModeResponse, FetchType } from 'react-dadata-box';
145+
146+
// {SpecificQueryModeResponse<T>} где 'T' это один из FetchType (значение передаваемое в пропс 'type'):
147+
// {AddressQueryMode} 'address' | {CountryQueryMode} 'country' | {PartyQueryMode} 'party' |
148+
// {BankQueryMode} | {EmailQueryMode} 'email' | {FioQueryMode} 'fio' |
149+
// {FmsUnitQueryMode} 'fms_unit';
150+
// это определяет типизацию структуры соотв. ответа от DaData по специфическому type
151+
152+
// SpecificQueryModeResponse<FetchType> дженерик который выводит один из AbstractResponseType
153+
// AbstractResponseType и любой их отдельных типов этого Union являются встроенными типами и могут быть импортированы под нужды описания типов из библиотеки
154+
type AbstractResponseType = CountryResponseType | PartyResponseType | BankResponseType | EmailResponseType | FioResponseType | FmsUnitResponseType
155+
156+
// тип 'suggestion' будет выведен автоматически на основе установленного типа запроса (type property)
157+
// и он будет являться SpecificQueryModeResponse<T>[] где 'T' соотв. (type property: FetchType)
158+
onChange?: (suggestion: SpecificQueryModeResponse<FetchType>) => void;
135159
```
136160
___
137161
#### onIdleOut ![](https://img.shields.io/badge/optional-green)
@@ -190,32 +214,38 @@ token: string;
190214
```
191215
___
192216
#### type ![](https://img.shields.io/badge/optional-green) ![](https://img.shields.io/badge/default-"address"-lightgrey)
193-
тип запрашиваемых "подсказок" (в терминологии сервиса DaData): 'address' (адреса), 'bank' (банки), 'email' (электронная почта), 'fio' (ФИО + определение пола), 'fms_unit' (отделение выдавшее паспорт РФ)
217+
тип запрашиваемых "подсказок" (в терминологии сервиса DaData): 'address' (адреса), 'country' (страны), 'bank' (банки), 'email' (электронная почта), 'fio' (ФИО + определение пола), 'fms_unit' (отделение выдавшее паспорт РФ)
194218

195219
```typescript
196-
type?: 'address' | 'party' | 'bank' | 'email' | 'fio' | 'fms_unit';
220+
type FetchType = AddressQueryMode | CountryQueryMode | PartyQueryMode | BankQueryMode | EmailQueryMode | FioQueryMode | FmsUnitQueryMode;
221+
// => 'address' (default) | 'country' | 'party' | 'bank' | 'email' | 'fio' | 'fms_unit'
222+
type?: FetchType;
197223
```
198224
![](https://img.shields.io/badge/ATTENTION-red) [![](https://img.shields.io/badge/TypeScript-types-blue?logo=typescript)](https://www.typescriptlang.org/)
199225
Для корректного вывода типов описывающих структуры которыми отвечает сервер DaData в соответствии с указанным типом сервиса (параметр **type**) -
200226
необходимо передать этот тип (соотв. строку) как параметр дженерика.
201227

202228
*'address'* является значение по умолчанию - и не требует явной установки
229+
230+
[![](https://img.shields.io/badge/CodeSandbox-playground-black?logo=codesandbox)](https://codesandbox.io/s/react-dadata-box-example-customactions-ox2li)
203231
```typescript
204232
// н/п если мы используем сервис 'party'
205-
import { PartyResponseType } from 'react-dadata-box';
233+
import { SpecificQueryModeResponse } from 'react-dadata-box';
206234
...
207235
// после установки 'party' как дженерик параметра компонента - обработчики такие как 'onChange' начинают типизироваться соотв.
208236
// выводится тип (suggestion: PartyResponseType) => void в данном примере
209237
<ReactDadataBox<'party'>
210238
token={testToken}
211239
type='party'
212-
onChange={(suggestion: PartyResponseType) => setSample2(suggestion)}
240+
// тип 'suggestion' будет выведен автоматически как SpecificQueryModeResponse<'party'>
241+
onChange={(suggestion) => setSample2(suggestion)}
242+
// тип 'suggestion' будет выведен автоматически как SpecificQueryModeResponse<'party'>
213243
customActions={(suggestions) =>
214-
!suggestions.length && (
215-
<a href=" " onClick={idleAction}>
216-
произвольное действие
217-
</a>
218-
)
244+
!suggestions.length && (
245+
<a href=" " onClick={idleAction}>
246+
произвольное действие
247+
</a>
248+
)
219249
}
220250
/>
221251
```
@@ -224,6 +254,7 @@ import { PartyResponseType } from 'react-dadata-box';
224254
| **type param** | **built-in type** |
225255
| ------------- | ------------- |
226256
| 'address' | AddressResponseType (default) |
257+
| 'country' | CountryResponseType |
227258
| 'party' | PartyResponseType |
228259
| 'bank' | BankResponseType |
229260
| 'email' | EmailResponseType |

dist/index.css

100755100644
File mode changed.

0 commit comments

Comments
 (0)