pagination.tsx
This file
Path
apps/web/src/components/ui/pagination.tsx
133 lines · 2.8 KiB · TypeScript
Last changed by
Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
History of this fileTake it
Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 1–133why, one step back1import { cn } from "cn";2import {3 ChevronLeftIcon,4 ChevronRightIcon,5 MoreHorizontalIcon,6} from "lucide-react";7import * as React from "react";89import { Button } from "@/components/ui/button";1011function Pagination({ className, ...props }: React.ComponentProps<"nav">) {12 return (13 <nav14 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}2223function PaginationContent({24 className,25 ...props26}: React.ComponentProps<"ul">) {27 return (28 <ul29 data-slot="pagination-content"30 className={cn("flex items-center gap-0.5", className)}31 {...props}32 />33 );34}3536function PaginationItem({ ...props }: React.ComponentProps<"li">) {37 return <li data-slot="pagination-item" {...props} />;38}3940type PaginationLinkProps = {41 isActive?: boolean;42} & Pick<React.ComponentProps<typeof Button>, "size"> &43 React.ComponentProps<"a">;4445function PaginationLink({46 className,47 isActive,48 size = "icon",49 ...props50}: PaginationLinkProps) {51 return (52 <Button53 variant={isActive ? "outline" : "ghost"}54 size={size}55 className={cn(className)}56 nativeButton={false}57 render={58 <a59 aria-current={isActive ? "page" : undefined}60 data-slot="pagination-link"61 data-active={isActive}62 {...props}63 />64 }65 />66 );67}6869function PaginationPrevious({70 className,71 text = "Previous",72 ...props73}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {74 return (75 <PaginationLink76 aria-label="Go to previous page"77 size="default"78 className={cn("pl-1.5!", className)}79 {...props}80 >81 <ChevronLeftIcon data-icon="inline-start" />82 <span className="hidden sm:block">{text}</span>83 </PaginationLink>84 );85}8687function PaginationNext({88 className,89 text = "Next",90 ...props91}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {92 return (93 <PaginationLink94 aria-label="Go to next page"95 size="default"96 className={cn("pr-1.5!", className)}97 {...props}98 >99 <span className="hidden sm:block">{text}</span>100 <ChevronRightIcon data-icon="inline-end" />101 </PaginationLink>102 );103}104105function PaginationEllipsis({106 className,107 ...props108}: React.ComponentProps<"span">) {109 return (110 <span111 aria-hidden112 data-slot="pagination-ellipsis"113 className={cn(114 "flex size-8 items-center justify-center [&_svg:not([class*='size-'])]:size-4",115 className116 )}117 {...props}118 >119 <MoreHorizontalIcon />120 <span className="sr-only">More pages</span>121 </span>122 );123}124125export {126 Pagination,127 PaginationContent,128 PaginationEllipsis,129 PaginationItem,130 PaginationLink,131 PaginationNext,132 PaginationPrevious,133};