forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListItem.js
More file actions
75 lines (66 loc) · 1.93 KB
/
ListItem.js
File metadata and controls
75 lines (66 loc) · 1.93 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
import React from 'react';
import ListItemContent from './ListItemContent';
import ListItemLayout from './ListItemLayout';
import Ripple from '../ripple';
import style from './style';
class ListItem extends React.Component {
static propTypes = {
children: React.PropTypes.any,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
onClick: React.PropTypes.func,
ripple: React.PropTypes.bool,
to: React.PropTypes.string
};
static defaultProps = {
disabled: false,
ripple: false
};
handleClick = (event) => {
if (this.props.onClick && !this.props.disabled) {
this.props.onClick(event);
}
};
groupChildren () {
const children = {
leftActions: [],
rightActions: [],
ignored: []
};
React.Children.forEach(this.props.children, (child, i) => {
if (!React.isValidElement(child)) {
return;
}
if (child.props.listItemIgnore) {
children.ignored.push(child);
return;
}
if (child.type === ListItemContent) {
children.itemContent = child;
return;
}
const bucket = children.itemContent ? 'rightActions' : 'leftActions';
children[bucket].push({...child, key: i});
});
return children;
}
render () {
const {className, onMouseDown, to, onClick, ripple, ...other} = this.props; //eslint-disable-line no-unused-vars
const children = this.groupChildren();
const content = <ListItemLayout {...children} {...other}/>;
let finalClassName = style.listItem;
if (className) finalClassName += ` ${className}`;
return (
<li className={finalClassName} onClick={this.handleClick} onMouseDown={onMouseDown}>
{to ? <a href={this.props.to}>{content}</a> : content}
{children.ignored}
</li>
);
}
}
export default Ripple({
className: style.ripple,
centered: false,
listItemIgnore: true
})(ListItem);
export {ListItem as RawListItem};