Files
dspace-angular/src/app/header/context-help-toggle/context-help-toggle.component.ts
2023-09-29 22:43:47 +02:00

41 lines
1.3 KiB
TypeScript

import { Component, OnInit, ElementRef } from '@angular/core';
import { ContextHelpService } from '../../shared/context-help.service';
import { Observable, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
/**
* Renders a "context help toggle" button that toggles the visibility of tooltip buttons on the page.
* If there are no tooltip buttons available on the current page, the toggle is unclickable.
*/
@Component({
selector: 'ds-context-help-toggle',
templateUrl: './context-help-toggle.component.html',
styleUrls: ['./context-help-toggle.component.scss']
})
export class ContextHelpToggleComponent implements OnInit {
buttonVisible$: Observable<boolean>;
subscriptions: Subscription[] = [];
constructor(
protected elRef: ElementRef,
protected contextHelpService: ContextHelpService,
) {
}
ngOnInit(): void {
this.buttonVisible$ = this.contextHelpService.tooltipCount$().pipe(map(x => x > 0));
this.subscriptions.push(this.buttonVisible$.subscribe((showContextHelpToggle: boolean) => {
if (showContextHelpToggle) {
this.elRef.nativeElement.classList.remove('d-none');
} else {
this.elRef.nativeElement.classList.add('d-none');
}
}));
}
onClick() {
this.contextHelpService.toggleIcons();
}
}