UNPKG

@coreui/react-pro

Version:

UI Components Library for React.js

48 lines (45 loc) 2.48 kB
import React, { forwardRef } from 'react'; import classNames from '../../node_modules/classnames/index.js'; import PropTypes from 'prop-types'; var CMultiSelectSelection = 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: classNames('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'; export { CMultiSelectSelection }; //# sourceMappingURL=CMultiSelectSelection.js.map