lbry-desktop/src/renderer/component/cardMedia/view.jsx

50 lines
1 KiB
React
Raw Normal View History

import React from 'react';
2017-07-14 01:18:28 +02:00
class CardMedia extends React.PureComponent {
static AUTO_THUMB_CLASSES = [
'purple',
'red',
'pink',
'indigo',
'blue',
'light-blue',
'cyan',
'teal',
'green',
'yellow',
'orange',
];
componentWillMount() {
this.setState({
autoThumbClass:
CardMedia.AUTO_THUMB_CLASSES[
Math.floor(Math.random() * CardMedia.AUTO_THUMB_CLASSES.length)
],
});
}
2017-07-14 01:18:28 +02:00
render() {
const { title, thumbnail } = this.props;
const atClass = this.state.autoThumbClass;
2017-07-14 01:18:28 +02:00
if (thumbnail) {
return <div className="card__media" style={{ backgroundImage: `url('${thumbnail}')` }} />;
2017-07-14 01:18:28 +02:00
}
return (
<div className={`card__media card__media--autothumb ${atClass}`}>
<div className="card__autothumb__text">
{title &&
title
.replace(/\s+/g, '')
.substring(0, Math.min(title.replace(' ', '').length, 5))
.toUpperCase()}
</div>
</div>
);
2017-07-14 01:18:28 +02:00
}
}
export default CardMedia;