# VelvetKit

## Pagination (`UI::Pagination`)

Page links for a long list, from a Pagy object.

Add it: `bin/rails generate velvetkit:add pagination`

Also adds: `icon`, `link`

Installs: `pagy`

### Arguments

```ruby
UI::Pagination.new(pagy:, label: nil, class: nil, **html_attrs, &url_builder)
```

### Notes

UI::Pagination — page links for a long list.

Follows shadcn's structure (nav > ul > li > a, ghost links with the current
page outlined) and takes a Pagy::Offset, so controllers stay conventional.

The series is computed here rather than read from Pagy, whose own #series is
protected in v43 and whose gap marker differs by version.

Usage:
  <%= render(UI::Pagination.new(pagy: @pagy) { |page| section_path(@section, page: page) }) %>

### Example: States

```erb
<% examples = {
     "First page" => [240, 1],
     "Middle" => [240, 5],
     "Last page" => [240, 10],
     "Long range, collapsed" => [2500, 50],
     "Single page (renders nothing)" => [10, 1]
   } %>
<div class="flex flex-col gap-8">
  <% examples.each do |label, (count, page)| %>
    <div class="flex flex-col gap-2">
      <span class="text-xs text-muted-foreground"><%= label %></span>
      <%= render(UI::Pagination.new(pagy: Pagy::Offset.new(count: count, page: page, limit: 25))) %>
    </div>
  <% end %>
</div>
```
