forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedia.js
More file actions
76 lines (69 loc) · 1.55 KB
/
Copy pathMedia.js
File metadata and controls
76 lines (69 loc) · 1.55 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules } from './utils';
const propTypes = {
body: PropTypes.bool,
bottom: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
cssModule: PropTypes.object,
heading: PropTypes.bool,
left: PropTypes.bool,
list: PropTypes.bool,
middle: PropTypes.bool,
object: PropTypes.bool,
right: PropTypes.bool,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
top: PropTypes.bool,
};
const Media = (props) => {
const {
body,
bottom,
className,
cssModule,
heading,
left,
list,
middle,
object,
right,
tag,
top,
...attributes
} = props;
let defaultTag;
if (heading) {
defaultTag = 'h4';
} else if (left || right) {
defaultTag = 'a';
} else if (object) {
defaultTag = 'img';
} else if (list) {
defaultTag = 'ul';
} else {
defaultTag = 'div';
}
const Tag = tag || defaultTag;
const classes = mapToCssModules(classNames(
className,
{
'media-body': body,
'media-heading': heading,
'media-left': left,
'media-right': right,
'media-top': top,
'media-bottom': bottom,
'media-middle': middle,
'media-object': object,
'media-list': list,
media: !body && !heading && !left && !right && !top && !bottom && !middle && !object && !list,
}
), cssModule);
return (
<Tag {...attributes} className={classes} />
);
};
Media.propTypes = propTypes;
export default Media;