mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
Introduce dedicated component for secondary navigation
This commit is contained in:
45
scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
Normal file
45
scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
Normal 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 SecondaryNavigation 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>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,3 +8,4 @@ export { default as PrimaryNavigation } from "./PrimaryNavigation";
|
||||
export { default as PrimaryNavigationLink } from "./PrimaryNavigationLink";
|
||||
export { default as Section } from "./Section";
|
||||
export { MenuContext, storeMenuCollapsed, isMenuCollapsed } from "./MenuContext";
|
||||
export { default as SecondaryNavigation } from "./SecondaryNavigation";
|
||||
|
||||
Reference in New Issue
Block a user