File

src/app/frame/frame.component.ts

Description

This component holds the 'frame' of the application containing the top bar, the side bar and the main container into which individual views are rendered based on the url. It also bridges between top bar and side menu: When the user clicks the menu icon in the topbar, this is communicated to the navigation drawer via this.showDrawer The component itself checks whether the user is currently in a project and passes this information down to the sidebar and topbar. It also checks the display size and makes the side menu an overlay when on handset size.

Metadata

selector app-frame
styleUrls ./frame.component.scss
templateUrl ./frame.component.html

Index

Properties
Methods

Constructor

constructor(breakpointObserver: BreakpointObserver, ss: StateService)
Parameters :
Name Type Optional
breakpointObserver BreakpointObserver No
ss StateService No

Methods

prepareRoute
prepareRoute(outlet: RouterOutlet)
Parameters :
Name Type Optional
outlet RouterOutlet No
Returns : any
toggleMenu
toggleMenu()

When user clicks sandwich this.showDrawer boolean changes value.

Returns : void

Properties

isHandset$
Type : Observable<boolean>
Default value : this.breakpointObserver.observe(Breakpoints.Handset).pipe( map((result) => result.matches), shareReplay() )
Public isProjectSet$
Default value : new BehaviorSubject<boolean>(false)
Public showDrawer
Default value : true
Public ss
Type : StateService
import {Component} from '@angular/core';
import {map, shareReplay} from 'rxjs/operators';
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
import {Observable, BehaviorSubject} from 'rxjs';
import {StateService} from '@app/state.service';
import {RouterOutlet} from '@angular/router';
import {slider} from '../route-animations';

/**
 * This component holds the 'frame' of the application
 * containing the top bar, the side bar and the main container
 * into which individual views are rendered based on the url.
 * It also bridges between top bar and side menu:
 *  When the user clicks the menu icon in the topbar, this is communicated to
 * the navigation drawer via this.showDrawer
 * The component itself checks whether the user is currently in a project
 * and passes this information down to the sidebar and topbar. It also checks the
 * display size and makes the side menu an overlay when on handset size.
 */
@Component({
  selector: 'app-frame',
  templateUrl: './frame.component.html',
  styleUrls: ['./frame.component.scss'],
  animations: [slider]
})
export class FrameComponent {
  public isProjectSet$ = new BehaviorSubject<boolean>(false);
  public showDrawer = true;

  isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset).pipe(
    map((result) => result.matches),
    shareReplay()
  );

  constructor(private breakpointObserver: BreakpointObserver, public ss: StateService) {
    ss.state$.pipe(map((state) => state.project != null)).subscribe(this.isProjectSet$);
  }

  /**
   * When user clicks sandwich this.showDrawer boolean changes value.
   */
  toggleMenu(): void {
    this.showDrawer = !this.showDrawer;
  }

  prepareRoute(outlet: RouterOutlet): any {
    return outlet && outlet.activatedRouteData && outlet.activatedRouteData.animation;
  }
}
<div class="root">
  <app-top-toolbar (menuClick)="toggleMenu()" [showMenuButton]="isProjectSet$ | async" class="header"></app-top-toolbar>
  <mat-sidenav-container class="sidenav-container">
    <!--if you set fixedInViewPort on the sidenav it will appear to the left of the mat-tooblar instead of under it-->
    <mat-sidenav
      id="sidenav"
      class="sidenav"
      [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
      [mode]="(isHandset$ | async) ? 'over' : 'side'"
      [opened]="showDrawer"
      *ngIf="isProjectSet$ | async"
    >
      <app-side-nav></app-side-nav>
    </mat-sidenav>
    <mat-sidenav-content class="sidenav-content">
      <div class="container" [@routeAnimations]="prepareRoute(outlet)">
        <router-outlet #outlet="outlet"></router-outlet>
      </div>
    </mat-sidenav-content>
  </mat-sidenav-container>
</div>

./frame.component.scss

.sidenav-container {
  height: 100%;
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

.sidenav {
  width: 200px;
}

.sidenav .mat-toolbar {
  background: inherit;
}

.sidenav-content {
  display: flex;
  flex-flow: column;
  height: 100%;
}

.container {
  margin: 0;
  padding: 0;
  width: 100%;
  flex: 1 1 auto;
  overflow-y: auto;
}

.root {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  height: 100%;
  overflow-y: hidden;
}

.header {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""