1
- import React , { ReactElement , ReactHTMLElement } from 'react' ;
1
+ import React , { ReactElement } from 'react' ;
2
2
import { ImageViewerNavProps } from '../../definitions' ;
3
- import { TbPhotoDown } from 'react-icons/tb' ;
3
+ import { TbChevronLeftPipe , TbChevronRightPipe , TbPhotoDown } from 'react-icons/tb' ;
4
+ import { useTranslation } from 'react-i18next' ;
5
+ import { Tooltip } from 'react-tooltip' ;
4
6
5
7
/**
6
8
* Navigation block
@@ -10,12 +12,13 @@ import { TbPhotoDown } from 'react-icons/tb';
10
12
* @returns {* }
11
13
*/
12
14
export default function ImageViewerNavigation ( props : ImageViewerNavProps ) {
15
+ const { t } = useTranslation ( ) ;
13
16
const { activeIndex = 0 , thumbWidth = 50 , thumbHeight = undefined , thumbSpace = 10 } = props ;
14
17
const [ listMarginLeft , setListMarginLeft ] = React . useState < number > ( 0 ) ;
15
18
16
19
React . useEffect ( ( ) => {
17
- if ( props . images && props . images [ activeIndex ] ) {
18
- let margin = ( ( activeIndex + 1 ) * ( thumbWidth + thumbSpace ) ) - ( thumbWidth / 2 ) ;
20
+ if ( props . images && props . images [ activeIndex ] ) {
21
+ let margin = ( activeIndex + 1 ) * ( thumbWidth + thumbSpace ) - thumbWidth / 2 ;
19
22
setListMarginLeft ( margin ) ;
20
23
}
21
24
} , [ props . images ] ) ;
@@ -30,22 +33,31 @@ export default function ImageViewerNavigation(props: ImageViewerNavProps) {
30
33
const imagesList = ( ) => {
31
34
let elements : ReactElement [ ] = [ ] ;
32
35
let styles = { } ;
33
- if ( thumbHeight )
34
- styles = { ...styles , height : `${ thumbHeight } px` } ;
36
+ if ( thumbHeight ) styles = { ...styles , height : `${ thumbHeight } px` } ;
35
37
styles = { ...styles , width : `${ thumbWidth } px` } ;
36
38
for ( let i = 0 ; i < props . imagesTotal ; i ++ ) {
37
39
let liElement = (
38
40
< li
39
41
key = { i }
40
- className = { ( i === activeIndex ) ? 'active' : '' }
41
- style = { { marginLeft : `${ thumbSpace } px` } }
42
+ className = { i === activeIndex ? 'active' : '' }
43
+ style = { { marginLeft : `${ thumbSpace } px` } }
42
44
onClick = { e => {
43
45
handleChangeImg ( i ) ;
44
46
} } >
45
47
{ props . images && props . images [ i ] ? (
46
- < img style = { styles } src = { props . images [ i ] . src } alt = { props . images [ i ] . alt } />
48
+ < img
49
+ style = { styles }
50
+ src = { props . images [ i ] . src }
51
+ alt = { props . images [ i ] . alt }
52
+ data-tooltip-id = 'navbar-tooltip'
53
+ data-tooltip-content = { props . images [ i ] . alt }
54
+ />
47
55
) : (
48
- < div className = "placeholder" style = { styles } >
56
+ < div
57
+ className = 'placeholder'
58
+ style = { styles }
59
+ data-tooltip-id = 'navbar-tooltip'
60
+ data-tooltip-content = { t ( 'navbarClickToDownload' ) } >
49
61
< TbPhotoDown />
50
62
</ div >
51
63
) }
@@ -58,10 +70,41 @@ export default function ImageViewerNavigation(props: ImageViewerNavProps) {
58
70
} ;
59
71
60
72
return (
61
- < div className = 'navbar' >
62
- < ul className = 'list list-transition' style = { { marginLeft : `calc(50% - ${ listMarginLeft } px)` } } >
63
- { imagesList ( ) }
64
- </ ul >
65
- </ div >
73
+ < >
74
+ < div className = 'navbar' >
75
+ < button
76
+ type = 'button'
77
+ className = 'navbar-goto-first'
78
+ onClick = { e => {
79
+ handleChangeImg ( 0 ) ;
80
+ } }
81
+ disabled = { activeIndex === 0 }
82
+ data-tooltip-id = 'navbar-tooltip'
83
+ data-tooltip-content = { t ( 'gotoFirst' ) }
84
+ data-tooltip-place = 'right'
85
+ data-tooltip-hidden = { activeIndex === 0 } >
86
+ < TbChevronLeftPipe />
87
+ </ button >
88
+ < div className = 'wrapper' >
89
+ < ul className = 'list list-transition' style = { { marginLeft : `calc(50% - ${ listMarginLeft } px)` } } >
90
+ { imagesList ( ) }
91
+ </ ul >
92
+ </ div >
93
+ < button
94
+ type = 'button'
95
+ className = 'navbar-goto-last'
96
+ onClick = { e => {
97
+ handleChangeImg ( props . imagesTotal - 1 ) ;
98
+ } }
99
+ disabled = { activeIndex === props . imagesTotal - 1 }
100
+ data-tooltip-id = 'navbar-tooltip'
101
+ data-tooltip-content = { t ( 'gotoLast' ) }
102
+ data-tooltip-place = 'left'
103
+ data-tooltip-hidden = { activeIndex === props . imagesTotal - 1 } >
104
+ < TbChevronRightPipe />
105
+ </ button >
106
+ </ div >
107
+ < Tooltip id = 'navbar-tooltip' />
108
+ </ >
66
109
) ;
67
110
}
0 commit comments