Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first and last page buttons to Pagination #2179

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/www/content/docs/components/pagination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationFirst,
PaginationItem,
PaginationLast,
PaginationLink,
PaginationNext,
PaginationPrevious,
Expand All @@ -55,6 +57,7 @@ import {
```tsx
<Pagination>
<PaginationContent>
<PaginationFirst href="#" />
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
Expand All @@ -67,6 +70,7 @@ import {
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
<PaginationLast href="#" />
</PaginationContent>
</Pagination>
```
Expand Down
4 changes: 4 additions & 0 deletions apps/www/registry/default/example/pagination-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationFirst,
PaginationItem,
PaginationLast,
PaginationLink,
PaginationNext,
PaginationPrevious,
Expand All @@ -12,6 +14,7 @@ export default function PaginationDemo() {
return (
<Pagination>
<PaginationContent>
<PaginationFirst href="#" />
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
Expand All @@ -32,6 +35,7 @@ export default function PaginationDemo() {
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
<PaginationLast href="#" />
</PaginationContent>
</Pagination>
)
Expand Down
42 changes: 41 additions & 1 deletion apps/www/registry/default/ui/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as React from "react"
import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react"
import {
ChevronFirst,
ChevronLast,
ChevronLeft,
ChevronRight,
MoreHorizontal,
} from "lucide-react"

import { cn } from "@/lib/utils"
import { ButtonProps, buttonVariants } from "@/registry/default/ui/button"
Expand Down Expand Up @@ -60,6 +66,22 @@ const PaginationLink = ({
)
PaginationLink.displayName = "PaginationLink"

const PaginationFirst = ({
className,
...props
}: React.ComponentProps<typeof PaginationLink>) => (
<PaginationLink
aria-label="Go to first page"
size="default"
className={cn("gap-1 pl-2.5", className)}
{...props}
>
<ChevronFirst className="h-4 w-4" />
<span>First</span>
</PaginationLink>
)
PaginationFirst.displayName = "PaginationFirst"

const PaginationPrevious = ({
className,
...props
Expand Down Expand Up @@ -91,6 +113,22 @@ const PaginationNext = ({
</PaginationLink>
)

const PaginationLast = ({
className,
...props
}: React.ComponentProps<typeof PaginationLink>) => (
<PaginationLink
aria-label="Go to last page"
size="default"
className={cn("gap-1 pr-2.5", className)}
{...props}
>
<span>Last</span>
<ChevronLast className="h-4 w-4" />
</PaginationLink>
)
PaginationLast.displayName = "PaginationLast"

const PaginationEllipsis = ({
className,
...props
Expand All @@ -113,4 +151,6 @@ export {
PaginationLink,
PaginationNext,
PaginationPrevious,
PaginationFirst,
PaginationLast,
}
4 changes: 4 additions & 0 deletions apps/www/registry/new-york/example/pagination-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationFirst,
PaginationItem,
PaginationLast,
PaginationLink,
PaginationNext,
PaginationPrevious,
Expand All @@ -12,6 +14,7 @@ export default function PaginationDemo() {
return (
<Pagination>
<PaginationContent>
<PaginationFirst href="#" />
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
Expand All @@ -32,6 +35,7 @@ export default function PaginationDemo() {
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
<PaginationLast href="#" />
</PaginationContent>
</Pagination>
)
Expand Down
36 changes: 36 additions & 0 deletions apps/www/registry/new-york/ui/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
ChevronLeftIcon,
ChevronRightIcon,
DotsHorizontalIcon,
DoubleArrowLeftIcon,
DoubleArrowRightIcon,
} from "@radix-ui/react-icons"

import { cn } from "@/lib/utils"
Expand Down Expand Up @@ -80,6 +82,22 @@ const PaginationPrevious = ({
)
PaginationPrevious.displayName = "PaginationPrevious"

const PaginationFirst = ({
className,
...props
}: React.ComponentProps<typeof PaginationLink>) => (
<PaginationLink
aria-label="Go to first page"
size="default"
className={cn("gap-1 pl-2.5", className)}
{...props}
>
<DoubleArrowLeftIcon className="h-4 w-4" />
<span>First</span>
</PaginationLink>
)
PaginationFirst.displayName = "PaginationFirst"

const PaginationNext = ({
className,
...props
Expand All @@ -95,6 +113,22 @@ const PaginationNext = ({
</PaginationLink>
)

const PaginationLast = ({
className,
...props
}: React.ComponentProps<typeof PaginationLink>) => (
<PaginationLink
aria-label="Go to last page"
size="default"
className={cn("gap-1 pr-2.5", className)}
{...props}
>
<span>Last</span>
<DoubleArrowRightIcon className="h-4 w-4" />
</PaginationLink>
)
PaginationLast.displayName = "PaginationLast"

const PaginationEllipsis = ({
className,
...props
Expand All @@ -117,4 +151,6 @@ export {
PaginationPrevious,
PaginationNext,
PaginationEllipsis,
PaginationFirst,
PaginationLast,
}