UNPKG

@bigfishtv/cockpit

Version:

80 lines (65 loc) 2.92 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, { Component } from 'react'; import classnames from 'classnames'; import Icon from '../Icon'; /** * Dumb asset cell for an image */ var ImageCell = (_temp = _class = function (_Component) { _inherits(ImageCell, _Component); function ImageCell(props) { _classCallCheck(this, ImageCell); var _this = _possibleConstructorReturn(this, _Component.call(this, props)); _this.state = { broken: false }; return _this; } ImageCell.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { if (this.props.url != nextProps.url) this.handleStatus(false); }; ImageCell.prototype.handleStatus = function handleStatus(broken) { this.setState({ broken: broken }); this.props.onStatus(broken); }; ImageCell.prototype.render = function render() { var _this2 = this; var broken = this.state.broken; var _props = this.props, queued = _props.queued, url = _props.url, mediaRatio = _props.mediaRatio; return React.createElement( 'div', { className: classnames('media', mediaRatio && 'media-' + mediaRatio, !broken && 'media-transparent-pattern') }, broken ? React.createElement( 'div', { className: 'media-inner' }, React.createElement(Icon, { name: 'image-broken', size: 24 }), React.createElement( 'span', { className: 'media-inner-title' }, 'Error loading file' ) ) : queued ? React.createElement( 'div', { className: 'media-inner' }, React.createElement(Icon, { name: 'access-time', size: 24 }) ) : React.createElement('img', { src: url, onError: function onError(e) { return _this2.handleStatus(true); }, onLoad: function onLoad(e) { return _this2.handleStatus(false); } }) ); }; return ImageCell; }(Component), _class.defaultProps = { url: 'http://placehold.it/300x200', mediaRatio: '1', onStatus: function onStatus() { return console.warn('[ImageCell] no onStatus prop'); }, queued: false }, _temp); export { ImageCell as default };