UNPKG

@attivio/suit

Version:

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

112 lines (93 loc) 3.81 kB
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 Button from 'react-bootstrap/lib/Button'; import DefaultImage from './DefaultImage'; import DocumentPreview from './DocumentPreview'; /** * 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 ? React.createElement(DefaultImage, { src: _uri, className: 'attivio-search-result-preview img-responsive', style: { maxHeight: '100px' }, alt: 'Thumbnail' }) : React.createElement( Button, { bsSize: 'small' }, 'Preview' ); return React.createElement( 'div', null, React.createElement( 'a', { onClick: this.doPreview, role: 'button', tabIndex: 0 }, imageComp ), havePreview ? React.createElement(DocumentPreview, { uris: previews, show: this.state.previewing, onClose: this.stopPreview, docTitle: this.props.previewTitle }) : null ); } return null; // No thumbnail for this document }; return DocumentThumbnail; }(React.Component), _class.defaultProps = { uri: null, previewUris: [], previewTitle: null }, _class.displayName = 'DocumentThumbnail', _temp); export { DocumentThumbnail as default };