import React from 'react'; import classnames from 'classnames'; import Collapse from 'react-bootstrap/lib/Collapse.js'; class NavigationSideBar extends React.Component { static PropTypes = { activeItemId: React.PropTypes.string.isRequired, onSelect: React.PropTypes.func, onToggle: React.PropTypes.func, groups: React.PropTypes.array }; render() { let {groups, activeItemId} = this.props; return (
{groups.map(group => (
{group.name}
{ group.items && group.items.map(item => this.renderGroupItem(item, activeItemId)) }
))}
); } renderGroupItem(item, activeItemId) { let isGroup = item.items && item.items.length > 0; return (
this.handleItemClicked(event, item)}> {item.name}
{isGroup &&
{item.items.map(item => this.renderGroupItem(item, activeItemId))}
}
); } handleItemClicked(event, item) { event.stopPropagation(); if(this.props.onToggle) { this.props.onToggle(this.props.groups, item.id); } if(item.onSelect) { item.onSelect(); } if(this.props.onSelect) { this.props.onSelect(item); } } } export default NavigationSideBar;