Skip to content

Commit

Permalink
Add support for custom onItemClick
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jun 6, 2023
1 parent a843cb7 commit 9f0f218
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,27 @@ export default function Thumbnail(props: ThumbnailProps) {
'Unable to find Document context. Did you wrap <Page /> in <Document />?',
);

const { linkService } = documentContext;
const { linkService, onItemClick } = documentContext;

const pageIndex = isProvided(pageNumberProps) ? pageNumberProps - 1 : pageIndexProps ?? null;

const pageNumber = pageNumberProps ?? (isProvided(pageIndexProps) ? pageIndexProps + 1 : null);

function onClick(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();

if (!pageNumber) {
if (!isProvided(pageIndex) || !pageNumber) {
return;
}

linkService.goToPage(pageNumber);
if (onItemClick) {
onItemClick({
pageIndex,
pageNumber,
});
} else {
linkService.goToPage(pageNumber);
}
}

return (
Expand Down

0 comments on commit 9f0f218

Please sign in to comment.