Skip to content

Commit 4b31bcf

Browse files
authored
Merge pull request #38 from lannodev/refactor/navbar-mobile
Refactor/navbar mobile
2 parents 2f43971 + c2980bd commit 4b31bcf

File tree

8 files changed

+68
-61
lines changed

8 files changed

+68
-61
lines changed

src/app/modules/layout/components/navbar/navbar-mobile/navbar-mobile-menu/navbar-mobile-menu.component.html

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<div class="pt-4" *ngFor="let menu of menuService.pagesMenu">
22
<div class="mx-1 mb-2 flex items-center justify-between">
3-
<small class="text-muted-foreground text-xs font-semibold">
3+
<small class="text-muted-foreground/50 text-xs font-semibold">
44
{{ menu.group }}
55
</small>
66
</div>
7-
<ul class="flex flex-col space-y-1">
7+
<ul class="flex flex-col">
88
<!-- List items -->
99
<li *ngFor="let item of menu.items">
1010
<!-- Menu List -->
11-
<div (click)="toggleMenu(item)" class="text-muted-foreground hover:text-foreground group relative">
11+
<div
12+
(click)="toggleMenu(item)"
13+
class="text-muted-foreground hover:text-foreground group flex grow items-center gap-4">
1214
<!-- Icon -->
13-
<div
14-
[ngClass]="item.active && !menuService.showSideBar ? 'text-primary' : 'text-muted-foreground/50'"
15-
class="pointer-events-none absolute m-2">
15+
<div [ngClass]="item.active && !menuService.showSideBar ? 'text-primary' : 'text-muted-foreground/50'">
1616
<svg-icon src="{{ item.icon }}" [svgClass]="'h-5 w-5'"> </svg-icon>
1717
</div>
1818

@@ -26,20 +26,20 @@
2626
<ng-template #parentMenu let-item="item">
2727
<div
2828
routerLink="{{ item.route }}"
29-
class="hover:bg-card flex h-9 cursor-pointer items-center justify-start rounded-sm">
29+
class="text-muted-foreground hover:text-primary flex h-[36px] cursor-pointer items-center justify-start rounded-sm">
3030
<a
3131
routerLinkActive="text-primary"
32-
(click)="closeMenu()"
33-
class="truncate text-xs font-semibold tracking-wide focus:outline-hidden ltr:ml-10 rtl:mr-10">
32+
class="truncate text-xs font-semibold tracking-wide focus:outline-hidden">
3433
{{ item.label }}
3534
</a>
3635
</div>
3736
</ng-template>
3837

3938
<!-- Workaround:: Disable routerLink -->
4039
<ng-template #childMenu let-item="item">
41-
<div class="hover:bg-card flex h-9 cursor-pointer items-center justify-start rounded-sm">
42-
<a class="truncate text-xs font-semibold tracking-wide focus:outline-hidden ltr:ml-10 rtl:mr-10">
40+
<div class="flex h-9 grow cursor-pointer items-center justify-start rounded-sm">
41+
<a
42+
class="text-muted-foreground group-hover:text-primary truncate text-xs font-semibold tracking-wide focus:outline-hidden">
4343
{{ item.label }}
4444
</a>
4545
</div>
@@ -48,9 +48,13 @@
4848
<!-- Arrow Icon -->
4949
<button
5050
*ngIf="item.children"
51-
[ngClass]="{ hidden: !menuService.showSideBar, 'rotate-90': item.expanded }"
52-
class="text-muted-foreground/50 pointer-events-none absolute top-1 flex items-center p-1 transition-all duration-500 ltr:right-0 rtl:left-0">
53-
<svg-icon src="assets/icons/heroicons/solid/chevron-right.svg" [svgClass]="'h-5 w-5'"> </svg-icon>
51+
[ngClass]="{ hidden: !menuService.showSideBar }"
52+
class="text-foreground/50 flex cursor-pointer items-center justify-end p-0 transition-all duration-500 ltr:right-0 rtl:left-0">
53+
@if(!item.expanded){
54+
<svg-icon src="assets/icons/heroicons/outline/plus.svg" svgClass="h-4 w-4"> </svg-icon>
55+
}@else {
56+
<svg-icon src="assets/icons/heroicons/outline/minus.svg" svgClass="h-4 w-4"> </svg-icon>
57+
}
5458
</button>
5559
</div>
5660

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div
2-
class="max-h-0 overflow-hidden pt-1 transition-all duration-500 ltr:pl-4 rtl:pr-4"
2+
class="max-h-0 overflow-hidden pt-1 transition-all duration-500 ltr:pl-2.5 rtl:pr-2.5"
33
[ngClass]="{ 'max-h-screen': submenu.expanded }">
44
<ul
55
class="border-border text-muted-foreground flex flex-col border-dashed ltr:border-l ltr:pl-2 rtl:border-r rtl:pr-2">
66
<li *ngFor="let sub of submenu.children">
7-
<div class="hover:bg-card hover:text-foreground flex rounded-sm" (click)="toggleMenu(sub)">
7+
<div class="text-muted-foreground hover:text-primary relative flex rounded-sm" (click)="toggleMenu(sub)">
88
<!-- Condition -->
99
<ng-container
1010
[ngTemplateOutlet]="sub.children ? childMenu : parentMenu"
@@ -18,25 +18,34 @@
1818
[routerLink]="sub.route"
1919
routerLinkActive="text-primary"
2020
[routerLinkActiveOptions]="{ exact: true }"
21-
class="inline-block w-full px-4 py-2 text-xs font-semibold">
21+
class="hover:bg-card inline-block w-full px-4 py-2 text-xs">
2222
{{ sub.label }}
2323
</a>
24+
@if(menuService.isActive(sub.route)){
25+
<span
26+
class="size-1.5 bg-primary absolute flex translate-y-3.5 items-center rounded-full ltr:-translate-x-[11.5px] rtl:translate-x-[11.5px]">
27+
</span>
28+
}
2429
</ng-template>
2530

2631
<!-- Child Menu -->
2732
<ng-template #childMenu let-sub="sub">
28-
<a class="inline-block w-full cursor-pointer px-4 py-2 text-xs font-semibold">
33+
<a class="inline-block w-full cursor-pointer px-4 py-2 text-xs">
2934
{{ sub.label }}
3035
</a>
31-
<button
32-
[ngClass]="{ 'rotate-90': sub.expanded }"
33-
class="text-muted-foreground flex items-center p-1 transition-all duration-500">
34-
<svg-icon src="assets/icons/heroicons/solid/chevron-right.svg" [svgClass]="'h-5 w-5'"> </svg-icon>
36+
<button class="text-foreground/50 flex cursor-pointer items-center justify-end transition-all duration-500">
37+
@if(!sub.expanded){
38+
<svg-icon src="assets/icons/heroicons/outline/plus.svg" svgClass="h-4 w-4"> </svg-icon>
39+
}@else {
40+
<svg-icon src="assets/icons/heroicons/outline/minus.svg" svgClass="h-4 w-4"> </svg-icon>
41+
}
3542
</button>
3643
</ng-template>
3744
</div>
3845
<!-- Submenu items -->
46+
@if(sub.children?.length){
3947
<app-navbar-mobile-submenu [submenu]="sub"></app-navbar-mobile-submenu>
48+
}
4049
</li>
4150
</ul>
4251
</div>

src/app/modules/layout/components/navbar/navbar-mobile/navbar-mobile-submenu/navbar-mobile-submenu.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { MenuService } from 'src/app/modules/layout/services/menu.service';
1414
export class NavbarMobileSubmenuComponent implements OnInit {
1515
@Input() public submenu = <SubMenuItem>{};
1616

17-
constructor(private menuService: MenuService) {}
17+
constructor(public menuService: MenuService) {}
1818

1919
ngOnInit(): void {}
2020

src/app/modules/layout/components/navbar/navbar-mobile/navbar-mobile.component.html

-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
<!--
2-
Mobile menu, show/hide based on mobile menu state.
3-
Entering: "duration-200 ease-out"
4-
From: "opacity-0 scale-95"
5-
To: "opacity-100 scale-100"
6-
Leaving: "duration-100 ease-in"
7-
From: "opacity-100 scale-100"
8-
To: "opacity-0 scale-95"
9-
-->
101
<div
112
[ngClass]="
123
menuService.showMobileMenu
@@ -32,7 +23,6 @@
3223
type="button"
3324
class="text-muted-foreground focus:ring-primary hover:bg-card hover:text-foreground inline-flex items-center justify-center rounded-md p-2 transition-transform hover:rotate-90 focus:outline-hidden focus:ring-2 focus:ring-inset">
3425
<span class="sr-only">Close menu</span>
35-
<!-- Heroicon name: outline/x -->
3626
<svg-icon src="assets/icons/heroicons/outline/x.svg"> </svg-icon>
3727
</button>
3828
</div>

src/app/modules/layout/components/navbar/profile-menu/profile-menu.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<img
66
clickOutside
77
(clickOutside)="isOpen = false"
8-
class="size-9 shrink-0 rounded-full border-2 border-green-500"
8+
class="size-9 shrink-0 rounded-md"
99
src="https://avatars.githubusercontent.com/u/12519008?v=4"
1010
alt="" />
1111
</button>

src/app/modules/layout/components/sidebar/sidebar-menu/sidebar-menu.component.html

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<div class="pt-4" *ngFor="let menu of menuService.pagesMenu">
2-
<div class="mx-1 mb-2 flex items-center justify-between">
1+
<div *ngFor="let menu of menuService.pagesMenu">
2+
<div *ngIf="menuService.showSideBar" class="mx-1 flex items-center justify-between py-3">
33
<small [ngClass]="{ hidden: !menuService.showSideBar }" class="text-muted-foreground/50 text-xs font-semibold">
44
{{ menu.group }}
55
</small>
@@ -8,11 +8,15 @@
88
<!-- List items -->
99
<li *ngFor="let item of menu.items">
1010
<!-- Menu List -->
11-
<div (click)="toggleMenu(item)" class="text-muted-foreground group relative">
11+
<div
12+
(click)="toggleMenu(item)"
13+
[ngClass]="{
14+
'hover:bg-primary/10': !menuService.showSideBar && item.active,
15+
'hover:bg-card/50': !menuService.showSideBar
16+
}"
17+
class="text-muted-foreground hover:text-foreground group relative flex grow items-center gap-4 rounded-lg px-2">
1218
<!-- Icon -->
13-
<div
14-
[ngClass]="item.active && !menuService.showSideBar ? 'text-primary' : 'text-muted-foreground/50'"
15-
class="pointer-events-none absolute m-2">
19+
<div [ngClass]="item.active && !menuService.showSideBar ? 'text-primary' : 'text-muted-foreground/50'">
1620
<svg-icon src="{{ item.icon }}" [svgClass]="'h-5 w-5'"> </svg-icon>
1721
</div>
1822

@@ -28,18 +32,20 @@
2832
routerLink="{{ item.route }}"
2933
class="text-muted-foreground hover:text-primary flex h-[36px] cursor-pointer items-center justify-start rounded-sm">
3034
<a
35+
[ngClass]="{ hidden: !menuService.showSideBar }"
3136
routerLinkActive="text-primary"
32-
class="ms-10 truncate text-xs font-semibold tracking-wide focus:outline-hidden">
37+
class="truncate text-xs font-semibold tracking-wide focus:outline-hidden">
3338
{{ item.label }}
3439
</a>
3540
</div>
3641
</ng-template>
3742

3843
<!-- Workaround:: Disable routerLink -->
3944
<ng-template #childMenu let-item="item">
40-
<div class="flex h-[36px] cursor-pointer items-center justify-start rounded-sm">
45+
<div class="flex h-9 grow cursor-pointer items-center justify-start rounded-sm">
4146
<a
42-
class="text-muted-foreground group-hover:text-primary ms-10 truncate text-xs font-semibold tracking-wide focus:outline-hidden">
47+
[ngClass]="{ hidden: !menuService.showSideBar }"
48+
class="text-muted-foreground group-hover:text-primary truncate text-xs font-semibold tracking-wide focus:outline-hidden">
4349
{{ item.label }}
4450
</a>
4551
</div>
@@ -49,7 +55,7 @@
4955
<button
5056
*ngIf="item.children"
5157
[ngClass]="{ hidden: !menuService.showSideBar }"
52-
class="text-foreground/50 pointer-events-none absolute top-1 mx-1 flex items-center p-1 transition-all duration-500 ltr:right-0 rtl:left-0">
58+
class="text-foreground/50 flex cursor-pointer items-center justify-end p-0 transition-all duration-500 ltr:right-0 rtl:left-0">
5359
@if(!item.expanded){
5460
<svg-icon src="assets/icons/heroicons/outline/plus.svg" svgClass="h-4 w-4"> </svg-icon>
5561
}@else {
@@ -58,9 +64,9 @@
5864
</button>
5965

6066
<!-- Tooltip -->
61-
<div class="fixed w-full" *ngIf="!menuService.showSideBar">
67+
<div class="z-1 fixed h-[36px]" *ngIf="!menuService.showSideBar">
6268
<span
63-
class="z-1 bg-foreground text-background absolute -top-[34px] w-auto min-w-max scale-0 rounded-md p-2 text-xs font-bold shadow-md transition-all duration-200 group-hover:scale-100 ltr:left-14 ltr:origin-left rtl:right-14 rtl:origin-right">
69+
class="z-1 bg-foreground text-background absolute w-auto min-w-max translate-y-[2px] scale-0 rounded-md p-2 text-xs font-bold shadow-md transition-all duration-200 group-hover:scale-100 ltr:origin-left ltr:translate-x-10 rtl:origin-right rtl:-translate-x-10">
6470
{{ item.label }}
6571
</span>
6672
</div>
@@ -71,7 +77,7 @@
7177
</li>
7278
</ul>
7379

74-
<div class="pt-3" *ngIf="menu.separator">
80+
<div class="py-3" *ngIf="menu.separator">
7581
<hr class="border-border border-dashed" />
7682
</div>
7783
</div>

src/app/modules/layout/components/sidebar/sidebar-submenu/sidebar-submenu.component.html

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<div
2-
class="ps-4 max-h-0 overflow-hidden pt-1 transition-all duration-500"
2+
class="max-h-0 overflow-hidden pt-1 transition-all duration-500 ltr:pl-4 rtl:pr-4"
33
[ngClass]="{ hidden: !menuService.showSideBar, 'max-h-screen': submenu.expanded }">
4-
<ul class="border-border text-muted-foreground relative flex flex-col border-dashed px-2 ltr:border-l rtl:border-r">
4+
<ul
5+
class="border-border text-muted-foreground flex flex-col border-dashed ltr:border-l ltr:pl-2 rtl:border-r rtl:pr-2">
56
<li *ngFor="let sub of submenu.children">
6-
<!-- <span
7-
class="-start-[3px] rtl:start-0 before:size-[6px] bg-primary absolute flex w-[6px] shrink-0 items-center before:absolute before:top-0 before:-translate-y-1/2 before:rounded-full rtl:before:translate-x-1/2">
8-
</span> -->
9-
10-
<div class="text-muted-foreground hover:text-primary flex rounded-sm" (click)="toggleMenu(sub)">
7+
<div class="text-muted-foreground hover:text-primary relative flex" (click)="toggleMenu(sub)">
118
<!-- Condition -->
129
<ng-container
1310
[ngTemplateOutlet]="sub.children ? childMenu : parentMenu"
@@ -20,12 +17,12 @@
2017
[routerLink]="sub.route"
2118
routerLinkActive="text-primary"
2219
[routerLinkActiveOptions]="{ exact: true }"
23-
class="hover:bg-card inline-block w-full px-4 py-2 text-xs">
20+
class="hover:bg-card inline-block w-full rounded-lg px-4 py-2 text-xs">
2421
{{ sub.label }}
2522
</a>
2623
@if(menuService.isActive(sub.route)){
2724
<span
28-
class="size-[6px] bg-primary absolute flex w-[6px] translate-y-[13px] items-center rounded-full ltr:-translate-x-[11px] rtl:translate-x-[11px]">
25+
class="size-1.5 bg-primary absolute flex translate-y-3.5 items-center rounded-full ltr:-translate-x-[11.5px] rtl:translate-x-[11.5px]">
2926
</span>
3027
}
3128
</ng-template>
@@ -37,7 +34,7 @@
3734
</a>
3835
<button
3936
[ngClass]="{ hidden: !menuService.showSideBar }"
40-
class="text-foreground/50 mx- mx-1 flex cursor-pointer items-center p-1 transition-all duration-500">
37+
class="text-foreground/50 flex cursor-pointer items-center justify-end px-2 transition-all duration-500">
4138
@if(!sub.expanded){
4239
<svg-icon src="assets/icons/heroicons/outline/plus.svg" svgClass="h-4 w-4"> </svg-icon>
4340
}@else {

src/app/modules/layout/components/sidebar/sidebar.component.html

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
class="bg-background hidden h-full flex-col justify-between pt-3 transition-all duration-300 lg:flex">
44
<div class="overflow-hidden">
55
<!-- Logo -->
6-
<div class="relative mx-4 h-9">
6+
<div
7+
[ngClass]="menuService.showSideBar ? 'justify-between' : 'justify-center'"
8+
class="mx-4 mb-2 flex h-9 items-center">
79
<div class="flex items-center" *ngIf="menuService.showSideBar">
810
<a
911
(click)="toggleSidebar()"
1012
class="bg-primary flex cursor-pointer items-center justify-center rounded-sm p-2 focus:outline-hidden focus:ring-1">
1113
<svg-icon src="assets/icons/logo.svg"> </svg-icon>
1214
</a>
13-
<b class="text-foreground ps-2 ml-1 text-sm font-bold">
15+
<b class="text-foreground ps-2 ml-1 grow text-sm font-bold">
1416
{{ appJson.displayName }}
1517
</b>
1618
</div>
1719
<button
1820
(click)="toggleSidebar()"
19-
class="text-muted-foreground/50 hover:text-muted-foreground absolute top-2 flex h-5 w-5 items-center justify-center rounded-sm transition-all duration-200 focus:outline-hidden ltr:right-2 rtl:left-2"
21+
class="text-muted-foreground/50 hover:text-muted-foreground flex items-center justify-center rounded-md p-2 transition-all duration-200 focus:outline-hidden"
2022
[ngClass]="{ 'rotate-180': !menuService.showSideBar }">
2123
<svg-icon src="assets/icons/heroicons/solid/chevron-double-left.svg"> </svg-icon>
2224
</button>
2325
</div>
2426

2527
<!-- Menu Items -->
26-
<!-- <app-sidebar-menu></app-sidebar-menu> -->
2728
<div
2829
class="scrollbar-thumb--sm scrollbar-track-rounded scrollbar-thin scrollbar-track-transparent scrollbar-thumb-card h-full overflow-auto px-4">
2930
<app-sidebar-menu></app-sidebar-menu>

0 commit comments

Comments
 (0)