diff --git a/src/components/Pagination/AutoPagination.tsx b/src/components/Pagination/AutoPagination.tsx index 3006000..56b9f71 100644 --- a/src/components/Pagination/AutoPagination.tsx +++ b/src/components/Pagination/AutoPagination.tsx @@ -1,17 +1,17 @@ -import React from 'react'; - import { Pagination } from './Pagination'; import { PaginationContent } from './PaginationContent'; import { PaginationItem } from './PaginationItem'; -import { PaginationLink, PaginationNext, PaginationPrevious } from './PaginationLink'; +import { PaginationLink, PaginationNextLink, PaginationPreviousLink } from './PaginationLink'; interface AutoPaginationProps { pageNo: number; pageSize: number; pageGap?: number; + + linkas?: React.ElementType; } -export const AutoPagination = ({ pageNo, pageSize, pageGap = 10 }: AutoPaginationProps) => { +export const AutoPagination = ({ pageNo, pageSize, pageGap = 10, linkas }: AutoPaginationProps) => { const start = Math.floor(pageNo / (pageGap + 1)) * pageGap; const end = Math.min(start + pageGap, pageSize); const pages = Array.from({ length: end - start }, (_, index) => index + start + 1); @@ -20,17 +20,27 @@ export const AutoPagination = ({ pageNo, pageSize, pageGap = 10 }: AutoPaginatio - + {pages.map(page => ( - + {page} ))} - = pageSize} href={`?page=${end + 1}`} /> + = pageSize} + href={`?page=${end + 1}`} + to={`?page=${end + 1}`} + as={linkas} + /> diff --git a/src/components/Pagination/PaginationLink.tsx b/src/components/Pagination/PaginationLink.tsx index 6b81e40..6871c5f 100644 --- a/src/components/Pagination/PaginationLink.tsx +++ b/src/components/Pagination/PaginationLink.tsx @@ -7,10 +7,17 @@ import { composeEventHandlers } from '@/libs/event'; interface PaginationLinkProps extends React.ComponentPropsWithoutRef<'a'> { active?: boolean; disabled?: boolean; + + as?: React.ElementType; + + /* + * For React-Router-Dom Link + */ + to?: string; } export const PaginationLink = React.forwardRef( - ({ active = false, disabled = false, onClick, ...props }, ref) => { + ({ active = false, disabled = false, onClick, as, ...props }, ref) => { const handleOnclick = (e: React.MouseEvent) => { if (disabled) e.preventDefault(); }; @@ -18,9 +25,9 @@ export const PaginationLink = React.forwardRef {disabled ? ( - + ) : ( - + )} ); @@ -28,7 +35,12 @@ export const PaginationLink = React.forwardRef { +export const PaginationPreviousLink = ({ + active = false, + disabled = false, + children, + ...props +}: PaginationLinkProps) => { return ( { +export const PaginationNextLink = ({ active = false, disabled = false, children, ...props }: PaginationLinkProps) => { return ( {children} diff --git a/src/stories/common/Pagination.stories.tsx b/src/stories/common/Pagination.stories.tsx index 2b102c2..e40e1db 100644 --- a/src/stories/common/Pagination.stories.tsx +++ b/src/stories/common/Pagination.stories.tsx @@ -7,7 +7,7 @@ import { PaginationContent, PaginationItem, PaginationLink, - PaginationPrevious, + PaginationPreviousLink, } from '../../'; const meta = { @@ -51,7 +51,7 @@ export const Disabled: Story = { return ( - + {[1, 2, 3].map(page => ( {page}