Skip to content

add pagination element #86

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

Merged
merged 5 commits into from
May 2, 2025
Merged

add pagination element #86

merged 5 commits into from
May 2, 2025

Conversation

TomWoodward
Copy link
Member

I can't express enough how annoying pagination logic is

image

the LinkForPage situation is because i think in some cases we may want the pagination to be buttons instead of links, but i'm not dealing with that explicitly yet

@TomWoodward TomWoodward requested a review from jivey May 1, 2025 15:00
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Pagination component along with supporting exports, stories, and tests to improve pagination functionality.

  • Adds new Pagination component, LinkForPage styled component, and related styling logic.
  • Provides interactive stories and snapshot tests to verify various pagination states.
  • Reorganizes export statements in the main index file for improved module structure.

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.

File Description
src/index.ts Reorganized component exports including Pagination.
src/components/Pagination.tsx New Pagination feature with dynamic page range logic.
src/components/Pagination.stories.tsx Stories to demonstrate Pagination usage.
src/components/Pagination.spec.tsx Snapshot tests for verifying Pagination behavior.
Files not reviewed (2)
  • package.json: Language not supported
  • src/components/snapshots/Pagination.spec.tsx.snap: Language not supported
Comments suppressed due to low confidence (1)

src/components/Pagination.tsx:58

  • [nitpick] Consider extracting the magic numbers (e.g. '+1' for the current page and '+2' for ellipses) into clearly named constants or adding inline comments to improve code readability.
const minEntries = showFromEnd * 2 + showFromCurrent * 2 + 1 + 2

const currentValue = current ? "page" : undefined;

return (
<a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an aria label for the link? When testing with a screenreader you only hear the numbers, which maybe works because of context, but I'm wondering if something like "Page x" or "Go to page x" would be clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I will add

<a
className={className}
aria-current={currentValue}
href={href || '#'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we won't ever see this in practice, but with "#" the screenreader reads all of them as "visited link".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this would be invalid maybe I should just make href required

root = document.createElement('main');
root.id = 'root';
document.body.append(root);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno if it matters but this repo uses a lot of fragment snapshots

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk I just copied the other specs setup

@TomWoodward TomWoodward merged commit 06ca92c into main May 2, 2025
2 of 3 checks passed
@TomWoodward TomWoodward deleted the pagination-element branch May 2, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants