Skip to content
Snippets Groups Projects
Commit 453794d6 authored by Kawtar Laariche's avatar Kawtar Laariche
Browse files

add collapse functionality to the sidebar

parent 24bed660
No related branches found
No related tags found
1 merge request!2Features/navbar
/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { ApplicationConfig } from '@angular/core';
import { provideProtractorTestingSupport } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { DevAuthInterceptor } from 'src/app/shared/interceptors/dev-auth-interceptor.service';
import routeConfig from 'src/app/routes';
export const appConfig: ApplicationConfig = {
providers: [
provideProtractorTestingSupport(),
provideRouter(routeConfig),
provideAnimations(),
{ provide: HTTP_INTERCEPTORS, useClass: DevAuthInterceptor, multi: true },
provideHttpClient(withInterceptorsFromDi()),
],
};
<div class="container"> <mat-toolbar class="mat-elevation-z3">
<div><gp-navbar></gp-navbar></div> <button mat-icon-button (click)="collapsed.set(!collapsed())">
<div class="sidebar-content-container"> <mat-icon>menu</mat-icon>
<div class="sidebar-container"><gp-sidebar></gp-sidebar></div> </button>
<div class="content-container"><ng-content></ng-content></div> </mat-toolbar>
</div> <mat-sidenav-container>
<div><gp-footer></gp-footer></div> <mat-sidenav mode="side" opened [style.width]="sidenavWidth()">
</div> <gp-sidebar [collapsed]="collapsed()"></gp-sidebar>
</mat-sidenav>
<mat-sidenav-content [style.margin-left]="sidenavWidth()">
<div class="content">
<router-outlet></router-outlet>
</div>
<!-- Add Content Here -->
<mat-toolbar class="footer">
<gp-footer></gp-footer>
</mat-toolbar> </mat-sidenav-content
></mat-sidenav-container>
.container { mat-toolbar {
min-height: 100vh; position: relative;
display: flex; z-index: 5;
flex-direction: column;
} }
.content {
.sidebar-content-container { padding: 24px;
display: flex;
flex: 1;
} }
.sidebar-container { mat-sidenav-container {
flex-shrink: 0; height: calc(100vh - 64px);
} }
.content-container { .footer {
flex-grow: 1; position: fixed;
bottom: 0;
width: 100%;
} }
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { Component } from '@angular/core'; import { Component, computed, signal } from '@angular/core';
import { HomeComponent } from '../home/home.component'; import { HomeComponent } from '../home/home.component';
import { NavbarComponent } from './navbar/navbar.component'; import { NavbarComponent } from './navbar/navbar.component';
import { SidebarComponent } from './sidebar/sidebar.component'; import { SidebarComponent } from './sidebar/sidebar.component';
import { FooterComponent } from './footer/footer.component'; import { FooterComponent } from './footer/footer.component';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatIconModule } from '@angular/material/icon';
import { MatSidenavModule } from '@angular/material/sidenav';
@Component({ @Component({
selector: 'gp-dashboard', selector: 'gp-dashboard',
standalone: true, standalone: true,
...@@ -17,6 +19,12 @@ import { RouterModule } from '@angular/router'; ...@@ -17,6 +19,12 @@ import { RouterModule } from '@angular/router';
SidebarComponent, SidebarComponent,
FooterComponent, FooterComponent,
RouterModule, RouterModule,
MatToolbarModule,
MatIconModule,
MatSidenavModule,
], ],
}) })
export class DashboardComponent {} export class DashboardComponent {
collapsed = signal(false);
sidenavWidth = computed(() => (this.collapsed() ? '65px' : '250px'));
}
<mat-list role="list"> <mat-list role="list">
<mat-list-item><a routerLink="home">home</a></mat-list-item> <mat-list-item><a routerLink="home">home</a></mat-list-item>
<mat-list-item role="listitem"> <a routerLink="marketplace">Marketplace</a></mat-list-item> <mat-list-item role="listitem">
<mat-list-item role="listitem"> <a routerLink="catalog">Catalog</a></mat-list-item> <a routerLink="marketplace">Marketplace</a></mat-list-item
>
<mat-list-item role="listitem">
<a routerLink="catalog">Catalog</a></mat-list-item
>
<mat-list-item role="listitem">My models</mat-list-item> <mat-list-item role="listitem">My models</mat-list-item>
<mat-list-item role="listitem">On-boarding model</mat-list-item> <mat-list-item role="listitem">On-boarding model</mat-list-item>
<mat-list-item role="listitem">Design studio</mat-list-item> <mat-list-item role="listitem">Design studio</mat-list-item>
......
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { Component } from '@angular/core'; import { Component, Input, signal } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { MatListModule } from '@angular/material/list'; import { MatListModule } from '@angular/material/list';
...@@ -10,4 +10,9 @@ import { MatListModule } from '@angular/material/list'; ...@@ -10,4 +10,9 @@ import { MatListModule } from '@angular/material/list';
standalone: true, standalone: true,
imports: [CommonModule, RouterModule, MatListModule], imports: [CommonModule, RouterModule, MatListModule],
}) })
export class SidebarComponent {} export class SidebarComponent {
sideNavCollapsed = signal(false);
@Input() set collapsed(val: boolean) {
this.sideNavCollapsed.set(val);
}
}
import { import { bootstrapApplication } from '@angular/platform-browser';
bootstrapApplication,
provideProtractorTestingSupport,
} from '@angular/platform-browser';
import { AppComponent } from './app/app.component'; import { AppComponent } from './app/app.component';
import { provideRouter } from '@angular/router'; import { appConfig } from 'app.config';
import routeConfig from './app/routes';
import { provideHttpClient, withInterceptorsFromDi } from "@angular/common/http";
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { DevAuthInterceptor } from './app/shared/interceptors/dev-auth-interceptor.service'; bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err),
);
bootstrapApplication(AppComponent, {
providers: [
provideProtractorTestingSupport(),
provideRouter(routeConfig),
provideAnimations(),
{ provide: HTTP_INTERCEPTORS, useClass: DevAuthInterceptor, multi: true },
provideHttpClient(withInterceptorsFromDi())
],
}).catch((err) => console.error(err));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment