react-toolbox/components/list/item.jsx

66 lines
2.1 KiB
React
Raw Normal View History

2015-10-19 03:38:25 +03:00
import React from 'react';
import FontIcon from '../font_icon';
import ListItemContent from './content';
import Ripple from '../ripple';
import style from './style';
2015-10-22 02:31:17 +03:00
class ListItem extends React.Component {
static propTypes = {
2015-10-19 03:38:25 +03:00
avatar: React.PropTypes.string,
caption: React.PropTypes.string.isRequired,
disabled: React.PropTypes.bool,
leftIcon: React.PropTypes.string,
legend: React.PropTypes.string,
rightIcon: React.PropTypes.string,
ripple: React.PropTypes.bool,
selectable: React.PropTypes.bool,
to: React.PropTypes.string
};
2015-10-19 03:38:25 +03:00
static defaultProps = {
disabled: false,
ripple: false,
selectable: false
};
2015-10-19 03:38:25 +03:00
2015-10-22 02:31:17 +03:00
handleClick = (event) => {
2015-10-19 03:38:25 +03:00
if (this.props.onClick && !this.props.disabled) {
this.props.onClick(event);
}
2015-10-22 02:31:17 +03:00
};
2015-10-19 03:38:25 +03:00
2015-10-22 02:31:17 +03:00
handleMouseDown = (event) => {
2015-10-19 03:38:25 +03:00
if (this.refs.ripple && !this.props.disabled) {
this.refs.ripple.start(event);
}
2015-10-22 02:31:17 +03:00
};
2015-10-19 03:38:25 +03:00
renderContent () {
2015-10-19 03:38:25 +03:00
let className = style.item;
if (this.props.legend) className += ` ${style['with-legend']}`;
if (this.props.disabled) className += ` ${style.disabled}`;
if (this.props.className) className += ` ${this.props.className}`;
if (this.props.selectable) className += ` ${style.selectable}`;
2015-10-19 03:38:25 +03:00
return (
<span className={className}>
2015-10-19 03:38:25 +03:00
{ this.props.leftIcon ? <FontIcon className={`${style.icon} ${style.left}`} value={this.props.leftIcon} /> : null }
{ this.props.avatar ? <img className={style.avatar} src={this.props.avatar} /> : null }
<ListItemContent caption={this.props.caption} legend={this.props.legend} />
{ this.props.ripple ? <Ripple ref='ripple' className={style.ripple} spread={2} /> : null }
{ this.props.rightIcon ? <FontIcon className={`${style.icon} ${style.right}`} value={this.props.rightIcon} /> : null }
</span>
);
}
render () {
return (
<li className={style['list-item']} onClick={this.handleClick} onMouseDown={this.handleMouseDown}>
{ this.props.to ? <a href={this.props.to}>{this.renderContent()}</a> : this.renderContent() }
2015-10-19 03:38:25 +03:00
</li>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
export default ListItem;