Skip to content

Commit

Permalink
Sticky control panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy committed Sep 29, 2024
1 parent 57f73cb commit 355d482
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/item-detail/item-detail.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<app-control-panel *ngIf="!isAnonymous">
<app-control-panel *ngIf="!isAnonymous" shouldStick=true>
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<app-breadcrumb *ngIf="itemData.environment" [testName]="itemData.name"></app-breadcrumb>
Expand Down
7 changes: 6 additions & 1 deletion src/app/shared/control-panel/control-panel.component.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#top-panel {
margin-left: 10px;
margin-right: 10px;
margin-top: 20px;
padding-top: 20px !important;
border-radius: 0.2rem;
}

Expand All @@ -13,3 +13,8 @@
padding-bottom: 5px;
padding-top: 5px;
}

.navbar-inverse {
background-color: #f0f1f4;
padding-bottom: 20px !important;
}
2 changes: 1 addition & 1 deletion src/app/shared/control-panel/control-panel.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav class="navbar navbar-expand-lg navbar-light py-1 content-container" id="top-panel">
<nav class="navbar navbar-expand-lg navbar-light py-1 content-container" [ngClass]="{'sticky-top': shouldStick }" id="top-panel" (scroll)="onWindowScroll();">
<button class="navbar-toggler text-primary" type="button" (click)="toggleNavbar()">
<i class="fas fa-ellipsis-h"></i>
</button>
Expand Down
23 changes: 19 additions & 4 deletions src/app/shared/control-panel/control-panel.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { Component } from "@angular/core";
import { Component, HostListener, Input } from "@angular/core";

@Component({
selector: "app-control-panel",
templateUrl: "./control-panel.component.html",
styleUrls: ["./control-panel.component.css", "../../shared-styles.css"]
selector: 'app-control-panel',
templateUrl: './control-panel.component.html',
styleUrls: ['./control-panel.component.css', '../../shared-styles.css']
})
export class ControlPanelComponent {

@Input() shouldStick = false;

navbarOpen = false;

toggleNavbar() {
this.navbarOpen = !this.navbarOpen;
}

@HostListener('window:scroll', ['$event'])
onWindowScroll() {
if (!this.shouldStick) {
return
}
const element = document.querySelector("#top-panel") as HTMLElement;
if (window.pageYOffset > element.clientHeight) {
element.classList.add("navbar-inverse");
} else {
element.classList.remove("navbar-inverse");
}
}

}

0 comments on commit 355d482

Please sign in to comment.