| 35 | }; |
| 36 | |
| 37 | export function Pagination({ |
| 38 | canNextPage, |
| 39 | canPreviousPage, |
| 40 | pageIndex, |
| 41 | firstPage, |
| 42 | lastPage, |
| 43 | nextPage, |
| 44 | previousPage, |
| 45 | className, |
| 46 | }: Props) { |
| 47 | const isFetching = useIsFetching() > 0; |
| 48 | const isLoading = isFetching; |
| 49 | return ( |
| 50 | <div |
| 51 | className={cn( |
| 52 | 'flex select-none items-center justify-end gap-1', |
| 53 | className, |
| 54 | )} |
| 55 | > |
| 56 | {typeof firstPage === 'function' && ( |
| 57 | <Button |
| 58 | variant="outline" |
| 59 | size="icon" |
| 60 | onClick={() => firstPage?.()} |
| 61 | disabled={!canPreviousPage} |
| 62 | className="max-sm:hidden" |
| 63 | icon={ChevronsLeftIcon} |
| 64 | /> |
| 65 | )} |
| 66 | <Button |
| 67 | variant="outline" |
| 68 | size="icon" |
| 69 | onClick={() => previousPage()} |
| 70 | disabled={!canPreviousPage} |
| 71 | icon={ChevronLeftIcon} |
| 72 | /> |
| 73 | |
| 74 | <Button |
| 75 | loading={isLoading} |
| 76 | loadingAbsolute |
| 77 | loadingType="ring" |
| 78 | disabled |
| 79 | variant="outline" |
| 80 | size="icon" |
| 81 | className={cn(typeof pageIndex === 'string' && 'min-w-8 w-auto px-2')} |
| 82 | > |
| 83 | {typeof pageIndex === 'number' ? pageIndex + 1 : pageIndex} |
| 84 | </Button> |
| 85 | |
| 86 | <Button |
| 87 | variant="outline" |
| 88 | size="icon" |
| 89 | onClick={() => nextPage()} |
| 90 | disabled={!canNextPage} |
| 91 | icon={ChevronRightIcon} |
| 92 | /> |
| 93 | |
| 94 | {typeof lastPage === 'function' && ( |