UNPKG

@sb1/ffe-account-selector-react

Version:

Selector for bank accounts with autocomplete.

47 lines (46 loc) 3.76 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React from 'react'; import { SearchableDropdownMultiSelect } from '@sb1/ffe-searchable-dropdown-react'; import { formatIncompleteAccountNumber } from '../format'; import { searchMatcherIgnoringAccountNumberFormatting } from '../searchMatcherIgnoringAccountNumberFormatting'; import { texts } from '../texts'; import { AccountMultiselectOptionBody } from './AccountMultiselectOptionBody'; export var AccountSelectorMulti = function (_a) { var _b; var id = _a.id, className = _a.className, _c = _a.locale, locale = _c === void 0 ? 'nb' : _c, selectedAccounts = _a.selectedAccounts, _d = _a.showBalance, showBalance = _d === void 0 ? false : _d, noMatches = _a.noMatches, accounts = _a.accounts, onChange = _a.onChange, labelledById = _a.labelledById, OptionBody = _a.optionBody, postListElement = _a.postListElement, onReset = _a.onReset, inputProps = _a.inputProps, _e = _a.formatAccountNumber, formatAccountNumber = _e === void 0 ? true : _e, ariaInvalid = _a.ariaInvalid, onOpen = _a.onOpen, onClose = _a.onClose, maxRenderedDropdownElements = _a.maxRenderedDropdownElements, rest = __rest(_a, ["id", "className", "locale", "selectedAccounts", "showBalance", "noMatches", "accounts", "onChange", "labelledById", "optionBody", "postListElement", "onReset", "inputProps", "formatAccountNumber", "ariaInvalid", "onOpen", "onClose", "maxRenderedDropdownElements"]); var formatter = formatAccountNumber ? formatIncompleteAccountNumber : undefined; return (React.createElement(SearchableDropdownMultiSelect, { id: id, labelledById: labelledById, inputProps: inputProps, dropdownAttributes: showBalance ? ['name', 'accountNumber', 'balance'] : ['name', 'accountNumber'], postListElement: postListElement, dropdownList: accounts, noMatch: noMatches !== null && noMatches !== void 0 ? noMatches : { text: texts[locale].noMatch }, formatter: formatter, onChange: onChange, searchAttributes: ['name', 'accountNumber'], locale: locale, optionBody: function (_a) { var item = _a.item, isHighlighted = _a.isHighlighted, restOptionBody = __rest(_a, ["item", "isHighlighted"]); if (OptionBody) { return (React.createElement(OptionBody, __assign({ item: item, isHighlighted: isHighlighted }, restOptionBody))); } return (React.createElement(AccountMultiselectOptionBody, { item: item, isHighlighted: isHighlighted, locale: locale, showBalance: showBalance })); }, ariaInvalid: (_b = rest['aria-invalid']) !== null && _b !== void 0 ? _b : ariaInvalid, searchMatcher: searchMatcherIgnoringAccountNumberFormatting, selectedItems: selectedAccounts, onOpen: onOpen, onClose: onClose, maxRenderedDropdownElements: maxRenderedDropdownElements, isEqual: function (accountA, accountB) { return accountA.accountNumber === accountB.accountNumber; } })); };