Skip to content

Commit

Permalink
Adding scroll to the top button #587, fixes #427
Browse files Browse the repository at this point in the history
  • Loading branch information
bpatrik committed Aug 8, 2023
1 parent d1ed607 commit b7529b1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/common/config/public/ClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export enum ThemeModes {
light = 1, dark, auto
}

export enum ScrollUpModes {
never = 1, mobileOnly, always
}

export type TAGS = {
client?: true,
priority?: ConfigPriority,
Expand Down Expand Up @@ -739,6 +743,17 @@ export class NavBarConfig {
description: $localize`Ratio of the page height, you need to scroll to hide the navigation bar.`,
})
NavbarHideDelay: number = 0.15;

@ConfigProperty({
tags: {
name: $localize`Show scroll up button`,
priority: ConfigPriority.underTheHood
},
type: ScrollUpModes,
description: $localize`Set when the floating scroll-up button should be visible.`,
})
showScrollUpButton: ScrollUpModes = ScrollUpModes.mobileOnly;

}

@SubConfigClass<TAGS>({tags: {client: true}, softReadonly: true})
Expand Down
14 changes: 14 additions & 0 deletions src/frontend/app/ui/frame/frame.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ a.dropdown-item span, button.dropdown-item span, div.dropdown-item span {
a.dropdown-item span.badge, button.dropdown-item span.badge {
margin-left: -0.8rem;
}

.btn-scroll-up {
position: fixed;
width: 3em;
height: 3em;
right: -3em;
bottom: 3em;
transition: 0.3s right;
z-index: 999;
}

.show-btn-scroll-up{
right: 1em;
}
13 changes: 10 additions & 3 deletions src/frontend/app/ui/frame/frame.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="container-fluid">
<a class="navbar-brand d-none d-sm-block" [routerLink]="['/gallery']"
[queryParams]="queryService.getParams()">
<app-icon class="d-inline-block align-top" [width]="30" [height]="30" ></app-icon>
<app-icon class="d-inline-block align-top" [width]="30" [height]="30"></app-icon>
<strong class="d-none d-lg-inline-block">{{title}}</strong>
</a>
<div class="collapse navbar-collapse text-center" id="navbarCollapse" [collapse]="collapsed">
Expand Down Expand Up @@ -57,14 +57,14 @@
</ng-container>
<li class="nav-item d-xl-block d-none">
<span>
<app-language #languageSelector class="navbar-btn" ></app-language>
<app-language #languageSelector class="navbar-btn"></app-language>
</span>
</li>
<li class="nav-item divider-vertical d-xl-block d-none">
</li>
<li class="nav-item dropdown">
<div class="btn-group" dropdown #dropdown="bs-dropdown" placement="bottom"
[autoClose]="false" container="body">
[autoClose]="false" container="body">
<button id="button-alignment" dropdownToggle
type="button" class="btn btn-tertiary dropdown-toggle"
aria-controls="dropdown-alignment">
Expand Down Expand Up @@ -204,3 +204,10 @@
<ng-content select="[navbar-appendix]"></ng-content>
</div>
<ng-content select="[body]"></ng-content>
<button
*ngIf="enableScrollUpButton"
(click)="scrollUp()"
[class.show-btn-scroll-up]="!shouldHideNavbar && !navbarKeepTop"
class="btn btn-tertiary rounded-pill btn-scroll-up">
<span class="oi oi-chevron-top"></span>
</button>
14 changes: 11 additions & 3 deletions src/frontend/app/ui/frame/frame.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {Config} from '../../../../common/config/public/Config';
import {BehaviorSubject} from 'rxjs';
import {NotificationService} from '../../model/notification.service';
import {QueryService} from '../../model/query.service';
import {NavigationLinkTypes, ThemeModes} from '../../../../common/config/public/ClientConfig';
import {NavigationLinkTypes, ScrollUpModes, ThemeModes} from '../../../../common/config/public/ClientConfig';
import {SearchQueryDTO} from '../../../../common/entities/SearchQueryDTO';
import {Utils} from '../../../../common/Utils';
import {PageHelper} from '../../model/page.helper';
import {BsDropdownDirective} from 'ngx-bootstrap/dropdown';
import {LanguageComponent} from '../language/language.component';
import {ThemeService} from '../../model/theme.service';
import {DeviceDetectorService} from 'ngx-device-detector';

@Component({
selector: 'app-frame',
Expand Down Expand Up @@ -49,14 +50,17 @@ export class FrameComponent {
@ViewChild('languageSelector', {static: true}) languageSelector: LanguageComponent;

ThemeModes = ThemeModes;
public readonly enableScrollUpButton: boolean;

constructor(
private authService: AuthenticationService,
public notificationService: NotificationService,
public queryService: QueryService,
private router: Router,
public themeService: ThemeService
public themeService: ThemeService,
private deviceService: DeviceDetectorService
) {
this.enableScrollUpButton = Config.Gallery.NavBar.showScrollUpButton === ScrollUpModes.always || (Config.Gallery.NavBar.showScrollUpButton === ScrollUpModes.mobileOnly && this.deviceService.isDesktop());
this.user = this.authService.user;
}

Expand Down Expand Up @@ -106,7 +110,7 @@ export class FrameComponent {
const down = this.lastScroll.any < scrollPosition;
const upDelay = up && this.lastScroll.down > scrollPosition + window.innerHeight * Config.Gallery.NavBar.NavbarShowDelay;
const downDelay = down && this.lastScroll.up < scrollPosition - window.innerHeight * Config.Gallery.NavBar.NavbarHideDelay;
//we are the top where the navbar by default lives
// We are the top where the navbar by default lives
if (this.navContainer.nativeElement.offsetHeight > scrollPosition) {
// do not force move navbar up when we are scrolling up from bottom
if (this.shouldHideNavbar != false || scrollPosition <= 0) {
Expand Down Expand Up @@ -141,5 +145,9 @@ export class FrameComponent {

this.lastScroll.any = scrollPosition;
}

scrollUp(): void {
PageHelper.ScrollY = 0;
}
}

6 changes: 3 additions & 3 deletions src/frontend/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ This is mostly btn-light
*/
.btn-tertiary, [data-bs-theme=light] .btn-tertiary {
--bs-btn-color: #000;
--bs-btn-bg: #f8f9fa;
--bs-btn-border-color: #f8f9fa;
--bs-btn-bg: var(--bs-body-bg);
--bs-btn-border-color: var(--bs-border-color);
--bs-btn-hover-color: #000;
--bs-btn-hover-bg: #d3d4d5;
--bs-btn-hover-border-color: #c6c7c8;
Expand All @@ -55,7 +55,7 @@ This is mostly btn-dark + border fix
*/
[data-bs-theme=dark] .btn-tertiary {
--bs-btn-color: #fff;
--bs-btn-bg: rgba(var(--bs-body-color-rgb), 0.03);
--bs-btn-bg: var(--bs-body-bg);
--bs-btn-border-color: var(--bs-border-color);
--bs-btn-hover-color: #fff;
--bs-btn-hover-bg: #424649;
Expand Down

0 comments on commit b7529b1

Please sign in to comment.