1
- import { Button , Flex , IconButton , Spacer } from '@invoke-ai/ui-library' ;
1
+ import { Button , CompositeNumberInput , Flex , Icon , IconButton , Spacer } from '@invoke-ai/ui-library' ;
2
2
import { ELLIPSIS , useGalleryPagination } from 'features/gallery/hooks/useGalleryPagination' ;
3
3
import { useCallback } from 'react' ;
4
- import { PiCaretLeftBold , PiCaretRightBold } from 'react-icons/pi' ;
4
+ import { PiCaretLeftBold , PiCaretRightBold , PiDotsThreeBold } from 'react-icons/pi' ;
5
5
6
6
export const GalleryPagination = ( ) => {
7
7
const { goPrev, goNext, isPrevEnabled, isNextEnabled, pageButtons, goToPage, currentPage, total } =
@@ -15,48 +15,63 @@ export const GalleryPagination = () => {
15
15
goNext ( ) ;
16
16
} , [ goNext ] ) ;
17
17
18
+ const onChangeJumpTo = useCallback (
19
+ ( v : number ) => {
20
+ goToPage ( v - 1 ) ;
21
+ } ,
22
+ [ goToPage ]
23
+ ) ;
24
+
18
25
if ( ! total ) {
19
26
return null ;
20
27
}
21
28
22
29
return (
23
- < Flex gap = { 2 } alignItems = "center" w = "full" >
24
- < IconButton
25
- size = "sm"
26
- aria-label = "prev"
27
- icon = { < PiCaretLeftBold /> }
28
- onClick = { onClickPrev }
29
- isDisabled = { ! isPrevEnabled }
30
- variant = "ghost"
31
- />
32
- < Spacer />
33
- { pageButtons . map ( ( page , i ) => {
34
- if ( page === ELLIPSIS ) {
35
- return (
36
- < Button size = "sm" key = { `ellipsis_${ i } ` } variant = "link" isDisabled >
37
- ...
38
- </ Button >
39
- ) ;
40
- }
41
- return (
42
- < Button
43
- size = "sm"
44
- key = { page }
45
- onClick = { goToPage . bind ( null , page - 1 ) }
46
- variant = { currentPage === page - 1 ? 'solid' : 'outline' }
47
- >
48
- { page }
49
- </ Button >
50
- ) ;
51
- } ) }
52
- < Spacer />
53
- < IconButton
54
- size = "sm"
55
- aria-label = "next"
56
- icon = { < PiCaretRightBold /> }
57
- onClick = { onClickNext }
58
- isDisabled = { ! isNextEnabled }
59
- variant = "ghost"
30
+ < Flex justifyContent = "space-between" alignItems = "center" w = "full" >
31
+ < Spacer w = "auto" />
32
+ < Flex flexGrow = "1" justifyContent = "center" >
33
+ < Flex gap = { 1 } alignItems = "center" >
34
+ < IconButton
35
+ size = "xs"
36
+ aria-label = "prev"
37
+ icon = { < PiCaretLeftBold /> }
38
+ onClick = { onClickPrev }
39
+ isDisabled = { ! isPrevEnabled }
40
+ variant = "ghost"
41
+ />
42
+ { pageButtons . map ( ( page , i ) => {
43
+ if ( page === ELLIPSIS ) {
44
+ return < Icon as = { PiDotsThreeBold } boxSize = "4" key = { `ellipsis-${ i } ` } /> ;
45
+ }
46
+ return (
47
+ < Button
48
+ size = "xs"
49
+ key = { page }
50
+ onClick = { goToPage . bind ( null , page - 1 ) }
51
+ variant = { currentPage === page - 1 ? 'solid' : 'outline' }
52
+ >
53
+ { page }
54
+ </ Button >
55
+ ) ;
56
+ } ) }
57
+ < IconButton
58
+ size = "xs"
59
+ aria-label = "next"
60
+ icon = { < PiCaretRightBold /> }
61
+ onClick = { onClickNext }
62
+ isDisabled = { ! isNextEnabled }
63
+ variant = "ghost"
64
+ />
65
+ </ Flex >
66
+ </ Flex >
67
+ < CompositeNumberInput
68
+ size = "xs"
69
+ maxW = "60px"
70
+ value = { currentPage + 1 }
71
+ min = { 1 }
72
+ max = { total }
73
+ step = { 1 }
74
+ onChange = { onChangeJumpTo }
60
75
/>
61
76
</ Flex >
62
77
) ;
0 commit comments