-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add pagination feature in blog page #5157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a26c350
afb7dba
c56fad9
2bc44a1
227a85b
07caf6b
44a40b7
a3462e8
e81ab78
f5d1075
1b8fe1a
0636531
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { useCallback, useMemo, useState } from 'react'; | ||
|
|
||
| /** | ||
| * @description Custom hook for managing pagination logic | ||
| * @example const { currentPage, setCurrentPage, currentItems, maxPage } = usePagination(items, 10, { currentPage: 2 }); | ||
| * @param {T[]} items - Array of items to paginate | ||
| * @param {number} itemsPerPage - Number of items per page | ||
| * @param {object} [options] - Pagination options | ||
| * @param {number} [options.currentPage] - Optional current page (controlled) | ||
| * @param {(page: number) => void} [options.onPageChange] - Called when setCurrentPage is invoked in controlled mode | ||
| * @returns {object} | ||
| * @returns {number} currentPage - Current page number | ||
| * @returns {function} setCurrentPage - Function to update the current page | ||
| * @returns {T[]} currentItems - Items for the current page | ||
| * @returns {number} maxPage - Total number of pages | ||
| */ | ||
| export function usePagination<T>( | ||
| items: T[], | ||
| itemsPerPage: number, | ||
| options: { currentPage?: number; onPageChange?: (page: number) => void } = {} | ||
| ) { | ||
| const [internalPage, setInternalPage] = useState(1); | ||
| const { currentPage: controlledPage, onPageChange } = options; | ||
| const isControlled = typeof controlledPage === 'number' && !Number.isNaN(controlledPage); | ||
| const page = isControlled ? (controlledPage as number) : internalPage; | ||
| const maxPage = Math.ceil(items.length / itemsPerPage); | ||
| const safePage = maxPage === 0 ? 1 : Math.min(Math.max(page, 1), maxPage); | ||
| const setCurrentPage = useCallback( | ||
| (nextPage: number) => { | ||
| if (isControlled) { | ||
| onPageChange?.(nextPage); | ||
|
|
||
| return; | ||
| } | ||
| setInternalPage(nextPage); | ||
| }, | ||
| [isControlled, onPageChange] | ||
| ); | ||
|
|
||
| const currentItems = useMemo(() => { | ||
| const start = (safePage - 1) * itemsPerPage; | ||
|
|
||
| return items.slice(start, start + itemsPerPage); | ||
| }, [items, safePage, itemsPerPage]); | ||
|
|
||
| return { | ||
| currentPage: safePage, | ||
| setCurrentPage, | ||
| currentItems, | ||
| maxPage | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React from 'react'; | ||
|
|
||
| /* eslint-disable max-len */ | ||
| /** | ||
| * @description Icons for Next button | ||
| */ | ||
| export default function IconNext() { | ||
| return ( | ||
| <svg | ||
| width='20' | ||
| height='20' | ||
| viewBox='0 0 24 24' | ||
| fill='none' | ||
| xmlns='http://www.w3.org/2000/svg' | ||
| className='stroke-current' | ||
| > | ||
| <path d='M9 6L15 12L9 18' strokeWidth='2' strokeLinecap='round' strokeLinejoin='round' /> | ||
| </svg> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React from 'react'; | ||
|
|
||
| /* eslint-disable max-len */ | ||
| /** | ||
| * @description Icons for Previous button in pagination | ||
| */ | ||
| export default function IconPrevious() { | ||
| return ( | ||
| <svg | ||
| width='20' | ||
| height='20' | ||
| viewBox='0 0 24 24' | ||
| fill='none' | ||
| xmlns='http://www.w3.org/2000/svg' | ||
| className='stroke-current' | ||
| > | ||
| <path d='M15 18L9 12L15 6' strokeWidth='2' strokeLinecap='round' strokeLinejoin='round' /> | ||
| </svg> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,118 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ButtonIconPosition } from '@/types/components/buttons/ButtonPropsType'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Button from '../buttons/Button'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import IconNext from '../icons/Next'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import IconPrevious from '../icons/Previous'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import PaginationItem from './PaginationItem'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface PaginationProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line prettier/prettier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Total number of pages */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| totalPages: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Current active page */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currentPage: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Function to handle page changes */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onPageChange: (page: number) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * This is the Pagination component. It displays a list of page numbers that can be clicked to navigate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function Pagination({ totalPages, currentPage, onPageChange }: PaginationProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handlePageChange = (page: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (page >= 1 && page <= totalPages) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onPageChange(page); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @returns number of pages shows in Pagination. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const getPageNumber = (): (number | 'start-ellipsis' | 'end-ellipsis')[] => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (totalPages <= 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Array.from({ length: Math.max(0, totalPages) }, (_, i) => i + 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pages: (number | 'start-ellipsis' | 'end-ellipsis')[] = [1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const left = Math.max(2, currentPage - 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const right = Math.min(totalPages - 1, currentPage + 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (left > 2) pages.push('start-ellipsis'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (let i = left; i <= right; i++) pages.push(i); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (right < totalPages - 1) pages.push('end-ellipsis'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pages.push(totalPages); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return pages; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <nav | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role='navigation' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-label='Pagination' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className='font-inter flex items-center justify-center gap-2 md:gap-8' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/* Previous button */} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => handlePageChange(currentPage - 1)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled={currentPage === 1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className={`font-normal flex h-[34px] items-center justify-center rounded bg-white px-3 py-[7px] text-sm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| leading-[17px] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tracking-[-0.01em] ${ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currentPage === 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? 'hover:bg-gray-white cursor-not-allowed text-gray-300' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : 'text-[#141717] hover:bg-gray-50' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find and display Tailwind configuration files
fd 'tailwind\.config\.(js|ts|cjs|mjs)' --type f -x cat {} \;
# Search for gray-white usage in the codebase
echo "=== Searching for gray-white usage ==="
rg 'gray-white' -nRepository: asyncapi/website Length of output: 6052 Replace The This applies to lines 69 and 109 in components/pagination/Pagination.tsx. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text='' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon={<IconPrevious />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconPosition={ButtonIconPosition.LEFT} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-label='Go to previous page' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/* Page numbers */} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className='flex gap-2' role='list'> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {getPageNumber().map((page) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof page === 'number' ? ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <PaginationItem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={page} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pageNumber={page} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isActive={page === currentPage} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onPageChange={handlePageChange} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-label={`Go to page ${page}`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <span | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={page} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className='font-inter flex size-8 items-center justify-center text-sm font-semibold text-[#6B6B6B] md:size-10' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-hidden='true' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
79
to
98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Either wrap each child in Option A — add listitem wrappers <div className='flex gap-2' role='list'>
{getPageNumber().map((page) =>
typeof page === 'number' ? (
- <PaginationItem
- key={page}
- ...
- />
+ <div role='listitem' key={page}>
+ <PaginationItem
+ pageNumber={page}
+ isActive={page === currentPage}
+ onPageChange={handlePageChange}
+ aria-label={`Go to page ${page}`}
+ />
+ </div>
) : (
- <span key={page} ...>
- ...
- </span>
+ <div role='listitem' key={page}>
+ <span
+ className='font-inter flex size-10 items-center justify-center text-sm font-semibold text-[`#6B6B6B`]'
+ aria-hidden='true'
+ >
+ ...
+ </span>
+ </div>
)
)}
</div>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {/* Next button */} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => handlePageChange(currentPage + 1)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disabled={currentPage === totalPages} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| className={` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| font-normal flex h-[34px] items-center justify-center rounded bg-white px-3 py-[7px] text-sm leading-[17px] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tracking-[-0.01em] ${ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currentPage === totalPages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? 'hover:bg-gray-white cursor-not-allowed text-gray-300' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : 'text-[#141717] hover:bg-gray-50' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| text='' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon={<IconNext />} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aria-label='Go to next page' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </nav> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||
| import React from 'react'; | ||||||||||
|
|
||||||||||
| export interface PaginationItemProps { | ||||||||||
| // eslint-disable-next-line prettier/prettier | ||||||||||
|
|
||||||||||
|
Comment on lines
+3
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Stray The directive on line 4 targets the next line, which is empty. Remove it. Proposed fix export interface PaginationItemProps {
- // eslint-disable-next-line prettier/prettier
-
/** The page number to display */📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| /** The page number to display */ | ||||||||||
| pageNumber: number; | ||||||||||
|
|
||||||||||
| /** Whether this page is currently active */ | ||||||||||
| isActive: boolean; | ||||||||||
|
|
||||||||||
| /** Function to handle page change */ | ||||||||||
| onPageChange: (page: number) => void; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * This is the PaginationItem component. It displays a single page number that can be clicked. | ||||||||||
| */ | ||||||||||
| export default function PaginationItem({ | ||||||||||
| pageNumber, | ||||||||||
| isActive, | ||||||||||
| onPageChange, | ||||||||||
| ...buttonProps | ||||||||||
| }: PaginationItemProps & React.ButtonHTMLAttributes<HTMLButtonElement>) { | ||||||||||
| return ( | ||||||||||
| <button | ||||||||||
| onClick={() => onPageChange(pageNumber)} | ||||||||||
| className={`font-inter font-normal relative flex size-8 items-center | ||||||||||
| justify-center rounded-full text-xs leading-[26px] md:size-10 md:text-sm | ||||||||||
| ${isActive ? 'bg-[#6200EE] text-white' : 'bg-transparent text-[#141717] hover:bg-gray-50'} | ||||||||||
| `} | ||||||||||
| aria-current={isActive ? 'page' : undefined} | ||||||||||
| {...buttonProps} | ||||||||||
| > | ||||||||||
| {pageNumber} | ||||||||||
| </button> | ||||||||||
| ); | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: asyncapi/website
Length of output: 125
🏁 Script executed:
Repository: asyncapi/website
Length of output: 859
🏁 Script executed:
Repository: asyncapi/website
Length of output: 87
🏁 Script executed:
Repository: asyncapi/website
Length of output: 87
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
Repository: asyncapi/website
Length of output: 2884
🏁 Script executed:
Repository: asyncapi/website
Length of output: 4375
🏁 Script executed:
Repository: asyncapi/website
Length of output: 8033
🏁 Script executed:
Repository: asyncapi/website
Length of output: 787
🏁 Script executed:
Repository: asyncapi/website
Length of output: 568
🏁 Script executed:
Repository: asyncapi/website
Length of output: 418
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
# Check if there are any recent changes or staging git status -- components/buttons/Button.tsxRepository: asyncapi/website
Length of output: 125
🏁 Script executed:
Repository: asyncapi/website
Length of output: 765
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
Repository: asyncapi/website
Length of output: 1131
🏁 Script executed:
Repository: asyncapi/website
Length of output: 110
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
Repository: asyncapi/website
Length of output: 4400
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
Repository: asyncapi/website
Length of output: 87
🏁 Script executed:
# Check if IconRocket, IconGoogleCalendar, etc. have built-in margins cat -n components/icons/Rocket.tsxRepository: asyncapi/website
Length of output: 2364
🏁 Script executed:
# Let's check if there's a master branch or other branches that might have the full history git branch -aRepository: asyncapi/website
Length of output: 163
🏁 Script executed:
Repository: asyncapi/website
Length of output: 209
🏁 Script executed:
Repository: asyncapi/website
Length of output: 827
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
Repository: asyncapi/website
Length of output: 42
🏁 Script executed:
Repository: asyncapi/website
Length of output: 785
🏁 Script executed:
Repository: asyncapi/website
Length of output: 894
🏁 Script executed:
Repository: asyncapi/website
Length of output: 3215
Removing icon margins breaks every other Button with both icon and text.
Confirmed: the
mr-2/ml-2classes were removed from the icon spans (lines 79, 85, 101, 103), eliminating spacing between icons and labels globally. This breaks multiple existing Buttons with both icon and text — includingGithubButton,YoutubeButton,SlackButton,SubscribeButton,GoogleCalendarButton,ICSFileButton, and others. The pagination buttons withtext=''remain unaffected since they have no visible text label.Apply the conditional margin approach:
Proposed fix — conditionally apply margin when text is present
{icon && iconPosition === ButtonIconPosition.LEFT && ( - <span className='inline-block' data-testid='Button-icon-left'> + <span className={`inline-block${text ? ' mr-2' : ''}`} data-testid='Button-icon-left'> {icon} </span> )} <span className='inline-block'>{text}</span> {icon && iconPosition === ButtonIconPosition.RIGHT && ( - <span className='inline-block' data-testid='Button-icon-right'> + <span className={`inline-block${text ? ' ml-2' : ''}`} data-testid='Button-icon-right'> {icon} </span> )}Apply the same pattern in the
<Link>branch (lines 101–103).📝 Committable suggestion
🤖 Prompt for AI Agents