Skip to content

Commit 804f56a

Browse files
Fix Layout of Navbar (#42)
1 parent c27078e commit 804f56a

3 files changed

Lines changed: 52 additions & 31 deletions

File tree

src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext.tsx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,55 @@ export interface PanelSideBarContextProps<TPanelItem, TMenuItem> {
4242
*/
4343
userDropDownMenu?: ReactNode;
4444
/**
45-
* The other menu content.
45+
* The menu content on the right.
4646
*/
47-
topBarCustomItems?: ReactNode[];
47+
topBarRightCustomItems?: ReactNode[];
48+
/**
49+
* The menu content on the left.
50+
*/
51+
topBarLeftCustomItems?: ReactNode[];
4852
}
4953

5054
export const PanelSideBarContext = createContext<PanelSideBarContextProps<any, any> | null>(null);
5155

5256
export interface PanelSideBarMenuProviderProps<TPanelItem, TMenuItem>
53-
extends Pick<PanelSideBarContextProps<TPanelItem, TMenuItem>, "globalItems" | "LinkRenderer" | "brand" | "footer" | "userDropDownMenu" | "userDropDownMenuToggle" | "topBarCustomItems" | "localItems"> {
57+
extends Pick<
58+
PanelSideBarContextProps<TPanelItem, TMenuItem>,
59+
"globalItems" | "LinkRenderer" | "brand" | "footer" | "userDropDownMenu" | "userDropDownMenuToggle" | "topBarRightCustomItems" | "topBarLeftCustomItems" | "localItems"
60+
> {
5461
/**
5562
* The children elements.
5663
*/
5764
children: React.ReactNode;
5865
}
5966

6067
export const PanelSideBarProvider = <TPanelItem, TMenuItem>(props: PanelSideBarMenuProviderProps<TPanelItem, TMenuItem>) => {
61-
const { children, globalItems, localItems = [], LinkRenderer, brand = null, footer = null, userDropDownMenu, userDropDownMenuToggle, topBarCustomItems } = props;
62-
63-
const activePanel = globalItems.find(x => x.children?.find(y => y.children ? y.children.find(s => s.active) : y.active));
64-
const firstActivePanel = activePanel ?? globalItems.find(x => x.id);
68+
const {
69+
children,
70+
globalItems,
71+
localItems = [],
72+
LinkRenderer,
73+
brand = null,
74+
footer = null,
75+
userDropDownMenu,
76+
userDropDownMenuToggle,
77+
topBarRightCustomItems,
78+
topBarLeftCustomItems,
79+
} = props;
80+
81+
const activePanel = globalItems.find((x) => x.children?.find((y) => (y.children ? y.children.find((s) => s.active) : y.active)));
82+
const firstActivePanel = activePanel ?? globalItems.find((x) => x.id);
6583

6684
const getActivePanelId = () => localItems?.at(0)?.id ?? firstActivePanel?.id ?? "";
6785

6886
const [activePanelId, setActivePanelId] = useState(getActivePanelId());
6987

70-
const [toggledMenuItemIds, setToggledMenuItemIds] = useState<string[]>([(firstActivePanel?.children ?
71-
firstActivePanel.children?.find((x) => x.children?.find(s => s.active)) : firstActivePanel?.children?.find((x) => x.active))?.id ?? ""]);
88+
const [toggledMenuItemIds, setToggledMenuItemIds] = useState<string[]>([
89+
(firstActivePanel?.children
90+
? firstActivePanel.children?.find((x) => x.children?.find((s) => s.active))
91+
: firstActivePanel?.children?.find((x) => x.active)
92+
)?.id ?? "",
93+
]);
7294

7395
const setActivePanel = (panelId: string) => setActivePanelId(panelId);
7496

@@ -97,7 +119,8 @@ export const PanelSideBarProvider = <TPanelItem, TMenuItem>(props: PanelSideBarM
97119
footer,
98120
userDropDownMenu,
99121
userDropDownMenuToggle,
100-
topBarCustomItems,
122+
topBarRightCustomItems,
123+
topBarLeftCustomItems,
101124
brand,
102125
}}
103126
>

src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "../../../../styles/Layout/PanelSideBarLayout.scss";
55
import { PanelSideBar } from "./PanelSideBar/PanelSidebar";
66
import { PanelSideBarLayoutContent } from "./PanelSideBarLayoutContent";
77
import { PanelSideBarToggle } from "./PanelSideBar/PanelSideBarToggle";
8-
import {usePanelSideBarContext} from "src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext";
8+
import { usePanelSideBarContext } from "src/lib/Layout/PanelSideBarLayout/PanelSideBar/Context/PanelSideBarContext";
99

1010
export interface PanelSideBarLayoutProps extends PropsWithChildren {
1111
/**
@@ -33,23 +33,30 @@ export const PanelSideBarLayout = (props: PanelSideBarLayoutProps) => {
3333
footer: contextFooter,
3434
userDropDownMenu,
3535
userDropDownMenuToggle,
36-
topBarCustomItems = [],
36+
topBarRightCustomItems = [],
37+
topBarLeftCustomItems = [],
3738
} = usePanelSideBarContext();
3839

3940
return (
4041
<>
4142
<nav id="nav-top" className="panel-layout navbar navbar-expand">
4243
{/* Navbar Brand */}
4344
<div className="navbar-brand">{brand ?? contextBrand}</div>
44-
<Nav className="navbar-user" vertical style={{ marginRight: 48 + topBarCustomItems.length * 32 }}>
45-
{/*Other Custom Menu*/}
46-
<div className="navbar-custom">
47-
{topBarCustomItems?.map((item, index) => (
48-
<NavItem key={index} className="navbar-custom-item">
49-
{item}
50-
</NavItem>
51-
))}
52-
</div>
45+
<Nav className="navbar-user flex-row justify-content-start align-items-center" style={{ marginLeft: 35 }}>
46+
{/*Left Custom Menu*/}
47+
{topBarLeftCustomItems?.map((item, index) => (
48+
<NavItem key={index} className="navbar-custom-item">
49+
{item}
50+
</NavItem>
51+
))}
52+
</Nav>
53+
<Nav className="navbar-user flex-row justify-content-end align-items-center" style={{ marginRight: 48 }}>
54+
{/*Right Custom Menu*/}
55+
{topBarRightCustomItems?.map((item, index) => (
56+
<NavItem key={index} className="navbar-custom-item">
57+
{item}
58+
</NavItem>
59+
))}
5360
{/* <NavbarUser /> */}
5461
<NavItem>
5562
<UncontrolledDropdown direction="start">

styles/Layout/PanelSideBarLayout.scss

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ $topnav-light-toggler-color: $gray-900;
9494
.navbar-user {
9595
display: flex;
9696
height: $usernav-base-height;
97-
width: $usernav-base-height;
97+
width: 100%;
9898
border: 1px solid $topnav-dark-toggler-color;
9999
border-radius: $usernav-base-height;
100100
background-color: $sidenav-light-link-active-color;
@@ -106,15 +106,6 @@ $topnav-light-toggler-color: $gray-900;
106106
rgba($color: $sidenav-light-color, $alpha: 0.75) 70%,
107107
rgba($color: $sidenav-light-link-active-color, $alpha: 1) 82%
108108
);
109-
align-items: center;
110-
justify-content: center;
111-
align-self: flex-end;
112-
margin-left: auto;
113-
114-
.navbar-custom {
115-
display: flex;
116-
flex-direction: row;
117-
}
118109

119110
.navbar-custom-item {
120111
margin-left: 1em;

0 commit comments

Comments
 (0)