This repository was archived by the owner on Jul 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: ECOM-80 add pagination to catalog page #41
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1e136d3
feat: ECOM-80 add pagination to catalog page
merucoding 422e085
fix: ECOM-80 reset to first page when searching
merucoding e4a473d
feat: ECOM-78 add disabled state to add to cart button
merucoding 09ea2fa
refactor: ECOM-77 resolve PR comments
merucoding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { ChevronLeftIcon, ChevronRightIcon, ChevronsLeft, ChevronsRight, MoreHorizontalIcon } from 'lucide-react' | ||
|
|
||
| import { cn } from '~/utils/ui' | ||
| import type { Button } from '~/components/ui/Button' | ||
| import { buttonVariants } from '~/components/ui/Button' | ||
| import type { ComponentProps, ReactElement } from 'react' | ||
|
|
||
| function Pagination({ className, ...properties }: ComponentProps<'nav'>): ReactElement { | ||
| return ( | ||
| <nav | ||
| role="navigation" | ||
| aria-label="pagination" | ||
| data-slot="pagination" | ||
| className={cn('mx-auto flex w-full justify-center my-4', className)} | ||
| {...properties} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationContent({ className, ...properties }: ComponentProps<'ul'>): ReactElement { | ||
| return ( | ||
| <ul data-slot="pagination-content" className={cn('flex flex-row items-center gap-1', className)} {...properties} /> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationItem({ ...properties }: ComponentProps<'li'>): ReactElement { | ||
| return <li data-slot="pagination-item" {...properties} /> | ||
| } | ||
|
|
||
| type PaginationLinkProperties = { | ||
| isActive?: boolean | ||
| } & Pick<ComponentProps<typeof Button>, 'size'> & | ||
| ComponentProps<'a'> | ||
|
|
||
| function PaginationLink({ className, isActive, size = 'icon', ...properties }: PaginationLinkProperties): ReactElement { | ||
| return ( | ||
| <a | ||
| aria-current={isActive ? 'page' : undefined} | ||
| data-slot="pagination-link" | ||
| data-active={isActive} | ||
| className={cn( | ||
| buttonVariants({ | ||
| variant: isActive ? 'outline' : 'ghost', | ||
| size | ||
| }), | ||
| className | ||
| )} | ||
| {...properties} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationPrevious({ className, ...properties }: ComponentProps<typeof PaginationLink>): ReactElement { | ||
| return ( | ||
| <PaginationLink | ||
| aria-label="Go to previous page" | ||
| size="default" | ||
| className={cn('gap-1 px-2.5 sm:pl-2.5', className)} | ||
| {...properties} | ||
| > | ||
| <ChevronLeftIcon /> | ||
| <span className="hidden sm:block">Previous</span> | ||
| </PaginationLink> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationNext({ className, ...properties }: ComponentProps<typeof PaginationLink>): ReactElement { | ||
| return ( | ||
| <PaginationLink | ||
| aria-label="Go to next page" | ||
| size="default" | ||
| className={cn('gap-1 px-2.5 sm:pr-2.5', className)} | ||
| {...properties} | ||
| > | ||
| <span className="hidden sm:block">Next</span> | ||
| <ChevronRightIcon /> | ||
| </PaginationLink> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationStart({ className, ...properties }: ComponentProps<typeof PaginationLink>): ReactElement { | ||
| return ( | ||
| <PaginationLink | ||
| aria-label="Go to first page" | ||
| size="default" | ||
| className={cn('gap-1 px-2.5 sm:pl-2.5', className)} | ||
| {...properties} | ||
| > | ||
| <ChevronsLeft /> | ||
| <span className="hidden sm:block">Start</span> | ||
| </PaginationLink> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationEnd({ className, ...properties }: ComponentProps<typeof PaginationLink>): ReactElement { | ||
| return ( | ||
| <PaginationLink | ||
| aria-label="Go to last page" | ||
| size="default" | ||
| className={cn('gap-1 px-2.5 sm:pr-2.5', className)} | ||
| {...properties} | ||
| > | ||
| <span className="hidden sm:block">End</span> | ||
| <ChevronsRight /> | ||
| </PaginationLink> | ||
| ) | ||
| } | ||
|
|
||
| function PaginationEllipsis({ className, ...properties }: ComponentProps<'span'>): ReactElement { | ||
| return ( | ||
| <span | ||
| aria-hidden | ||
| data-slot="pagination-ellipsis" | ||
| className={cn('flex size-9 items-center justify-center', className)} | ||
| {...properties} | ||
| > | ||
| <MoreHorizontalIcon className="size-4" /> | ||
| <span className="sr-only">More pages</span> | ||
| </span> | ||
| ) | ||
| } | ||
|
|
||
| export { | ||
| Pagination, | ||
| PaginationContent, | ||
| PaginationLink, | ||
| PaginationItem, | ||
| PaginationPrevious, | ||
| PaginationNext, | ||
| PaginationEllipsis, | ||
| PaginationStart, | ||
| PaginationEnd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bitbybit marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Sparkles } from 'lucide-react' | ||
| import type { ReactElement } from 'react' | ||
|
|
||
| export function NoProductsFound(): ReactElement { | ||
| return ( | ||
| <div className="w-full h-full flex items-center justify-center"> | ||
| <div className="max-w-xs flex flex-col items-center justify-center gap-4 text-center"> | ||
| <Sparkles size={60} className="text-sky-200" /> | ||
| <p className="text-sm">We couldnβt find any products matching your search.</p> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import type { ReactElement } from 'react' | ||
| import { | ||
| Pagination, | ||
| PaginationContent, | ||
| PaginationEnd, | ||
| PaginationItem, | ||
| PaginationNext, | ||
| PaginationPrevious, | ||
| PaginationStart | ||
| } from '~/components/ui/Pagination' | ||
|
|
||
| export const ITEMS_PER_PAGE = 12 | ||
merucoding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| type PaginationControlsProperties = { | ||
| page: number | ||
| totalPage: number | ||
| onPageChange: (page: number) => void | ||
| } | ||
|
|
||
| export function PaginationControls({ page, totalPage, onPageChange }: PaginationControlsProperties): ReactElement { | ||
| const isFirstPage = page === 1 | ||
| const isLastPage = page === totalPage | ||
| const disabledState = 'pointer-events-none opacity-50' | ||
merucoding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <Pagination> | ||
| <PaginationContent> | ||
| <PaginationItem> | ||
| <PaginationStart | ||
| onClick={() => !isFirstPage && onPageChange(1)} | ||
| className={isFirstPage ? disabledState : ''} | ||
| /> | ||
| </PaginationItem> | ||
| <PaginationItem> | ||
| <PaginationPrevious | ||
| onClick={() => !isFirstPage && onPageChange(page - 1)} | ||
| className={isFirstPage ? disabledState : ''} | ||
| /> | ||
| </PaginationItem> | ||
| <PaginationItem className="px-2.5 sm:pl-2.5 border rounded-sm"> | ||
| {page} / {totalPage} | ||
| </PaginationItem> | ||
| <PaginationItem> | ||
| <PaginationNext | ||
| onClick={() => !isLastPage && onPageChange(page + 1)} | ||
| className={isLastPage ? disabledState : ''} | ||
| /> | ||
| </PaginationItem> | ||
| <PaginationItem> | ||
| <PaginationEnd | ||
| onClick={() => !isLastPage && onPageChange(totalPage)} | ||
| className={isLastPage ? disabledState : ''} | ||
| /> | ||
| </PaginationItem> | ||
| </PaginationContent> | ||
| </Pagination> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.