@coreui/react-pro
Version:
UI Components Library for React.js
50 lines (46 loc) • 2.52 kB
JavaScript
var React = require('react');
var index = require('../../node_modules/classnames/index.js');
var PropTypes = require('prop-types');
var CMultiSelectSelection = React.forwardRef(function (_a, ref) {
var children = _a.children, multiple = _a.multiple, placeholder = _a.placeholder, onRemove = _a.onRemove, search = _a.search, _b = _a.selected, selected = _b === void 0 ? [] : _b, selectionType = _a.selectionType, selectionTypeCounterText = _a.selectionTypeCounterText;
return (React.createElement("span", { className: index.default('form-multi-select-selection', {
'form-multi-select-selection-tags': multiple && selectionType === 'tags',
}), ref: ref },
multiple && selectionType === 'counter' && !search && selected.length === 0 && placeholder,
multiple &&
selectionType === 'counter' &&
!search &&
selected.length > 0 &&
"".concat(selected.length, " ").concat(selectionTypeCounterText),
multiple &&
selectionType === 'tags' &&
selected.map(function (option, index) {
if (selectionType === 'tags') {
return (React.createElement("span", { className: "form-multi-select-tag", key: index },
option.label,
!option.disabled && (React.createElement("button", { className: "form-multi-select-tag-delete", type: "button", "aria-label": "Close", onClick: function () { return onRemove && onRemove(option); } }))));
}
return;
}),
multiple &&
selectionType === 'text' &&
selected.map(function (option, index) { return (React.createElement("span", { key: index },
option.label,
index === selected.length - 1 ? '' : ',',
"\u00A0")); }),
!multiple && !search && selected.map(function (option) { return option.label; })[0],
children));
});
CMultiSelectSelection.propTypes = {
multiple: PropTypes.bool,
onRemove: PropTypes.func,
placeholder: PropTypes.string,
search: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['external'])]),
selected: PropTypes.array,
selectionType: PropTypes.oneOf(['counter', 'tags', 'text']),
selectionTypeCounterText: PropTypes.string,
};
CMultiSelectSelection.displayName = 'CMultiSelectSelection';
exports.CMultiSelectSelection = CMultiSelectSelection;
//# sourceMappingURL=CMultiSelectSelection.js.map
;