react-toolbox/components/card/CardMedia.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

import React, { PropTypes, Component } from 'react';
2015-11-21 22:17:18 +03:00
import ClassNames from 'classnames';
import style from './style';
class CardMedia extends Component {
static propTypes = {
aspectRatio: PropTypes.oneOf([ 'wide', 'square' ]),
2015-11-23 07:19:26 +03:00
children: PropTypes.any,
className: PropTypes.string,
color: PropTypes.string,
2015-11-22 04:43:18 +03:00
contentOverlay: PropTypes.bool,
image: PropTypes.oneOfType([
PropTypes.string,
2015-11-23 07:19:26 +03:00
PropTypes.element
])
2016-01-08 18:50:07 +03:00
};
render () {
const { aspectRatio, children, className, color, contentOverlay, image, ...other } = this.props;
2015-11-21 22:17:18 +03:00
const classes = ClassNames(style.cardMedia, {
[style[aspectRatio]]: aspectRatio
}, className);
2015-11-22 04:43:18 +03:00
const innerClasses = ClassNames(style.content, {
[style.contentOverlay]: contentOverlay
});
const bgStyle = {
backgroundColor: color ? color : undefined,
backgroundImage: typeof image === 'string' ? `url('${image}')` : undefined
};
return (
<div style={bgStyle} className={classes} {...other}>
2015-11-22 04:43:18 +03:00
<div className={innerClasses}>
{children}
</div>
</div>
);
}
}
export default CardMedia;