react-dadata
Version:
React-компонент для подсказок адресов, организаций и банков с помощью сервиса DaData.ru
65 lines (64 loc) • 3.39 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import React from 'react';
import { BaseSuggestions } from '../../base-suggestions';
import { HighlightWords } from '../../highlight-words';
var AddressSuggestions = /** @class */ (function (_super) {
__extends(AddressSuggestions, _super);
function AddressSuggestions() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.loadSuggestionsUrl = 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address';
_this.getLoadSuggestionsData = function () {
var _a = _this.props, count = _a.count, filterFromBound = _a.filterFromBound, filterToBound = _a.filterToBound, filterLocations = _a.filterLocations, filterLocationsBoost = _a.filterLocationsBoost, filterLanguage = _a.filterLanguage, filterRestrictValue = _a.filterRestrictValue;
var query = _this.state.query;
// TODO: Type this params
var requestPayload = {
query: query,
count: count || 10,
};
// Ограничение поиска по типу
if (filterFromBound && filterToBound) {
requestPayload.from_bound = { value: filterFromBound };
requestPayload.to_bound = { value: filterToBound };
}
// Язык подсказок
if (filterLanguage) {
requestPayload.language = filterLanguage;
}
// Сужение области поиска
if (filterLocations) {
requestPayload.locations = filterLocations;
}
// Приоритет города при ранжировании
if (filterLocationsBoost) {
requestPayload.locations_boost = filterLocationsBoost;
}
// @see https://confluence.hflabs.ru/pages/viewpage.action?pageId=1023737934
if (filterRestrictValue) {
requestPayload.restrict_value = true;
}
return requestPayload;
};
_this.renderOption = function (suggestion) {
var _a = _this.props, renderOption = _a.renderOption, highlightClassName = _a.highlightClassName;
var query = _this.state.query;
return renderOption ? (renderOption(suggestion, query)) : (React.createElement(HighlightWords, { highlightClassName: highlightClassName || 'react-dadata--highlighted', words: _this.getHighlightWords(), tagName: "mark", text: suggestion.value }));
};
return _this;
}
return AddressSuggestions;
}(BaseSuggestions));
export { AddressSuggestions };