Components
Pagination
Pagination with page navigation, next and previous links.
Loading...
Installation
CLI
npx shadcn@latest add https://exawizards.com/exabase/design/registry/pagination.jsonManual
Copy and paste the following code into your project.
import * as React from "react"
import {
ChevronLeftIcon,
ChevronRightIcon,
DotsHorizontalIcon,
} from "@exawizards/exabase-design-system-icons-react"
import { cn } from "@/lib/utils"
import { Button, buttonVariants } from "@/components/ui/button"
function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
return (
<nav
role="navigation"
aria-label="pagination"
data-slot="pagination"
className={cn("mx-auto flex w-full justify-center", className)}
{...props}
/>
)
}
function PaginationContent({
className,
...props
}: React.ComponentProps<"ul">) {
return (
<ul
data-slot="pagination-content"
className={cn("flex items-center gap-0.5", className)}
{...props}
/>
)
}
function PaginationItem({ ...props }: React.ComponentProps<"li">) {
return <li data-slot="pagination-item" {...props} />
}
type PaginationLinkProps = {
isActive?: boolean
} & Pick<React.ComponentProps<typeof Button>, "size"> &
React.ComponentProps<"a">
function PaginationLink({
className,
isActive,
size = "default",
...props
}: PaginationLinkProps) {
return (
<a
data-slot="pagination-link"
data-active={isActive}
data-size={size}
className={cn(
buttonVariants({ variant: isActive ? "outline" : "ghost", size }),
"flex data-[size=default]:min-w-8 data-[size=lg]:min-w-9 data-[size=sm]:min-w-7 data-[size=xs]:min-w-6",
className
)}
aria-current={isActive ? "page" : undefined}
{...props}
/>
)
}
function PaginationPrevious({
className,
text = "Previous",
...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to previous page"
size="default"
className={cn("pl-1.5!", className)}
{...props}
>
<ChevronLeftIcon data-icon="inline-start" />
<span className="hidden sm:block">{text}</span>
</PaginationLink>
)
}
function PaginationNext({
className,
text = "Next",
...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to next page"
size="default"
className={cn("pr-1.5!", className)}
{...props}
>
<span className="hidden sm:block">{text}</span>
<ChevronRightIcon data-icon="inline-end" />
</PaginationLink>
)
}
function PaginationEllipsis({
className,
size = "default",
...props
}: Pick<React.ComponentProps<typeof Button>, "size"> &
React.ComponentProps<"span">) {
return (
<span
aria-hidden
data-slot="pagination-ellipsis"
data-size={size}
className={cn(
"flex items-center justify-center data-[size=default]:w-8 data-[size=lg]:w-9 data-[size=sm]:w-7 data-[size=xs]:w-6",
className
)}
{...props}
>
<DotsHorizontalIcon />
<span className="sr-only">More pages</span>
</span>
)
}
export {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
}
Usage
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination"<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
</PaginationContent>
</Pagination>Next.js
By default the <PaginationLink /> component will render an <a /> tag.
To use the Next.js <Link /> component, make the following updates to pagination.tsx.
+ import Link from "next/link"
- type PaginationLinkProps = ... & React.ComponentProps<"a">
+ type PaginationLinkProps = ... & React.ComponentProps<typeof Link>
function PaginationLink({...}){
return (
- <a
+ <LinkExamples
Size
Loading...
Custom Text
<PaginationPrevious text="前へ" />
<PaginationNext text="次へ" />Loading...
API
PaginationLink
| Prop | Type | Default | Description |
|---|---|---|---|
isActive | Boolean | false | The active state of the link. |
size | xs | sm | default | lg | default | The size of the link. |
PaginationPrevious
| Prop | Type | Default | Description |
|---|---|---|---|
size | xs | sm | default | lg | default | The size of the link. |
text | string | Previous | The text of the link. |
PaginationNext
| Prop | Type | Default | Description |
|---|---|---|---|
size | xs | sm | default | lg | default | The size of the link. |
text | string | Next | The text of the link. |
PaginationEllipsis
The PaginationEllipsis component accept the following props.
| Prop | Type | Default | Description |
|---|---|---|---|
size | xs | sm | default | lg | default | The size of the link. |