react-toolbox/components/list/List.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-10-19 03:38:25 +03:00
import React from 'react';
2016-05-22 20:08:47 +03:00
import classnames from 'classnames';
import { themr } from 'react-css-themr';
import ListItem from './ListItem';
2015-10-19 03:38:25 +03:00
2015-10-22 02:31:17 +03:00
class List extends React.Component {
static propTypes = {
children: React.PropTypes.node,
2015-10-19 03:38:25 +03:00
className: React.PropTypes.string,
ripple: React.PropTypes.bool,
2016-05-22 20:08:47 +03:00
selectable: React.PropTypes.bool,
theme: React.PropTypes.shape({
list: React.PropTypes.string.isRequired
})
};
2015-10-19 03:38:25 +03:00
static defaultProps = {
className: '',
ripple: false,
selectable: false
};
2015-10-19 03:38:25 +03:00
renderItems () {
return React.Children.map(this.props.children, (item) => {
if (item.type === ListItem) {
return React.cloneElement(item, {
ripple: this.props.ripple,
selectable: this.props.selectable
});
} else {
return React.cloneElement(item);
}
});
}
2015-10-19 03:38:25 +03:00
render () {
return (
2016-05-22 20:08:47 +03:00
<ul data-react-toolbox='list' className={classnames(this.props.theme.list, this.props.className)}>
{this.renderItems()}
2015-10-19 03:38:25 +03:00
</ul>
);
}
2015-10-21 13:25:07 +03:00
}
2015-10-22 02:31:17 +03:00
2016-05-22 20:08:47 +03:00
export default themr('ToolboxList')(List);