2015-10-19 03:38:25 +03:00
|
|
|
import React from 'react';
|
2016-04-10 12:39:04 +03:00
|
|
|
import classnames from 'classnames';
|
2016-05-22 20:08:47 +03:00
|
|
|
import { themr } from 'react-css-themr';
|
2016-01-26 16:59:57 +03:00
|
|
|
import ListItemText from './ListItemText';
|
2015-10-19 03:38:25 +03:00
|
|
|
|
2016-01-26 16:59:57 +03:00
|
|
|
const types = ['auto', 'normal', 'large'];
|
2015-10-19 03:38:25 +03:00
|
|
|
|
2016-01-26 16:59:57 +03:00
|
|
|
class ListItemContent extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
caption: React.PropTypes.string,
|
|
|
|
children: React.PropTypes.any,
|
|
|
|
legend: React.PropTypes.string,
|
2016-05-22 20:08:47 +03:00
|
|
|
theme: React.PropTypes.shape({
|
|
|
|
itemContentRoot: React.PropTypes.string.isRequired,
|
|
|
|
large: React.PropTypes.string.isRequired
|
|
|
|
}),
|
2016-01-26 16:59:57 +03:00
|
|
|
type: React.PropTypes.oneOf(types)
|
|
|
|
};
|
2015-10-19 03:38:25 +03:00
|
|
|
|
2016-02-12 13:23:27 +03:00
|
|
|
getType () {
|
2016-01-26 16:59:57 +03:00
|
|
|
const {type, children, caption, legend} = this.props;
|
|
|
|
|
|
|
|
let count = React.Children.count(children);
|
2016-04-09 21:34:34 +03:00
|
|
|
[caption, legend].forEach(s => { count += s ? 1 : 0; });
|
2016-01-26 16:59:57 +03:00
|
|
|
const typeIndex = Math.min(count, types.length);
|
|
|
|
|
|
|
|
return type || types[typeIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-05-22 20:08:47 +03:00
|
|
|
const {children, caption, legend, theme} = this.props;
|
|
|
|
const className = classnames(theme.itemContentRoot, {
|
|
|
|
[theme[this.getType()]]: theme[this.getType()]
|
2016-04-10 12:39:04 +03:00
|
|
|
});
|
2016-01-26 16:59:57 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<span className={className}>
|
2016-04-10 12:39:04 +03:00
|
|
|
{caption && <ListItemText primary>{caption}</ListItemText>}
|
|
|
|
{legend && <ListItemText>{legend}</ListItemText>}
|
|
|
|
{children}
|
2016-01-26 16:59:57 +03:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-22 20:08:47 +03:00
|
|
|
export default themr('ToolboxList')(ListItemContent);
|