-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Expand file tree
/
Copy pathList.js
More file actions
53 lines (44 loc) · 1.09 KB
/
List.js
File metadata and controls
53 lines (44 loc) · 1.09 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
import React, {Component, PropTypes, Children, isValidElement} from 'react';
import Subheader from '../Subheader';
class List extends Component {
static propTypes = {
/**
* These are usually `ListItem`s that are passed to
* be part of the list.
*/
children: PropTypes.node,
/**
* Override the inline-styles of the root element.
*/
style: PropTypes.object,
};
static contextTypes = {
muiTheme: PropTypes.object.isRequired,
};
render() {
const {
children,
style,
...other,
} = this.props;
const {prepareStyles} = this.context.muiTheme;
let hasSubheader = false;
const firstChild = Children.toArray(children)[0];
if (isValidElement(firstChild) && firstChild.type === Subheader) {
hasSubheader = true;
}
const styles = {
root: {
padding: 0,
paddingBottom: 8,
paddingTop: hasSubheader ? 0 : 8,
},
};
return (
<div {...other} style={prepareStyles(Object.assign(styles.root, style))}>
{children}
</div>
);
}
}
export default List;