Skip to content

Commit 2a9fdc6

Browse files
Mary Hipppsychedelicious
authored andcommitted
feat(ui): add jump to option for gallery pagination
1 parent 3657285 commit 2a9fdc6

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageGrid/GalleryPagination.tsx

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Button, Flex, IconButton, Spacer } from '@invoke-ai/ui-library';
1+
import { Button, CompositeNumberInput, Flex, Icon, IconButton, Spacer } from '@invoke-ai/ui-library';
22
import { ELLIPSIS, useGalleryPagination } from 'features/gallery/hooks/useGalleryPagination';
33
import { useCallback } from 'react';
4-
import { PiCaretLeftBold, PiCaretRightBold } from 'react-icons/pi';
4+
import { PiCaretLeftBold, PiCaretRightBold, PiDotsThreeBold } from 'react-icons/pi';
55

66
export const GalleryPagination = () => {
77
const { goPrev, goNext, isPrevEnabled, isNextEnabled, pageButtons, goToPage, currentPage, total } =
@@ -15,48 +15,63 @@ export const GalleryPagination = () => {
1515
goNext();
1616
}, [goNext]);
1717

18+
const onChangeJumpTo = useCallback(
19+
(v: number) => {
20+
goToPage(v - 1);
21+
},
22+
[goToPage]
23+
);
24+
1825
if (!total) {
1926
return null;
2027
}
2128

2229
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}
6075
/>
6176
</Flex>
6277
);

0 commit comments

Comments
 (0)