Skip to content

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

Merged
airikej merged 6 commits into
rcfrom
feat/20-pagination-new-tedi-ready-component
May 8, 2026
Merged

feat(pagination): new TEDI-Ready component #20#612
airikej merged 6 commits into
rcfrom
feat/20-pagination-new-tedi-ready-component

Conversation

@airikej
Copy link
Copy Markdown
Contributor

@airikej airikej commented Apr 27, 2026

Summary by CodeRabbit

  • New Features

    • Added a Pagination component with prev/next, page buttons, ellipses for large page counts, results count, and an optional page-size selector; supports controlled/uncontrolled modes and customizable labels.
  • Documentation

    • Added a React Router integration guide showing URL-driven pagination.
  • Tests

    • Added comprehensive tests for hook and component behaviors.
  • Storybook

    • Added stories demonstrating variants, controlled usage, and custom labels.
  • Style

    • Added component styles and size variant.

@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 27 minutes and 10 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ 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: 5047d2db-3737-41c2-be99-73a327518f90

📥 Commits

Reviewing files that changed from the base of the PR and between cbd3fa5 and 50c89b2.

📒 Files selected for processing (9)
  • src/community/components/table/components/pagination/pagination.tsx
  • 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/use-pagination.ts
  • src/tedi/providers/label-provider/label-provider.stories.tsx
  • src/tedi/providers/label-provider/labels-map.ts
📝 Walkthrough

Walkthrough

Adds a new Pagination feature: types, a usePagination hook, a Pagination React component with styles, tests, Storybook stories, router usage docs, and barrel exports to the package entry point.

Changes

Pagination feature

Layer / File(s) Summary
Data Shape
src/tedi/components/navigation/pagination/pagination.types.ts
Public types: PaginationItemType, PaginationItem, PaginationLabels, and PaginationProps define item model, labels, and component props.
Core Hook
src/tedi/components/navigation/pagination/use-pagination.ts
usePagination computes ordered pagination items (previous, page numbers, ellipses, next), clamps page, enforces non-negative counts, and marks selected/disabled states.
Component Implementation
src/tedi/components/navigation/pagination/pagination.tsx
Pagination component renders results text, conditional <nav> with prev/next, ellipses, page buttons, controlled/uncontrolled page behavior, page-size Select, and label merging via useLabels. Exports default and named Pagination.
Styling
src/tedi/components/navigation/pagination/pagination.module.scss
Adds grid layout, slot wrappers, nav/list/button styles, ellipsis variant, selected/disabled states, medium-size modifier, and page-size layout.
Tests
src/tedi/components/navigation/pagination/pagination.spec.tsx
Unit tests for usePagination (edge cases, ellipses, clamping, slot counts) and Pagination component (ARIA, controlled/uncontrolled behavior, prev/next, results label, page-size selection, no-op clicks).
Stories / Examples
src/tedi/components/navigation/pagination/pagination.stories.tsx
Storybook meta and multiple stories demonstrating default/first/last, controlled examples, many-pages ellipsis, sibling/boundary variations, page-size and results combinations, and custom labels.
Docs / Usage
src/tedi/components/navigation/pagination/usage-with-router.mdx
MDX example demonstrating syncing page/pageSize with React Router search params and sanitizing URL state.
Barrel Exports
src/tedi/components/navigation/pagination/index.ts, src/tedi/index.ts
Adds package-level re-exports for the pagination barrel so consumers can import via tedi root.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

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 'feat(pagination): new TEDI-Ready component #20' clearly and concisely describes the primary change: introducing a new Pagination component to the TEDI design system.
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
Comment thread src/tedi/components/navigation/pagination/pagination.module.scss
Comment thread src/tedi/components/navigation/pagination/pagination.types.ts Outdated
Comment thread src/tedi/components/navigation/pagination/index.ts
Comment thread src/tedi/components/navigation/pagination/pagination.stories.tsx Outdated
Comment thread src/tedi/components/navigation/pagination/pagination.stories.tsx
Comment thread src/tedi/components/navigation/pagination/pagination.module.scss
@airikej airikej temporarily deployed to github-pages May 7, 2026 11:49 — with GitHub Actions Inactive
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.

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

13-13: ⚡ Quick win

Add forwardRef to expose the pagination root element to consumers.

The component renders a root <div> that callers will reasonably want to ref (e.g., programmatic focus or scroll-into-view). Per the project guidelines for src/tedi/components/**/*.tsx, components that need ref forwarding must use forwardRef.

♻️ Proposed refactor
-import { useCallback, useId, useMemo, useState } from 'react';
+import { forwardRef, useCallback, useId, useMemo, useState } from 'react';

-export const Pagination = (props: PaginationProps): JSX.Element => {
+export const Pagination = forwardRef<HTMLDivElement, PaginationProps>((props, ref) => {
   // ...
   return (
-    <div className={rootClassName} data-name="tedi-pagination">
+    <div ref={ref} className={rootClassName} data-name="tedi-pagination">
   // ...
-};
+});

As per coding guidelines: "Components that need ref forwarding must use forwardRef" for src/tedi/components/**/*.tsx.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tedi/components/navigation/pagination/pagination.tsx` at line 13, The
Pagination component must be converted to a forwardRef so callers can obtain a
ref to the root div: change the declaration of Pagination to use
React.forwardRef and accept (props: PaginationProps, ref:
React.Ref<HTMLDivElement>) then pass that ref to the root <div> rendered by
Pagination; update the exported symbol (Pagination) to the forwarded component
and adjust any type annotations to use
React.ForwardRefExoticComponent/React.RefAttributes as needed so consumers can
call ref on the component.

38-38: ⚡ Quick win

Consider making the results label locale-agnostic.

The default results formatter hardcodes the count before the translated text (${count} ${getLabel(...)}). Some locales place the number after the noun (e.g., "výsledkov: 5"), so this order may produce garbled output for non-default locales. The labels prop does allow full override, which limits the blast radius, but the built-in default will silently break for those locales.

A common pattern is to embed a placeholder token inside the translated string and interpolate at call time, rather than doing string concatenation at this layer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tedi/components/navigation/pagination/pagination.tsx` at line 38, The
default results label currently builds the string by prefixing the count
(results: (count) => `${count} ${getLabel('pagination.results', count)}`), which
breaks locales where the number comes after the noun; change the default to ask
the localization layer to include a placeholder and interpolate there
instead—i.e., call getLabel('pagination.results') with a placeholder-aware API
or fetch the template and replace a {count} token at render time (and update
locale keys like 'pagination.results' to include a {count} placeholder). Ensure
the code paths around the results label (the results function, the labels prop
default, and any usage sites) use this placeholder interpolation so overriding
via labels still works.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/tedi/components/navigation/pagination/pagination.tsx`:
- Line 13: The Pagination component must be converted to a forwardRef so callers
can obtain a ref to the root div: change the declaration of Pagination to use
React.forwardRef and accept (props: PaginationProps, ref:
React.Ref<HTMLDivElement>) then pass that ref to the root <div> rendered by
Pagination; update the exported symbol (Pagination) to the forwarded component
and adjust any type annotations to use
React.ForwardRefExoticComponent/React.RefAttributes as needed so consumers can
call ref on the component.
- Line 38: The default results label currently builds the string by prefixing
the count (results: (count) => `${count} ${getLabel('pagination.results',
count)}`), which breaks locales where the number comes after the noun; change
the default to ask the localization layer to include a placeholder and
interpolate there instead—i.e., call getLabel('pagination.results') with a
placeholder-aware API or fetch the template and replace a {count} token at
render time (and update locale keys like 'pagination.results' to include a
{count} placeholder). Ensure the code paths around the results label (the
results function, the labels prop default, and any usage sites) use this
placeholder interpolation so overriding via labels still works.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 00d4cc8d-090f-4fdd-a377-0249f6c9c93f

📥 Commits

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

📒 Files selected for processing (6)
  • 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/index.ts
✅ Files skipped from review due to trivial changes (1)
  • src/tedi/index.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/tedi/components/navigation/pagination/pagination.stories.tsx
  • src/tedi/components/navigation/pagination/pagination.types.ts
  • src/tedi/components/navigation/pagination/pagination.module.scss
  • src/tedi/components/navigation/pagination/pagination.spec.tsx

@airikej airikej temporarily deployed to github-pages May 7, 2026 12:13 — with GitHub Actions Inactive
@airikej airikej temporarily deployed to github-pages May 7, 2026 12:22 — with GitHub Actions Inactive
@airikej airikej requested a review from ly-tempel-bitweb May 7, 2026 12:26
@airikej airikej merged commit c564788 into rc May 8, 2026
20 checks passed
@airikej airikej deleted the feat/20-pagination-new-tedi-ready-component branch May 8, 2026 04:37
github-actions Bot pushed a commit that referenced this pull request May 8, 2026
# [17.1.0-rc.4](react-17.1.0-rc.3...react-17.1.0-rc.4) (2026-05-08)

### Features

* **pagination:** new TEDI-Ready component [#20](#20) ([#612](#612)) ([c564788](c564788))
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

2 participants