Skip to content

feat(pagination): new TEDI-Ready component #20#612

Open
airikej wants to merge 3 commits intorcfrom
feat/20-pagination-new-tedi-ready-component
Open

feat(pagination): new TEDI-Ready component #20#612
airikej wants to merge 3 commits intorcfrom
feat/20-pagination-new-tedi-ready-component

Conversation

@airikej
Copy link
Copy Markdown
Contributor

@airikej airikej commented Apr 27, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Pagination component with page navigation, results count display, and page size selector
    • Supports controlled and uncontrolled modes with customizable labels and button sizing
    • Includes ellipsis rendering for large page counts and full accessibility support
    • Compatible with React Router for URL-based pagination state management
  • Documentation

    • Added React Router integration guide with example usage

@airikej airikej linked an issue Apr 27, 2026 that may be closed by this pull request
21 tasks
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

@airikej has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 53 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8345f4c7-bf91-4fcf-bc52-cc5e9ff4801f

📥 Commits

Reviewing files that changed from the base of the PR and between 9c19a0b and 9aee720.

📒 Files selected for processing (5)
  • src/tedi/components/navigation/pagination/pagination.module.scss
  • src/tedi/components/navigation/pagination/pagination.spec.tsx
  • src/tedi/components/navigation/pagination/pagination.stories.tsx
  • src/tedi/components/navigation/pagination/pagination.tsx
  • src/tedi/components/navigation/pagination/pagination.types.ts
📝 Walkthrough

Walkthrough

This pull request introduces a complete Pagination component feature including a custom hook for computing pagination navigation items, TypeScript type definitions, comprehensive test coverage, Storybook documentation, and documentation for integration with React Router. The component is exported through the package barrel.

Changes

Cohort / File(s) Summary
Component Implementation
src/tedi/components/navigation/pagination/pagination.tsx, src/tedi/components/navigation/pagination/use-pagination.ts, src/tedi/components/navigation/pagination/pagination.types.ts
Introduces a new Pagination component supporting controlled/uncontrolled paging with prev/next navigation and optional page-size selection. The usePagination hook computes navigation items including page numbers, ellipsis placeholders, and boundary navigation based on configurable sibling and boundary counts.
Styling
src/tedi/components/navigation/pagination/pagination.module.scss
Defines grid-based layout for pagination container with slots for results and navigation, plus styling for pagination buttons, ellipsis items, interactive states (hover, active, focus-visible, disabled), and a medium-size modifier variant.
Testing & Stories
src/tedi/components/navigation/pagination/pagination.spec.tsx, src/tedi/components/navigation/pagination/pagination.stories.tsx
Comprehensive test suite validating hook edge cases (zero pages, ellipsis logic, clamping), component rendering (aria attributes, disabled states, controlled/uncontrolled modes), page-size selection, and localization. Storybook stories demonstrate various pagination states, ellipsis behavior, size variants, and controlled configurations.
Documentation & Exports
src/tedi/components/navigation/pagination/usage-with-router.mdx, src/tedi/components/navigation/pagination/index.ts, src/tedi/index.ts
Adds MDX documentation showing integration with React Router using URL search parameters, barrel module exports for simplified imports, and extends package-level exports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • mart-sessman
  • ly-tempel-bitweb
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main addition: a new Pagination component that is TEDI-Ready, matching the comprehensive changeset introducing the component, hook, types, tests, stories, and documentation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/20-pagination-new-tedi-ready-component

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/tedi/components/navigation/pagination/pagination.tsx (1)

105-158: Optional: drop the as number cast via discriminated narrowing.

PaginationItem is a discriminated union, so once item.type === 'page' is checked, TS can narrow page to number without a cast. Replacing the trailing else with an explicit if (item.type === 'page') (and an exhaustive default) preserves full type safety and removes the assertion on line 137.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tedi/components/navigation/pagination/pagination.tsx` around lines 105 -
158, The map callback currently falls through to a non-discriminated branch and
uses a cast "item.page as number"; change the final else into an explicit if
(item.type === 'page') branch so TypeScript narrows PaginationItem and you can
use const pageNumber = item.page without the cast, then add an exhaustive
default (e.g., throw new Error or return null) to satisfy exhaustiveness; update
the branch that uses pageNumber, mergedLabels, and handlePageChange accordingly
so no "as number" assertion remains.
src/tedi/components/navigation/pagination/pagination.spec.tsx (1)

244-253: Prefer semantic queries over data-name selectors.

Both assertions look up the root via container.querySelector('[data-name="tedi-pagination"]'). Querying the <nav> by getByRole('navigation', { name: /Pagination/i }) (or by the surrounding region) keeps the test aligned with the project's "semantic queries" guideline. Class-name string matching is also brittle to CSS Modules hashing — consider asserting on rendered styles or the size class via a stable hook (e.g., a serializable size attribute) if you need to verify size wiring.

As per coding guidelines: "Use semantic queries in tests (getByRole, getByLabelText) instead of non-semantic queries (getByTestId)."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tedi/components/navigation/pagination/pagination.spec.tsx` around lines
244 - 253, Replace non-semantic
container.querySelector('[data-name="tedi-pagination"]') lookups in
pagination.spec.tsx with semantic queries from the render result, e.g., use
getByRole('navigation', { name: /Pagination/i }) (or screen.getByRole) to locate
the Pagination root; for the size assertion avoid brittle class string matching
— either assert a stable serialized hook the component exposes (e.g., a
data-size or aria attribute like data-size="medium" or aria-valuetext), or
assert on a deterministic style/behavior (rendered CSS property or presence of a
specific child element) instead of relying on CSS- module-hashed class names;
update the two tests referencing Pagination to use getByRole and to check a
stable size indicator (or rendered style) rather than matching className.
src/tedi/components/navigation/pagination/pagination.types.ts (1)

79-79: Consider ReadonlyArray<number> for pageSizeOptions

Using a readonly array here improves API ergonomics (accepts as const arrays) and discourages accidental mutation of caller-provided options.

♻️ Suggested refactor
-  pageSizeOptions?: number[];
+  pageSizeOptions?: ReadonlyArray<number>;

As per coding guidelines, component APIs should use robust typings and avoid weakly constrained patterns where stronger typing is straightforward.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tedi/components/navigation/pagination/pagination.types.ts` at line 79,
Update the pagination API to use an immutable type for the pageSizeOptions
property: replace the mutable array type currently declared as pageSizeOptions?:
number[] in pagination.types (the pageSizeOptions property in the Pagination
props/type) with pageSizeOptions?: ReadonlyArray<number> so callers can pass `as
const` arrays and accidental mutation of caller-provided arrays is discouraged;
ensure any internal usage treats the value as readonly (or copies it when
mutation is needed).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tedi/components/navigation/pagination/pagination.module.scss`:
- Around line 64-126: The buttons collapse because .tedi-pagination__button uses
--pagination-button-size which is never defined for different sizes; update the
size modifiers (e.g., .tedi-pagination--medium and add .tedi-pagination--small)
to set --pagination-button-size to the appropriate token instead of hardcoding
min-width/height in .tedi-pagination--medium, so .tedi-pagination__button
consumes that custom property for all sizes (refer to .tedi-pagination__button,
.tedi-pagination--medium and add .tedi-pagination--small).

---

Nitpick comments:
In `@src/tedi/components/navigation/pagination/pagination.spec.tsx`:
- Around line 244-253: Replace non-semantic
container.querySelector('[data-name="tedi-pagination"]') lookups in
pagination.spec.tsx with semantic queries from the render result, e.g., use
getByRole('navigation', { name: /Pagination/i }) (or screen.getByRole) to locate
the Pagination root; for the size assertion avoid brittle class string matching
— either assert a stable serialized hook the component exposes (e.g., a
data-size or aria attribute like data-size="medium" or aria-valuetext), or
assert on a deterministic style/behavior (rendered CSS property or presence of a
specific child element) instead of relying on CSS- module-hashed class names;
update the two tests referencing Pagination to use getByRole and to check a
stable size indicator (or rendered style) rather than matching className.

In `@src/tedi/components/navigation/pagination/pagination.tsx`:
- Around line 105-158: The map callback currently falls through to a
non-discriminated branch and uses a cast "item.page as number"; change the final
else into an explicit if (item.type === 'page') branch so TypeScript narrows
PaginationItem and you can use const pageNumber = item.page without the cast,
then add an exhaustive default (e.g., throw new Error or return null) to satisfy
exhaustiveness; update the branch that uses pageNumber, mergedLabels, and
handlePageChange accordingly so no "as number" assertion remains.

In `@src/tedi/components/navigation/pagination/pagination.types.ts`:
- Line 79: Update the pagination API to use an immutable type for the
pageSizeOptions property: replace the mutable array type currently declared as
pageSizeOptions?: number[] in pagination.types (the pageSizeOptions property in
the Pagination props/type) with pageSizeOptions?: ReadonlyArray<number> so
callers can pass `as const` arrays and accidental mutation of caller-provided
arrays is discouraged; ensure any internal usage treats the value as readonly
(or copies it when mutation is needed).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c63e9b84-5854-4261-b718-76dbf3be1541

📥 Commits

Reviewing files that changed from the base of the PR and between 1329251 and 9c19a0b.

📒 Files selected for processing (9)
  • src/tedi/components/navigation/pagination/index.ts
  • src/tedi/components/navigation/pagination/pagination.module.scss
  • src/tedi/components/navigation/pagination/pagination.spec.tsx
  • src/tedi/components/navigation/pagination/pagination.stories.tsx
  • src/tedi/components/navigation/pagination/pagination.tsx
  • src/tedi/components/navigation/pagination/pagination.types.ts
  • src/tedi/components/navigation/pagination/usage-with-router.mdx
  • src/tedi/components/navigation/pagination/use-pagination.ts
  • src/tedi/index.ts

Comment thread src/tedi/components/navigation/pagination/pagination.module.scss Outdated
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.

[Pagination]: New TEDI-Ready component

1 participant