react-toolbox/components/list/item.jsx

68 lines
2.2 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';
2015-10-19 03:38:25 +03:00
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,
className: React.PropTypes.string,
2015-10-19 03:38:25 +03:00
disabled: React.PropTypes.bool,
leftIcon: React.PropTypes.string,
legend: React.PropTypes.string,
onClick: React.PropTypes.func,
2015-10-19 03:38:25 +03:00
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}>
{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}
2015-10-19 03:38:25 +03:00
<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;