Last active
July 12, 2018 05:37
-
-
Save M4R1KU/706a1c4b64f578700a2e9f1e61768590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div cdkOverlayOrigin | |
#origin="cdkOverlayOrigin" | |
#trigger> | |
<button mat-button (click)="openOverlay()"> | |
Open | |
</button> | |
</div> | |
<ng-template | |
cdkConnectedOverlay | |
hasBackdrop | |
backdropClass="cdk-overlay-transparent-backdrop" | |
[cdkConnectedOverlayOrigin]="searchFieldOrigin" | |
[cdkConnectedOverlayOpen]="showOverlay" | |
[cdkConnectedOverlayPositions]="positions" | |
[cdkConnectedOverlayMinWidth]="triggerWidth" | |
[cdkConnectedOverlayHeight]="triggerHeight" | |
(backdropClick)="closeSearchField()"> | |
<div class="overlay-content"> | |
Content goes here | |
</div> | |
</ng-template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; | |
import {ConnectionPositionPair} from '@angular/cdk/overlay'; | |
@Component({ | |
selector: 'overlay-demo', | |
templateUrl: './overlay-demo.html' | |
}) | |
export class OverlayDemoComponent implements OnInit { | |
@ViewChild('trigger') trigger: ElementRef; | |
public showOverlay: boolean = false; | |
private _triggerWidth: number; | |
private _triggerHeight: number; | |
private _positions: ConnectionPositionPair[] = [ | |
{ | |
originX: 'start', | |
originY: 'top', | |
overlayX: 'start', | |
overlayY: 'top', | |
offsetX: 0, | |
offsetY: 0 | |
} | |
]; | |
ngOnInit() { | |
this._refreshTriggerDimensions(); | |
} | |
public closeOverlay() { | |
this.showOverlay = false; | |
} | |
public openOverlay() { | |
this._refreshTriggerDimensions(); | |
this.showOverlay = true; | |
} | |
private _refreshTriggerDimensions() { | |
let clientRect = this.trigger.nativeElement.getBoundingClientRect(); | |
this._triggerWidth = clientRect.width; | |
this._triggerHeight = clientRect.height; | |
} | |
get positions(): ConnectionPositionPair[] { | |
return this._positions; | |
} | |
get triggerHeight(): number { | |
return this._triggerHeight; | |
} | |
get triggerWidth(): number { | |
return this._triggerWidth; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overlay Demo for connected overlay creation.