All files / app/layout/header/font-scale-control font-scale-control.component.ts

100% Statements 22/22
100% Branches 2/2
100% Functions 8/8
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 504x 4x 4x 4x                 4x 40x   40x 40x   40x 40x 40x 40x     5x       2x       2x 1x         4x       1x       1x      
import { FontScaleService } from '../../services/font-scale.service';
import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { ButtonComponent, IconButtonComponent } from '@drevo-web/ui';
 
@Component({
    selector: 'app-font-scale-control',
    imports: [CdkOverlayOrigin, CdkConnectedOverlay, IconButtonComponent, ButtonComponent],
    templateUrl: './font-scale-control.component.html',
    styleUrl: './font-scale-control.component.scss',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FontScaleControlComponent {
    private readonly fontScaleService = inject(FontScaleService);
 
    private readonly _isOpen = signal(false);
    readonly isOpen = this._isOpen.asReadonly();
 
    readonly scalePercent = this.fontScaleService.scalePercent;
    readonly canIncrease = this.fontScaleService.canIncrease;
    readonly canDecrease = this.fontScaleService.canDecrease;
    readonly isDefault = this.fontScaleService.isDefault;
 
    toggle(): void {
        this._isOpen.update(open => !open);
    }
 
    close(): void {
        this._isOpen.set(false);
    }
 
    onOverlayKeydown(event: KeyboardEvent): void {
        if (event.key === 'Escape') {
            this.close();
        }
    }
 
    increase(): void {
        this.fontScaleService.increase();
    }
 
    decrease(): void {
        this.fontScaleService.decrease();
    }
 
    reset(): void {
        this.fontScaleService.reset();
    }
}