1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00
onion/js/components/nav_routes_links_link.js

65 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
import React from 'react';
import DropdownButton from 'react-bootstrap/lib/DropdownButton';
2015-10-01 14:00:56 +02:00
import MenuItem from 'react-bootstrap/lib/MenuItem';
import NavItem from 'react-bootstrap/lib/NavItem';
import LinkContainer from 'react-router-bootstrap/lib/LinkContainer';
let NavRoutesLinksLink = React.createClass({
propTypes: {
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
]),
disabled: React.PropTypes.bool,
depth: React.PropTypes.number,
headerTitle: React.PropTypes.string,
routePath: React.PropTypes.string
},
render() {
const { children, headerTitle, depth, disabled, routePath } = this.props;
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
if (children) {
return (
<DropdownButton
disabled={disabled}
id={`nav-route-${headerTitle.toLowerCase()}-dropdown`}
title={headerTitle}>
{children}
</DropdownButton>
);
} else {
if (depth === 1) {
// if the node's child is actually a node of level one (a child of a node), we're
2015-10-01 14:00:56 +02:00
// returning a DropdownButton matching MenuItem
return (
<LinkContainer
disabled={disabled}
to={routePath}>
2015-10-01 14:00:56 +02:00
<MenuItem>{headerTitle}</MenuItem>
</LinkContainer>
);
} else if (depth === 0) {
return (
<LinkContainer
disabled={disabled}
to={routePath}>
2015-10-01 14:00:56 +02:00
<NavItem>{headerTitle}</NavItem>
</LinkContainer>
);
} else {
return null;
}
}
}
});
export default NavRoutesLinksLink;