1+ import { animate , keyframes , style , transition , trigger } from '@angular/animations' ;
12import { CommonModule } from '@angular/common' ;
2- import { Component , input , output } from '@angular/core' ;
3+ import { Component , input , output , signal } from '@angular/core' ;
34import { SgcButton , SgcIcon } from '@swissgeol/ui-core-angular' ;
45
56export type PdfNavigationAction = 'next' | 'previous' | 'start' | 'end' ;
@@ -8,13 +9,31 @@ export type PdfNavigationAction = 'next' | 'previous' | 'start' | 'end';
89 imports : [ CommonModule , SgcButton , SgcIcon ] ,
910 templateUrl : './pdf-viewer-navigation.component.html' ,
1011 styleUrl : './pdf-viewer-navigation.component.scss' ,
12+ animations : [
13+ trigger ( 'shake' , [
14+ transition ( 'false => true' , [
15+ animate (
16+ '0.4s ease-in-out' ,
17+ keyframes ( [
18+ style ( { transform : 'translateX(0)' , offset : 0 } ) ,
19+ style ( { transform : 'translateX(-4px)' , offset : 0.2 } ) ,
20+ style ( { transform : 'translateX(4px)' , offset : 0.4 } ) ,
21+ style ( { transform : 'translateX(-3px)' , offset : 0.6 } ) ,
22+ style ( { transform : 'translateX(3px)' , offset : 0.8 } ) ,
23+ style ( { transform : 'translateX(0)' , offset : 1 } ) ,
24+ ] ) ,
25+ ) ,
26+ ] ) ,
27+ ] ) ,
28+ ] ,
1129} )
1230export class PdfViewerNavigationComponent {
1331 public readonly currentPage = input < number | undefined > ( ) ;
1432 public readonly pageCount = input < number | undefined > ( ) ;
1533 public readonly disableInteractions = input ( false ) ;
1634 public readonly navigate = output < PdfNavigationAction > ( ) ;
1735 public readonly goToPage = output < number > ( ) ;
36+ protected readonly showError = signal ( false ) ;
1837
1938 protected handleNavigate ( action : PdfNavigationAction ) {
2039 this . navigate . emit ( action ) ;
@@ -24,12 +43,18 @@ export class PdfViewerNavigationComponent {
2443 const trimmed = input . value . trim ( ) ;
2544 const count = this . pageCount ( ) ;
2645 const page = / ^ \d + $ / . test ( trimmed ) ? Number . parseInt ( trimmed , 10 ) : Number . NaN ;
46+ input . blur ( ) ;
47+
2748 if ( ! Number . isNaN ( page ) && count != null && page >= 1 && page <= count ) {
49+ input . value = page . toString ( ) ;
2850 this . goToPage . emit ( page ) ;
2951 } else {
30- this . resetInputValue ( input ) ;
52+ this . showError . set ( true ) ;
3153 }
32- input . blur ( ) ;
54+ }
55+
56+ protected onShakeDone ( ) {
57+ this . showError . set ( false ) ;
3358 }
3459
3560 protected resetInputValue ( input : HTMLInputElement ) {
0 commit comments