UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

124 lines (104 loc) 4.06 kB
var _class2, _temp; 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } import React from 'react'; export var DataPairInfo = /** * The type of the value which, if present, is used to add * an indicator for well-known categories. */ function DataPairInfo(label, value) { var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; _classCallCheck(this, DataPairInfo); this.label = label; this.value = value; this.type = type; } /** The value for the pair. */ /** The label shown describing the value. */ ; /** * Display a list of name/value pairs, with optional category type indicators * in a side-by-side, two-column list format. */ var DataPairs = (_temp = _class2 = function (_React$Component) { _inherits(DataPairs, _React$Component); function DataPairs(props) { _classCallCheck(this, DataPairs); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.showAll = _this.showAll.bind(_this); _this.state = { showingAll: false }; return _this; } DataPairs.prototype.showAll = function showAll() { if (this.showAllLink) { this.showAllLink.blur(); } this.setState({ showingAll: true }); }; DataPairs.prototype.render = function render() { var _this2 = this; var rows = []; var haveTruncated = false; this.props.pairs.forEach(function (pair) { var value = pair.value; if (!_this2.state.showingAll && pair.value.length > DataPairs.MAX_CHARACTERS) { haveTruncated = true; value = pair.value.substr(0, 100) + '\u2026'; } if (pair.type && pair.type !== '') { // Have a real type, use that class name var className = 'attivio-labeldata-2col-search-results-entity attivio-labeldata-2col-search-results-' + pair.type; rows.push(React.createElement( 'dt', { className: className, key: pair.label + '-label' }, pair.label )); } else { // Simple label rows.push(React.createElement( 'dt', { key: pair.label + '-label' }, pair.label )); } rows.push(React.createElement( 'dd', { key: pair.label + '-value' }, value )); }); if (!this.state.showingAll && haveTruncated) { // Add the show all link... rows.push(React.createElement('dt', { key: 'allData-label' })); rows.push(React.createElement( 'dd', { key: 'allData-value' }, React.createElement( 'a', { className: 'attivio-labeldata-2col-search-results-more', onClick: this.showAll, role: 'button', tabIndex: 0, ref: function ref(c) { _this2.showAllLink = c; } }, 'All data\u2026' ) )); } return React.createElement( 'dl', { className: 'attivio-labeldata-2col attivio-labeldata-2col-search-results' }, rows ); }; return DataPairs; }(React.Component), _class2.displayName = 'DataPairs', _class2.MAX_CHARACTERS = 100, _temp); export { DataPairs as default }; DataPairs.DataPairInfo = DataPairInfo;