react-toolbox/components/list/ListItemContent.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-10-19 03:38:25 +03:00
import React from 'react';
import style from './style';
2016-04-10 12:39:04 +03:00
import classnames from 'classnames';
import ListItemText from './ListItemText';
2015-10-19 03:38:25 +03:00
const types = ['auto', 'normal', 'large'];
2015-10-19 03:38:25 +03:00
class ListItemContent extends React.Component {
static propTypes = {
caption: React.PropTypes.string,
children: React.PropTypes.any,
legend: React.PropTypes.string,
type: React.PropTypes.oneOf(types)
};
2015-10-19 03:38:25 +03:00
getType () {
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; });
const typeIndex = Math.min(count, types.length);
return type || types[typeIndex];
}
render () {
const {children, caption, legend} = this.props;
2016-04-10 12:39:04 +03:00
const className = classnames(style.itemContentRoot, {
[style[this.getType()]]: style[this.getType()]
});
return (
<span className={className}>
2016-04-10 12:39:04 +03:00
{caption && <ListItemText primary>{caption}</ListItemText>}
{legend && <ListItemText>{legend}</ListItemText>}
{children}
</span>
);
}
}
2015-10-19 03:38:25 +03:00
export default ListItemContent;