2015-09-08 14:20:06 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
2015-10-01 14:00:56 +02:00
|
|
|
import MenuItem from 'react-bootstrap/lib/MenuItem';
|
|
|
|
import NavItem from 'react-bootstrap/lib/NavItem';
|
2016-06-17 15:07:32 +02:00
|
|
|
import NavDropdown from 'react-bootstrap/lib/NavDropdown';
|
2015-10-01 14:00:56 +02:00
|
|
|
|
|
|
|
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
|
|
|
|
|
2015-09-08 14:20:06 +02:00
|
|
|
|
2016-06-17 15:07:32 +02:00
|
|
|
const NavRoutesLinksLink = React.createClass({
|
2015-09-08 14:20:06 +02:00
|
|
|
propTypes: {
|
2016-06-17 15:07:32 +02:00
|
|
|
children: React.PropTypes.node,
|
2016-01-21 16:47:35 +01:00
|
|
|
depth: React.PropTypes.number,
|
2016-06-17 15:07:32 +02:00
|
|
|
disabled: React.PropTypes.bool,
|
2016-01-21 16:47:35 +01:00
|
|
|
headerTitle: React.PropTypes.string,
|
|
|
|
routePath: React.PropTypes.string
|
2016-06-17 15:07:32 +02:00
|
|
|
|
|
|
|
// All other props are passed through to the backing NavItem, or NavDropdown
|
2015-09-08 14:20:06 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2016-06-17 15:07:32 +02:00
|
|
|
const { children, headerTitle, depth, disabled, routePath, ...props } = this.props;
|
2015-09-08 14:20:06 +02:00
|
|
|
|
2015-09-08 14:26:56 +02:00
|
|
|
// if the route has children, we're returning a DropdownButton that will get filled
|
2015-10-01 14:00:56 +02:00
|
|
|
// with MenuItems
|
2016-01-21 15:11:19 +01:00
|
|
|
if (children) {
|
2015-09-08 14:20:06 +02:00
|
|
|
return (
|
2016-06-17 15:07:32 +02:00
|
|
|
<NavDropdown
|
|
|
|
{...props}
|
2016-01-21 16:47:35 +01:00
|
|
|
disabled={disabled}
|
2016-01-29 11:20:27 +01:00
|
|
|
id={`nav-route-${headerTitle.toLowerCase()}-dropdown`}
|
|
|
|
title={headerTitle}>
|
2015-09-08 14:20:06 +02:00
|
|
|
{children}
|
2016-06-17 15:07:32 +02:00
|
|
|
</NavDropdown>
|
2015-09-08 14:20:06 +02:00
|
|
|
);
|
|
|
|
} else {
|
2016-01-21 15:11:19 +01:00
|
|
|
if (depth === 1) {
|
2015-09-08 14:20:06 +02:00
|
|
|
// if the node's child is actually a node of level one (a child of a node), we're
|
2016-06-17 15:07:32 +02:00
|
|
|
// returning a MenuItem for the containing NavDropdown
|
2015-09-08 14:20:06 +02:00
|
|
|
return (
|
2016-01-21 16:47:35 +01:00
|
|
|
<LinkContainer
|
2016-06-17 15:07:32 +02:00
|
|
|
{...props}
|
2016-01-21 16:47:35 +01:00
|
|
|
disabled={disabled}
|
|
|
|
to={routePath}>
|
2015-10-01 14:00:56 +02:00
|
|
|
<MenuItem>{headerTitle}</MenuItem>
|
|
|
|
</LinkContainer>
|
2015-09-08 14:20:06 +02:00
|
|
|
);
|
2016-01-21 15:11:19 +01:00
|
|
|
} else if (depth === 0) {
|
2015-09-08 14:20:06 +02:00
|
|
|
return (
|
2016-01-21 16:47:35 +01:00
|
|
|
<LinkContainer
|
2016-06-17 15:07:32 +02:00
|
|
|
{...props}
|
2016-01-21 16:47:35 +01:00
|
|
|
disabled={disabled}
|
|
|
|
to={routePath}>
|
2015-10-01 14:00:56 +02:00
|
|
|
<NavItem>{headerTitle}</NavItem>
|
|
|
|
</LinkContainer>
|
2015-09-08 14:20:06 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-29 11:20:27 +01:00
|
|
|
export default NavRoutesLinksLink;
|