infoalloggi-monorepo/apps/infoalloggi/src/components/ui/pagination.tsx

128 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-08-04 17:45:44 +02:00
import {
2025-08-28 18:27:07 +02:00
ChevronLeftIcon,
ChevronRightIcon,
MoreHorizontalIcon,
2025-08-04 17:45:44 +02:00
} from "lucide-react";
2025-08-28 18:27:07 +02:00
import type * as React from "react";
2025-08-04 17:45:44 +02:00
import { type Button, buttonVariants } from "~/components/ui/button";
2025-08-28 18:27:07 +02:00
import { cn } from "~/lib/utils";
2025-08-04 17:45:44 +02:00
function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
2025-08-28 18:27:07 +02:00
return (
<nav
// biome-ignore lint/a11y/noRedundantRoles: <ext>
role="navigation"
aria-label="pagination"
data-slot="pagination"
className={cn("mx-auto flex w-full justify-center", className)}
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function PaginationContent({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<"ul">) {
2025-08-28 18:27:07 +02:00
return (
<ul
data-slot="pagination-content"
className={cn("flex flex-row items-center gap-1", className)}
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function PaginationItem({ ...props }: React.ComponentProps<"li">) {
2025-08-28 18:27:07 +02:00
return <li data-slot="pagination-item" {...props} />;
2025-08-04 17:45:44 +02:00
}
type PaginationLinkProps = {
2025-08-28 18:27:07 +02:00
isActive?: boolean;
2025-08-04 17:45:44 +02:00
} & Pick<React.ComponentProps<typeof Button>, "size"> &
2025-08-28 18:27:07 +02:00
React.ComponentProps<"a">;
2025-08-04 17:45:44 +02:00
function PaginationLink({
2025-08-28 18:27:07 +02:00
className,
isActive,
size = "icon",
...props
2025-08-04 17:45:44 +02:00
}: PaginationLinkProps) {
2025-08-28 18:27:07 +02:00
return (
<a
aria-current={isActive ? "page" : undefined}
data-slot="pagination-link"
data-active={isActive}
className={cn(
buttonVariants({
variant: isActive ? "outline" : "ghost",
size,
}),
className,
)}
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function PaginationPrevious({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof PaginationLink>) {
2025-08-28 18:27:07 +02:00
return (
<PaginationLink
aria-label="Go to previous page"
size="default"
className={cn("gap-1 px-2.5 sm:pl-2.5", className)}
{...props}
>
<ChevronLeftIcon />
<span className="hidden sm:block">Previous</span>
</PaginationLink>
);
2025-08-04 17:45:44 +02:00
}
function PaginationNext({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof PaginationLink>) {
2025-08-28 18:27:07 +02:00
return (
<PaginationLink
aria-label="Go to next page"
size="default"
className={cn("gap-1 px-2.5 sm:pr-2.5", className)}
{...props}
>
<span className="hidden sm:block">Next</span>
<ChevronRightIcon />
</PaginationLink>
);
2025-08-04 17:45:44 +02:00
}
function PaginationEllipsis({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<"span">) {
2025-08-28 18:27:07 +02:00
return (
<span
aria-hidden
data-slot="pagination-ellipsis"
className={cn("flex size-9 items-center justify-center", className)}
{...props}
>
<MoreHorizontalIcon className="size-4" />
<span className="sr-only">More pages</span>
</span>
);
2025-08-04 17:45:44 +02:00
}
export {
2025-08-28 18:27:07 +02:00
Pagination,
PaginationContent,
PaginationLink,
PaginationItem,
PaginationPrevious,
PaginationNext,
PaginationEllipsis,
2025-08-04 17:45:44 +02:00
};