@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
84 lines (68 loc) • 3.09 kB
JavaScript
var _class, _temp;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React from 'react';
import Configurable from './Configurable';
/** Displays a currently applied facet filter. */
var NavbarFilter = (_temp = _class = function (_React$Component) {
_inherits(NavbarFilter, _React$Component);
function NavbarFilter(props) {
_classCallCheck(this, NavbarFilter);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.remove = _this.remove.bind(_this);
return _this;
}
NavbarFilter.prototype.processLabel = function processLabel(original) {
var _this2 = this;
if (original.includes('>>>')) {
var truncated = false;
var pieces = original.split('>>>').map(function (piece) {
var trimmed = piece.trim();
if (_this2.props.maxHierarchicalSegmentLength > 0 && trimmed.length > _this2.props.maxHierarchicalSegmentLength) {
trimmed = trimmed.substring(0, _this2.props.maxHierarchicalSegmentLength) + '\u2026'; // Include the ellipsis
truncated = true;
}
return trimmed;
});
var displayLabel = pieces.join(' > ');
if (truncated) {
var full = original.replace('>>>', '>');
return React.createElement(
'span',
{ title: full },
displayLabel
);
}
return displayLabel;
}
return original;
};
NavbarFilter.prototype.remove = function remove(event) {
this.props.removeCallback();
event.target.blur();
};
NavbarFilter.prototype.render = function render() {
var label = this.processLabel(this.props.bucketLabel);
return React.createElement(
'div',
{ className: 'attivio-globalmastnavbar-filter' },
this.props.facetName,
': \xA0',
React.createElement(
'a',
{
className: 'attivio-globalmastnavbar-filter-link attivio-icon-remove',
onClick: this.remove,
role: 'button',
tabIndex: 0
},
label
)
);
};
return NavbarFilter;
}(React.Component), _class.defaultProps = {
maxHierarchicalSegmentLength: 0
}, _class.displayName = 'NavbarFilter', _temp);
export default Configurable(NavbarFilter);