Rename subnavigation component

This commit is contained in:
René Pfeuffer
2020-03-11 15:47:40 +01:00
parent 163b1be93b
commit c4a6f5a978
9 changed files with 165 additions and 168 deletions

View File

@@ -0,0 +1,45 @@
import React, { ReactElement, ReactNode } from "react";
import { MenuContext } from "./MenuContext";
import SubNavigation from "./SubNavigation";
import NavLink from "./NavLink";
type Props = {
to: string;
icon: string;
label: string;
title: string;
activeWhenMatch?: (route: any) => boolean;
activeOnlyWhenExact?: boolean;
children?: ReactElement[];
};
export default class SecondaryNavigationItem extends React.Component<Props> {
render() {
const { to, icon, label, title, activeWhenMatch, activeOnlyWhenExact, children } = this.props;
if (children) {
return (
<MenuContext.Consumer>
{({ menuCollapsed }) => (
<SubNavigation
to={to}
icon={icon}
label={label}
title={title}
activeWhenMatch={activeWhenMatch}
activeOnlyWhenExact={activeOnlyWhenExact}
collapsed={menuCollapsed}
>
{children}
</SubNavigation>
)}
</MenuContext.Consumer>
);
} else {
return (
<MenuContext.Consumer>
{({ menuCollapsed }) => <NavLink to={to} icon={icon} label={label} title={title} collapsed={menuCollapsed} />}
</MenuContext.Consumer>
);
}
}
}