UNPKG

@attivio/suit

Version:

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

129 lines (102 loc) 4.34 kB
'use strict'; exports.__esModule = true; exports.default = undefined; var _class, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _Button = require('react-bootstrap/lib/Button'); var _Button2 = _interopRequireDefault(_Button); var _DefaultImage = require('./DefaultImage'); var _DefaultImage2 = _interopRequireDefault(_DefaultImage); var _DocumentPreview = require('./DocumentPreview'); var _DocumentPreview2 = _interopRequireDefault(_DocumentPreview); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } /** * A component to display the thumbnail for a document. If the * thumbnail isn't set, then no image is displayed. If the URI * isn't valid, then the image is hidden rather than showing a * broken image in the browser. */ var DocumentThumbnail = (_temp = _class = function (_React$Component) { _inherits(DocumentThumbnail, _React$Component); // eslint-disable-line max-len function DocumentThumbnail(props) { _classCallCheck(this, DocumentThumbnail); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = { previewing: false }; _this.doPreview = _this.doPreview.bind(_this); _this.stopPreview = _this.stopPreview.bind(_this); return _this; } DocumentThumbnail.prototype.doPreview = function doPreview() { this.setState({ previewing: true }); }; DocumentThumbnail.prototype.stopPreview = function stopPreview() { this.setState({ previewing: false }); }; DocumentThumbnail.prototype.render = function render() { var haveImage = this.props.uri && this.props.uri.length > 0; var havePreview = this.props.previewUris && this.props.previewUris.length > 0; var previews = void 0; if (this.props.previewUris) { if (typeof previews === 'string') { previews = [previews]; } else { previews = this.props.previewUris; } } // We show something if there's a thumbnail URI or there are preview images... if (haveImage || havePreview) { var _uri = this.props.uri; if (_uri && _uri.startsWith('/')) { _uri = _uri.substring(1); } var imageComp = _uri ? _react2.default.createElement(_DefaultImage2.default, { src: _uri, className: 'attivio-search-result-preview img-responsive', style: { maxHeight: '100px' }, alt: 'Thumbnail' }) : _react2.default.createElement( _Button2.default, { bsSize: 'small' }, 'Preview' ); return _react2.default.createElement( 'div', null, _react2.default.createElement( 'a', { onClick: this.doPreview, role: 'button', tabIndex: 0 }, imageComp ), havePreview ? _react2.default.createElement(_DocumentPreview2.default, { uris: previews, show: this.state.previewing, onClose: this.stopPreview, docTitle: this.props.previewTitle }) : null ); } return null; // No thumbnail for this document }; return DocumentThumbnail; }(_react2.default.Component), _class.defaultProps = { uri: null, previewUris: [], previewTitle: null }, _class.displayName = 'DocumentThumbnail', _temp); exports.default = DocumentThumbnail; module.exports = exports['default'];