Skip to content

Instantly share code, notes, and snippets.

@yokoishioka
Last active May 8, 2020 06:09
Show Gist options
  • Save yokoishioka/13c433d74c6422c3ab5d324f1636d7e3 to your computer and use it in GitHub Desktop.
Save yokoishioka/13c433d74c6422c3ab5d324f1636d7e3 to your computer and use it in GitHub Desktop.
<div cesDeviceScreenSize>
<div *ngIf="showMenuContent" [ngClass]="{'slide-down': this.allowToggle}" class="menu-container">
<ces-button title="close {{ menuTitle }}" class="button-icon-only menu-button-close" (click)="closeMenu()">
<ces-svg-x-circle class="menu-icon-close"></ces-svg-x-circle>
</ces-button>
<div class="menu-content" (click)="toggleNav()">
<ng-content></ng-content>
</div>
</div>
<ces-button *ngIf="showMenuButton" title="open {{ menuTitle }}" class="button-icon-only menu-button-open fade-in" (click)="openMenu()">
<ces-svg-ellipsis-vertical class="menu-icon-open"></ces-svg-ellipsis-vertical>
</ces-button>
</div>
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core';
import { DevicesService } from 'projects/devices/src/public-api';
import { distinctUntilChanged } from 'rxjs/operators';
import { Subscription } from 'rxjs';
@Component({
selector: 'ces-menu-toggle',
templateUrl: './menu-toggle.component.html',
styleUrls: ['./menu-toggle.component.scss']
})
export class MenuToggleComponent implements OnInit, OnDestroy {
@Input() showMenuButton: boolean = false;
@Input() showMenuContent: boolean = false;
@Input() menuTitle: string = "menu";
allowToggle: boolean;
sub: Subscription;
constructor(
private devices: DevicesService
) { }
ngOnInit() {
this.devices.detectSize = "type";
this.sub = this.devices.screenSize.pipe(distinctUntilChanged()).subscribe(size => {
this.checkSize(size);
})
}
ngOnDestroy() {
this.sub.unsubscribe();
}
closeMenu() {
this.showMenuButton = true;
this.showMenuContent = false;
}
openMenu() {
this.showMenuButton = false;
this.showMenuContent = true;
}
checkSize(size: string) {
if (size === 'medium') {
this.allowToggle = false;
this.openMenu();
}
else if (size === 'small') {
this.allowToggle = true;
this.closeMenu();
}
}
toggleNav() {
if (this.allowToggle) {
this.showMenuButton = !this.showMenuButton;
this.showMenuContent = !this.showMenuContent;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment