@telsystems/inputs
Version:
56 lines • 2.86 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as React from 'react';
import { SelectInput } from './SelectInput';
import { BasicDropDown } from './BasicDropDown';
var MultiSelect = (function (_super) {
__extends(MultiSelect, _super);
function MultiSelect() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, args) || this;
_this.onDropDownToggle = function (isDropDownActive) { return function () {
_this.setState({ isDropDownActive: isDropDownActive });
}; };
_this.state = {
isDropDownActive: false,
};
return _this;
}
MultiSelect.prototype.render = function () {
var _a = this.props, placeholder = _a.placeholder, disabled = _a.disabled, items = _a.items, selectedIndex = _a.selectedIndex, onItemClick = _a.onItemClick, groupName = _a.groupName, useCheckbox = _a.useCheckbox, clearSelectedButton = _a.clearSelectedButton, onClear = _a.onClear;
var isDropDownActive = this.state.isDropDownActive;
var selectedItems = this.getSelectedItems();
return (React.createElement(BasicDropDown, { items: items, useCheckbox: useCheckbox, clearSelectedButton: clearSelectedButton, onItemClick: onItemClick, groupName: groupName, selectedIndex: selectedIndex, hideAfterClick: false, onClear: onClear, onOpen: this.onDropDownToggle(true), onClose: this.onDropDownToggle(false) },
React.createElement(SelectInput, { active: isDropDownActive, disabled: disabled, placeholder: placeholder, value: selectedItems.joinedTitles, selectedCount: selectedItems.count })));
};
MultiSelect.prototype.getSelectedItems = function () {
var _a = this.props, groupName = _a.groupName, items = _a.items;
var initialValue = {
count: 0,
titles: [],
joinedTitles: ''
};
return items.reduce(function (res, item) {
if (item.selected) {
res.count++;
res.titles.push(item.content.title);
res.joinedTitles = res.titles.join(', ');
}
return res;
}, initialValue);
};
return MultiSelect;
}(React.PureComponent));
export { MultiSelect };
//# sourceMappingURL=MultiSelect.js.map