diff --git a/src/common/MetadataItem/MetadataItem.js b/src/common/MetadataItem/MetadataItem.js new file mode 100644 index 000000000..cd9dfd39b --- /dev/null +++ b/src/common/MetadataItem/MetadataItem.js @@ -0,0 +1,118 @@ +import React, { PureComponent } from 'react'; +import PropTypes from 'prop-types'; +import Icon, { dataUrl as iconDataUrl } from 'stremio-icons/dom'; +import colors from 'stremio-colors'; +import { RELATIVE_POSTER_SIZE } from './constants'; +import styles from './styles'; + +class MetadataItem extends PureComponent { + getPosterSize = () => { + switch (this.props.posterShape) { + case 'poster': + return { + width: RELATIVE_POSTER_SIZE, + height: RELATIVE_POSTER_SIZE * 1.464 + }; + case 'landscape': + return { + width: RELATIVE_POSTER_SIZE / 0.5625, + height: RELATIVE_POSTER_SIZE + }; + default: + return { + width: RELATIVE_POSTER_SIZE, + height: RELATIVE_POSTER_SIZE + }; + } + } + + getPlaceholderIcon = () => { + switch (this.props.type) { + case 'tv': + return 'ic_tv'; + case 'series': + return 'ic_series'; + case 'channel': + return 'ic_channels'; + default: + return 'ic_movies'; + } + } + + renderInCinemaLabel() { + if (!this.props.isInCinema) { + return null; + } + + return ( +
+ + IN CINEMA +
+ ); + } + + renderName() { + if (this.props.name.length === 0) { + return null; + } + + return ( + {this.props.name} + ); + } + + renderYear() { + if (this.props.year.length === 0) { + return null; + } + + return ( + {this.props.year} + ); + } + + render() { + const posterSize = this.getPosterSize(); + const contentContainerStyle = { + width: posterSize.width + }; + const placeholderIcon = this.getPlaceholderIcon(); + const placeholderIconUrl = iconDataUrl({ icon: placeholderIcon, fill: colors.accent, width: Math.round(RELATIVE_POSTER_SIZE / 2.2) }); + const imageStyle = { + height: posterSize.height, + backgroundImage: `url(${this.props.posterUrl}), url('${placeholderIconUrl}')` + }; + + return ( +
+
+
+ {this.renderInCinemaLabel()} +
+ {this.renderName()} + {this.renderYear()} +
+
+ ); + } +} + +MetadataItem.propTypes = { + type: PropTypes.oneOf(['movie', 'series', 'channel', 'tv', 'other']).isRequired, + name: PropTypes.string.isRequired, + posterUrl: PropTypes.string.isRequired, + posterShape: PropTypes.oneOf(['poster', 'landscape', 'square']).isRequired, + isInCinema: PropTypes.bool.isRequired, + year: PropTypes.string.isRequired +}; +MetadataItem.defaultProps = { + type: 'other', + name: '', + posterUrl: '', + posterShape: 'poster', + isInCinema: false, + year: '' +}; + +export default MetadataItem; diff --git a/src/common/MetadataItem/constants.json b/src/common/MetadataItem/constants.json new file mode 100644 index 000000000..b477ccb3d --- /dev/null +++ b/src/common/MetadataItem/constants.json @@ -0,0 +1,3 @@ +{ + "RELATIVE_POSTER_SIZE": 138 +} \ No newline at end of file diff --git a/src/common/MetadataItem/index.js b/src/common/MetadataItem/index.js new file mode 100644 index 000000000..aac1d12c5 --- /dev/null +++ b/src/common/MetadataItem/index.js @@ -0,0 +1,3 @@ +import MetadataItem from './MetadataItem'; + +export default MetadataItem; diff --git a/src/common/MetadataItem/styles.less b/src/common/MetadataItem/styles.less new file mode 100644 index 000000000..a7a046aad --- /dev/null +++ b/src/common/MetadataItem/styles.less @@ -0,0 +1,63 @@ +@import 'stremio-colors'; +.root-container { + padding: 1px; + display: inline-block; + .content-container { + display: flex; + flex-direction: column; + cursor: pointer; + .poster { + width: 100%; + display: flex; + align-items: flex-end; + background-size: cover, auto; + background-repeat: no-repeat; + background-position: center; + background-origin: border-box; + background-color: @colordarkest; + .in-cinema-container { + width: 100%; + height: 26px; + display: flex; + align-items: center; + justify-content: center; + background-color: @colormedium; + .in-cinema-icon { + height: 100%; + width: 12px; + fill: @colorwhite; + margin-right: 6px; + } + .in-cinema-label { + font-size: 13px; + text-transform: uppercase; + color: @colorwhite; + } + } + } + .name, .year { + width: 100%; + display: inline-block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + .name { + font-size: 12px; + color: @colorwhite; + } + .year { + font-size: 11px; + color: @colorwhite80; + } + } + &:hover { + background: @colorwhite; + .name { + color: @colorblack; + } + .year { + color: @colorneutral; + } + } +} \ No newline at end of file diff --git a/src/common/index.js b/src/common/index.js index c792e5abf..cfc2af87f 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -2,10 +2,12 @@ import Checkbox from './Checkbox'; import Popup from './Popup'; import NavBar from './NavBar'; import Modal from './Modal'; +import MetadataItem from './MetadataItem'; export { Checkbox, Popup, NavBar, - Modal + Modal, + MetadataItem };