Skip to content

✨ feat(pagination)!: align with shadcn/ui composition and add simple mode#636

Open
mikij wants to merge 1 commit into
feat/#462-docs-improvementsfrom
feat/#538-pagination
Open

✨ feat(pagination)!: align with shadcn/ui composition and add simple mode#636
mikij wants to merge 1 commit into
feat/#462-docs-improvementsfrom
feat/#538-pagination

Conversation

@mikij
Copy link
Copy Markdown
Contributor

@mikij mikij commented May 26, 2026

What was done? 📝

Refactored the pagination component to align with shadcn/ui composition patterns:

  • Added zSimple input to show only page numbers (hides prev/next nav buttons)
  • Changed zSize default from 'default' to 'icon' for pagination item buttons
  • Added PaginationItemSizeType (icon sizes) and PaginationNavSizeType (text sizes) type aliases with navSize computed mapping
  • Removed redundant zPageIndexChange output — zPageIndex is a model() so two-way binding works natively
  • Switched <z-button> component to <button z-button> directive in pagination button
  • Updated CSS variants to match shadcn/ui styling (smaller gaps, padding, icon sizing)
  • Added new demos: iconsonly, simple, preview; replaced default and custom
  • Updated API documentation with new size types and zSimple input
  • Updated spec to test model binding instead of removed output

Screenshots or GIFs 📸

Figma / shadcn/ui Implementation
shadcn/ui pagination composition zard pagination with icon sizes, simple mode

Link to Issue 🔗

Closes #538

Type of change 🏗

  • Refactor (non-breaking change that improves the code or technical debt)
  • New feature (non-breaking change that adds functionality)

Breaking change 🚨

  • zSize default changed from 'default' to 'icon' — consumers not explicitly passing zSize will see icon-sized page buttons instead of text-sized
  • zPageIndexChange output removed — consumers should use [(zPageIndex)] two-way binding (standard model() pattern) instead of (zPageIndexChange)
  • ZardPaginationContentVariants, ZardPaginationPreviousVariants, ZardPaginationNextVariants, ZardPaginationEllipsisVariants, ZardPaginationVariants type exports removed from pagination.variants.ts

Checklist 🧐

  • Tested on Chrome
  • Tested on Safari
  • Tested on Firefox
  • No errors in the console

Summary by CodeRabbit

Release Notes

  • New Features

    • Added simple pagination mode for streamlined display
    • Added icons-only pagination variant with rows-per-page selection
  • Changes

    • Updated pagination size configuration options to icon-style variants
    • Removed zPageIndexChange event; use [(zPageIndex)] two-way binding instead
    • Added zSimple property to toggle navigation controls
  • Documentation

    • Updated API documentation with new properties and available size options

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 244f3fd8-bf29-44ea-8518-f68aeb268ec7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#538-pagination

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.

@mikij mikij requested a review from Luizgomess May 26, 2026 11:49
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: 5

🤖 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.

Inline comments:
In `@libs/zard/src/lib/shared/components/pagination/pagination.component.spec.ts`:
- Line 11: Replace the TestBed-based spec setup and DOM queries with Testing
Library APIs: import and call render(TestHostComponent) from
`@testing-library/angular` to mount the host that contains the <z-pagination>
(z-pagination binding to pageIndex/totalPages/customClass) and replace any
fixture.debugElement or fixture.nativeElement queries with screen queries
(screen.getByRole / screen.getByText / screen.getByTestId as appropriate) and
user-event interactions; ensure assertions reference the rendered output via
screen and that any TestHostComponent properties (pageIndex, totalPages,
customClass) are passed/updated through the render call or by rerendering,
applying the same migration to the other occurrences noted (lines with the same
z-pagination usage).
- Line 63: Replace brittle textContent-based button lookups (e.g., the
Array.from(getButtons()).find(...) that assigns page3Button) with role-and-name
queries and assert behavior: use testing-library queries like
getByRole('button', { name: /to page 3/i }) (or findByRole for async) to select
controls, then assert interaction outcomes (toBeDisabled, click and expect
model/page changes) instead of inspecting DOM structure; update the analogous
assertions at the other mentioned locations (lines referencing
getButtons()/textContent) to follow the same role/name-driven selection and
behavior-based assertions in the pagination.component.spec.ts tests.

In `@libs/zard/src/lib/shared/components/pagination/pagination.component.ts`:
- Around line 198-202: The pagination UI computes navigation state from
zPageIndex() without clamping against zTotal(), which can yield invalid pages;
before deriving any nav values (e.g., where pagePrevious, pageNext,
pageStart/pageEnd etc. are calculated in pagination.component.ts) compute a
clampedCurrent = clamp(zPageIndex(), 1, Math.max(1, zTotal())) and use
clampedCurrent for all UI bindings and disabled checks, and modify
goToPage(page) to validate/reject out-of-range writes by clamping or returning
early if page < 1 or page > Math.max(1, zTotal()); apply this pattern to the
other nav calculations referenced (lines ~213-218, 228-232, 253-281) so
emitted/linked pages are always within [1, max(1, zTotal())].
- Around line 69-82: The component currently renders an inner <button> causing
nested interactive controls; update ZardPaginationButtonComponent so the host
element (selector: 'button[z-pagination-button], a[z-pagination-button]')
receives the styling, state and attributes instead of rendering an inner button:
remove the inner <button z-button ...> from the template and make the template a
simple <ng-content />; move the bindings for data-active, class, zDisabled,
zSize and zType to host bindings (use `@HostBinding` or the component's host
metadata) and forward any ZardButton behavior/state (ZardButtonComponent inputs
like zDisabled(), zSize(), zType() and class()) onto the host so consumers don’t
get nested interactive elements and the host element reflects
active/disabled/size/type styles and attributes.

In `@libs/zard/src/lib/shared/components/pagination/pagination.variants.ts`:
- Around line 1-13: Import VariantProps from 'class-variance-authority' and
re-export type aliases for each CVA constant so the typed public contract is
restored; create and export types using the pattern VariantProps<typeof
paginationContentVariants>, VariantProps<typeof paginationPreviousVariants>,
VariantProps<typeof paginationNextVariants>, VariantProps<typeof
paginationEllipsisVariants>, and VariantProps<typeof paginationVariants>
referencing the corresponding identifiers (paginationContentVariants,
paginationPreviousVariants, paginationNextVariants, paginationEllipsisVariants,
paginationVariants).
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 45715987-1224-4daf-b5d5-762d3e234c80

📥 Commits

Reviewing files that changed from the base of the PR and between c626d87 and f2bae72.

⛔ Files ignored due to path filters (7)
  • apps/web/public/r/pagination.json is excluded by !apps/web/public/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/custom.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/default.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/iconsonly.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/preview.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/simple.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/installation/manual/pagination.ts is excluded by !**/generated/** and included by apps/**
📒 Files selected for processing (9)
  • libs/zard/src/lib/shared/components/pagination/demo/default.ts
  • libs/zard/src/lib/shared/components/pagination/demo/iconsonly.ts
  • libs/zard/src/lib/shared/components/pagination/demo/pagination.ts
  • libs/zard/src/lib/shared/components/pagination/demo/preview.ts
  • libs/zard/src/lib/shared/components/pagination/demo/simple.ts
  • libs/zard/src/lib/shared/components/pagination/doc/api.ts
  • libs/zard/src/lib/shared/components/pagination/pagination.component.spec.ts
  • libs/zard/src/lib/shared/components/pagination/pagination.component.ts
  • libs/zard/src/lib/shared/components/pagination/pagination.variants.ts
💤 Files with no reviewable changes (1)
  • libs/zard/src/lib/shared/components/pagination/demo/default.ts

Comment thread libs/zard/src/lib/shared/components/pagination/pagination.component.spec.ts Outdated
Comment thread libs/zard/src/lib/shared/components/pagination/pagination.component.ts Outdated
Comment thread libs/zard/src/lib/shared/components/pagination/pagination.component.ts Outdated
@mikij mikij force-pushed the feat/#538-pagination branch from f2bae72 to 1a96c58 Compare May 26, 2026 12:25
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

🤖 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.

Inline comments:
In `@libs/zard/src/lib/shared/components/pagination/pagination.component.spec.ts`:
- Around line 21-24: The helper getNavButton currently searches all buttons and
filters by hasAttribute('z-pagination-button') to handle nested buttons; once
ZardPaginationButtonComponent is flattened with host bindings, simplify
getNavButton to directly use screen.getByRole('button', { name }) and remove the
buttons.find(...) fallback logic; update the function getNavButton to return the
single element from screen.getByRole and remove reliance on the
'z-pagination-button' attribute check.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: e539f95a-5046-4f82-8045-88a816aef36e

📥 Commits

Reviewing files that changed from the base of the PR and between f2bae72 and 1a96c58.

⛔ Files ignored due to path filters (7)
  • apps/web/public/r/pagination.json is excluded by !apps/web/public/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/custom.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/default.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/iconsonly.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/preview.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/components/pagination/demo/simple.ts is excluded by !**/generated/** and included by apps/**
  • apps/web/src/generated/installation/manual/pagination.ts is excluded by !**/generated/** and included by apps/**
📒 Files selected for processing (9)
  • libs/zard/src/lib/shared/components/pagination/demo/default.ts
  • libs/zard/src/lib/shared/components/pagination/demo/iconsonly.ts
  • libs/zard/src/lib/shared/components/pagination/demo/pagination.ts
  • libs/zard/src/lib/shared/components/pagination/demo/preview.ts
  • libs/zard/src/lib/shared/components/pagination/demo/simple.ts
  • libs/zard/src/lib/shared/components/pagination/doc/api.ts
  • libs/zard/src/lib/shared/components/pagination/pagination.component.spec.ts
  • libs/zard/src/lib/shared/components/pagination/pagination.component.ts
  • libs/zard/src/lib/shared/components/pagination/pagination.variants.ts
💤 Files with no reviewable changes (1)
  • libs/zard/src/lib/shared/components/pagination/demo/default.ts

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.

1 participant