|
1 | 1 | import * as React from 'react' |
2 | | -import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react' |
| 2 | +import { |
| 3 | + ChevronLeftIcon, |
| 4 | + ChevronRightIcon, |
| 5 | + MoreHorizontalIcon, |
| 6 | +} from 'lucide-react' |
3 | 7 |
|
4 | 8 | import { cn } from '@/lib/utils' |
5 | | -import { ButtonProps, buttonVariants } from '@/components/ui/button' |
6 | | -import Link from 'next/link' |
| 9 | +import { Button, buttonVariants } from '@/components/ui/button' |
7 | 10 |
|
8 | | -const Pagination = ({ className, ...props }: React.ComponentProps<'nav'>) => ( |
9 | | - <nav |
10 | | - role="navigation" |
11 | | - aria-label="pagination" |
12 | | - className={cn('mx-auto flex w-full justify-center', className)} |
13 | | - {...props} |
14 | | - /> |
15 | | -) |
16 | | -Pagination.displayName = 'Pagination' |
| 11 | +function Pagination({ className, ...props }: React.ComponentProps<'nav'>) { |
| 12 | + return ( |
| 13 | + <nav |
| 14 | + role="navigation" |
| 15 | + aria-label="pagination" |
| 16 | + data-slot="pagination" |
| 17 | + className={cn('mx-auto flex w-full justify-center', className)} |
| 18 | + {...props} |
| 19 | + /> |
| 20 | + ) |
| 21 | +} |
17 | 22 |
|
18 | | -const PaginationContent = React.forwardRef< |
19 | | - HTMLUListElement, |
20 | | - React.ComponentProps<'ul'> |
21 | | ->(({ className, ...props }, ref) => ( |
22 | | - <ul |
23 | | - ref={ref} |
24 | | - className={cn('flex flex-row items-center gap-1', className)} |
25 | | - {...props} |
26 | | - /> |
27 | | -)) |
28 | | -PaginationContent.displayName = 'PaginationContent' |
| 23 | +function PaginationContent({ |
| 24 | + className, |
| 25 | + ...props |
| 26 | +}: React.ComponentProps<'ul'>) { |
| 27 | + return ( |
| 28 | + <ul |
| 29 | + data-slot="pagination-content" |
| 30 | + className={cn('flex flex-row items-center gap-1', className)} |
| 31 | + {...props} |
| 32 | + /> |
| 33 | + ) |
| 34 | +} |
29 | 35 |
|
30 | | -const PaginationItem = React.forwardRef< |
31 | | - HTMLLIElement, |
32 | | - React.ComponentProps<'li'> |
33 | | ->(({ className, ...props }, ref) => ( |
34 | | - <li ref={ref} className={cn('', className)} {...props} /> |
35 | | -)) |
36 | | -PaginationItem.displayName = 'PaginationItem' |
| 36 | +function PaginationItem({ ...props }: React.ComponentProps<'li'>) { |
| 37 | + return <li data-slot="pagination-item" {...props} /> |
| 38 | +} |
37 | 39 |
|
38 | 40 | type PaginationLinkProps = { |
39 | 41 | isActive?: boolean |
40 | | -} & Pick<ButtonProps, 'size'> & |
41 | | - React.ComponentProps<typeof Link> |
| 42 | +} & Pick<React.ComponentProps<typeof Button>, 'size'> & |
| 43 | + React.ComponentProps<'a'> |
42 | 44 |
|
43 | | -const PaginationLink = ({ |
| 45 | +function PaginationLink({ |
44 | 46 | className, |
45 | 47 | isActive, |
46 | 48 | size = 'icon', |
47 | 49 | ...props |
48 | | -}: PaginationLinkProps) => ( |
49 | | - <Link |
50 | | - aria-current={isActive ? 'page' : undefined} |
51 | | - className={cn( |
52 | | - buttonVariants({ |
53 | | - variant: isActive ? 'outline' : 'ghost', |
54 | | - size, |
55 | | - }), |
56 | | - className |
57 | | - )} |
58 | | - {...props} |
59 | | - /> |
60 | | -) |
61 | | -PaginationLink.displayName = 'PaginationLink' |
| 50 | +}: PaginationLinkProps) { |
| 51 | + return ( |
| 52 | + <a |
| 53 | + aria-current={isActive ? 'page' : undefined} |
| 54 | + data-slot="pagination-link" |
| 55 | + data-active={isActive} |
| 56 | + className={cn( |
| 57 | + buttonVariants({ |
| 58 | + variant: isActive ? 'outline' : 'ghost', |
| 59 | + size, |
| 60 | + }), |
| 61 | + className |
| 62 | + )} |
| 63 | + {...props} |
| 64 | + /> |
| 65 | + ) |
| 66 | +} |
62 | 67 |
|
63 | | -const PaginationPrevious = ({ |
| 68 | +function PaginationPrevious({ |
64 | 69 | className, |
65 | 70 | ...props |
66 | | -}: React.ComponentProps<typeof PaginationLink>) => ( |
67 | | - <PaginationLink |
68 | | - aria-label="Go to previous page" |
69 | | - size="default" |
70 | | - className={cn('gap-1 pl-2.5', className)} |
71 | | - {...props} |
72 | | - > |
73 | | - <ChevronLeft className="size-4" /> |
74 | | - <span>Previous</span> |
75 | | - </PaginationLink> |
76 | | -) |
77 | | -PaginationPrevious.displayName = 'PaginationPrevious' |
| 71 | +}: React.ComponentProps<typeof PaginationLink>) { |
| 72 | + return ( |
| 73 | + <PaginationLink |
| 74 | + aria-label="Go to previous page" |
| 75 | + size="default" |
| 76 | + className={cn('gap-1 px-2.5 sm:pl-2.5', className)} |
| 77 | + {...props} |
| 78 | + > |
| 79 | + <ChevronLeftIcon /> |
| 80 | + <span className="hidden sm:block">Previous</span> |
| 81 | + </PaginationLink> |
| 82 | + ) |
| 83 | +} |
78 | 84 |
|
79 | | -const PaginationNext = ({ |
| 85 | +function PaginationNext({ |
80 | 86 | className, |
81 | 87 | ...props |
82 | | -}: React.ComponentProps<typeof PaginationLink>) => ( |
83 | | - <PaginationLink |
84 | | - aria-label="Go to next page" |
85 | | - size="default" |
86 | | - className={cn('gap-1 pr-2.5', className)} |
87 | | - {...props} |
88 | | - > |
89 | | - <span>Next</span> |
90 | | - <ChevronRight className="size-4" /> |
91 | | - </PaginationLink> |
92 | | -) |
93 | | -PaginationNext.displayName = 'PaginationNext' |
| 88 | +}: React.ComponentProps<typeof PaginationLink>) { |
| 89 | + return ( |
| 90 | + <PaginationLink |
| 91 | + aria-label="Go to next page" |
| 92 | + size="default" |
| 93 | + className={cn('gap-1 px-2.5 sm:pr-2.5', className)} |
| 94 | + {...props} |
| 95 | + > |
| 96 | + <span className="hidden sm:block">Next</span> |
| 97 | + <ChevronRightIcon /> |
| 98 | + </PaginationLink> |
| 99 | + ) |
| 100 | +} |
94 | 101 |
|
95 | | -const PaginationEllipsis = ({ |
| 102 | +function PaginationEllipsis({ |
96 | 103 | className, |
97 | 104 | ...props |
98 | | -}: React.ComponentProps<'span'>) => ( |
99 | | - <span |
100 | | - aria-hidden |
101 | | - className={cn('flex size-9 items-center justify-center', className)} |
102 | | - {...props} |
103 | | - > |
104 | | - <MoreHorizontal className="size-4" /> |
105 | | - <span className="sr-only">More pages</span> |
106 | | - </span> |
107 | | -) |
108 | | -PaginationEllipsis.displayName = 'PaginationEllipsis' |
| 105 | +}: React.ComponentProps<'span'>) { |
| 106 | + return ( |
| 107 | + <span |
| 108 | + aria-hidden |
| 109 | + data-slot="pagination-ellipsis" |
| 110 | + className={cn('flex size-9 items-center justify-center', className)} |
| 111 | + {...props} |
| 112 | + > |
| 113 | + <MoreHorizontalIcon className="size-4" /> |
| 114 | + <span className="sr-only">More pages</span> |
| 115 | + </span> |
| 116 | + ) |
| 117 | +} |
109 | 118 |
|
110 | 119 | export { |
111 | 120 | Pagination, |
112 | 121 | PaginationContent, |
113 | | - PaginationEllipsis, |
114 | | - PaginationItem, |
115 | 122 | PaginationLink, |
116 | | - PaginationNext, |
| 123 | + PaginationItem, |
117 | 124 | PaginationPrevious, |
| 125 | + PaginationNext, |
| 126 | + PaginationEllipsis, |
118 | 127 | } |
0 commit comments