|
| 1 | +import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react'; |
| 2 | +import * as React from 'react'; |
| 3 | + |
| 4 | +import { Button, ButtonProps } from './Button'; |
| 5 | + |
| 6 | +const Pagination = ({ ...props }: React.ComponentProps<'nav'>) => ( |
| 7 | + <nav |
| 8 | + role="navigation" |
| 9 | + aria-label="pagination" |
| 10 | + className={'Pagination'} |
| 11 | + {...props} |
| 12 | + /> |
| 13 | +); |
| 14 | +Pagination.displayName = 'Pagination'; |
| 15 | + |
| 16 | +const PaginationContent = React.forwardRef< |
| 17 | + HTMLUListElement, |
| 18 | + React.ComponentProps<'ul'> |
| 19 | +>(({ ...props }, ref) => ( |
| 20 | + <ul ref={ref} className={'PaginationContent'} {...props} /> |
| 21 | +)); |
| 22 | +PaginationContent.displayName = 'PaginationContent'; |
| 23 | + |
| 24 | +const PaginationItem = React.forwardRef< |
| 25 | + HTMLLIElement, |
| 26 | + React.ComponentProps<'li'> |
| 27 | +>(({ ...props }, ref) => <li ref={ref} className="" {...props} />); |
| 28 | +PaginationItem.displayName = 'PaginationItem'; |
| 29 | + |
| 30 | +type PaginationLinkProps = { |
| 31 | + isActive?: boolean; |
| 32 | +} & Pick<ButtonProps, 'size'> & |
| 33 | + React.ComponentProps<'button'>; |
| 34 | + |
| 35 | +const PaginationLink = ({ |
| 36 | + isActive, |
| 37 | + size = 'icon', |
| 38 | + ...props |
| 39 | +}: PaginationLinkProps) => ( |
| 40 | + <Button |
| 41 | + aria-current={isActive ? 'page' : undefined} |
| 42 | + data-variant={isActive ? 'outline' : 'ghost'} |
| 43 | + data-size={size} |
| 44 | + className={'PaginationLink'} |
| 45 | + {...props} |
| 46 | + /> |
| 47 | +); |
| 48 | +PaginationLink.displayName = 'PaginationLink'; |
| 49 | + |
| 50 | +// size is 'default' from both next and previous |
| 51 | +const PaginationPrevious = ({ |
| 52 | + ...props |
| 53 | +}: React.ComponentProps<typeof PaginationLink>) => ( |
| 54 | + <PaginationLink |
| 55 | + aria-label="Go to previous page" |
| 56 | + className={'PaginationPrevious'} |
| 57 | + {...props} |
| 58 | + > |
| 59 | + <ChevronLeft |
| 60 | + style={{ |
| 61 | + height: '1rem', |
| 62 | + width: '1rem', |
| 63 | + flexShrink: 0, |
| 64 | + }} |
| 65 | + /> |
| 66 | + <span>Prev</span> |
| 67 | + </PaginationLink> |
| 68 | +); |
| 69 | +PaginationPrevious.displayName = 'PaginationPrevious'; |
| 70 | + |
| 71 | +const PaginationNext = ({ |
| 72 | + ...props |
| 73 | +}: React.ComponentProps<typeof PaginationLink>) => ( |
| 74 | + <PaginationLink |
| 75 | + aria-label="Go to next page" |
| 76 | + className={'PaginationNext'} |
| 77 | + {...props} |
| 78 | + > |
| 79 | + <span>Next</span> |
| 80 | + <ChevronRight |
| 81 | + style={{ |
| 82 | + height: '1rem', |
| 83 | + width: '1rem', |
| 84 | + flexShrink: 0, |
| 85 | + }} |
| 86 | + /> |
| 87 | + </PaginationLink> |
| 88 | +); |
| 89 | +PaginationNext.displayName = 'PaginationNext'; |
| 90 | + |
| 91 | +const PaginationEllipsis = ({ ...props }: React.ComponentProps<'span'>) => ( |
| 92 | + <span aria-hidden className={'PaginationEllipsis'} {...props}> |
| 93 | + <MoreHorizontal |
| 94 | + style={{ |
| 95 | + height: '1rem', |
| 96 | + width: '1rem', |
| 97 | + }} |
| 98 | + /> |
| 99 | + <span className="sr-only">More pages</span> |
| 100 | + </span> |
| 101 | +); |
| 102 | +PaginationEllipsis.displayName = 'PaginationEllipsis'; |
| 103 | + |
| 104 | +export { |
| 105 | + Pagination, |
| 106 | + PaginationContent, |
| 107 | + PaginationEllipsis, |
| 108 | + PaginationItem, |
| 109 | + PaginationLink, |
| 110 | + PaginationNext, |
| 111 | + PaginationPrevious, |
| 112 | +}; |
0 commit comments