forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardMedia.js
More file actions
49 lines (43 loc) · 1.38 KB
/
CardMedia.js
File metadata and controls
49 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { PropTypes } from 'react';
import { themr } from 'react-css-themr';
import classnames from 'classnames';
import { CARD } from '../identifiers.js';
const CardMedia = ({ aspectRatio, children, className, color, contentOverlay, image, theme, ...other }) => {
const classes = classnames(theme.cardMedia, {
[theme[aspectRatio]]: aspectRatio
}, className);
const innerClasses = classnames(theme.content, {
[theme.contentOverlay]: contentOverlay
});
const bgStyle = {
backgroundColor: color ? color : undefined,
backgroundImage: typeof image === 'string' ? `url('${image}')` : undefined
};
return (
<div style={bgStyle} className={classes} {...other}>
<div className={innerClasses}>
{children}
</div>
</div>
);
};
CardMedia.propTypes = {
aspectRatio: PropTypes.oneOf([ 'wide', 'square' ]),
children: PropTypes.any,
className: PropTypes.string,
color: PropTypes.string,
contentOverlay: PropTypes.bool,
image: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
]),
theme: React.PropTypes.shape({
cardMedia: React.PropTypes.string.isRequired,
content: React.PropTypes.string.isRequired,
contentOverlay: React.PropTypes.string.isRequired,
square: React.PropTypes.string.isRequired,
wide: React.PropTypes.string.isRequired
})
};
export default themr(CARD)(CardMedia);
export { CardMedia };