Pagination
indiacn/paginationFreeComponent
Page navigation with default and flat variants in 3 sizes.
Install it
npx shadcn@latest add https://indiacn.in/r/pagination.jsonSource
1'use client';23import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react';4import { ComponentProps, createContext, useContext } from 'react';56import { Label2 } from '@/components/ui/typography';7import { cn } from '@/lib/utils';89type TPaginationSize = 'sm' | 'md' | 'lg';10type TPaginationVariant = 'default' | 'flat';1112const PAGINATION_CONTEXT = createContext<{ size: TPaginationSize; variant: TPaginationVariant }>({13 size: 'md',14 variant: 'default',15});1617/** Navigation pagination component. */18function Pagination({19 className,20 size = 'md',21 variant = 'default',22 ...props23}: ComponentProps<'nav'> & { size?: TPaginationSize; variant?: TPaginationVariant }) {24 return (25 <PAGINATION_CONTEXT.Provider value={{ size, variant }}>26 <nav27 role='navigation'28 aria-label='pagination'29 className={cn('mx-auto flex w-full justify-center', className)}30 {...props}31 />32 </PAGINATION_CONTEXT.Provider>33 );34}3536/** Container list for pagination items. */37function PaginationContent({ className, ...props }: ComponentProps<'ul'>) {38 const { variant } = useContext(PAGINATION_CONTEXT);3940 return (41 <ul42 className={cn(43 'flex list-none flex-row items-center pl-0',44 variant === 'flat'45 ? 'gap-1.5'46 : // The `first:`/`last:` Tailwind selectors compile to :first-child/:last-child.47 // Each <a> is the only child of its <li>, so applying them on the link48 // matches every link. Apply them at the <ul> level via descendant49 // selectors so only the actual edge items get rounded corners.50 'gap-0 [&>li:first-child>*]:rounded-l-md [&>li:last-child>*]:rounded-r-md',51 className,52 )}53 {...props}54 />55 );56}5758/** Single pagination list item wrapper. */59function PaginationItem({ className, ...props }: ComponentProps<'li'>) {60 return <li className={cn('list-none', className)} {...props} />;61}6263interface IPaginationLinkProps extends ComponentProps<'a'> {64 isActive?: boolean;65 disabled?: boolean;66 size?: TPaginationSize;67 variant?: TPaginationVariant;68}6970const PAGINATION_SIZE_CLASSES: Record<TPaginationVariant, Record<TPaginationSize, string>> = {71 default: {72 sm: 'px-2 py-1 text-sm',73 md: 'px-3 py-1.5 text-base',74 lg: 'px-6 py-3 text-lg',75 },76 flat: {77 sm: 'size-7 text-sm',78 md: 'size-8 text-base',79 lg: 'size-10 text-lg',80 },81};8283/** UX4G-style page link with default and flat variants. */84// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from indiacn
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | indiacn | Components | Free | 2 deps | |
| Alertalert | indiacn | Components | Free | 2 deps | |
| Badgebadge | indiacn | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | indiacn | Components | Free | 1 dep | |
| Buttonbutton | indiacn | Components | Free | 3 deps | |
| Button Groupbutton-group | indiacn | Components | Free | no deps | |
| Cardcard | indiacn | Components | Free | 1 dep | |
| Chipchip | indiacn | Components | Free | 2 deps |
