Class: Shadcn::PaginationComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Shadcn::PaginationComponent
- Defined in:
- app/components/shadcn/pagination_component.rb
Overview
Pagination component for navigating paged content Matches shadcn/ui Pagination component
Supports three usage patterns:
- Slot-based API (full control):
<%= render Shadcn::PaginationComponent.new do |pagination| %>
<% pagination.with_pagination_content do |content| %>
<% content.with_previous(href: "/page/1") %>
<% content.with_item(href: "/page/1") { "1" } %>
<% content.with_item(href: "/page/2", active: true) { "2" } %>
<% content.with_item(href: "/page/3") { "3" } %>
<% content.with_ellipse %>
<% content.with_next_page(href: "/page/3") %>
<% end %>
<% end %>
-
Collection-based API (Kaminari/will_paginate): <%= render Shadcn::PaginationComponent.new(collection: @posts) %>
-
Pagy-based API: <%= render Shadcn::PaginationComponent.new(pagy: @pagy) %>
Constant Summary collapse
- BASE_CLASSES =
"mx-auto flex w-full justify-center"
Instance Attribute Summary
Attributes inherited from BaseComponent
#class_name, #data, #html_options
Instance Method Summary collapse
- #before_render ⇒ Object
-
#initialize(collection: nil, pagy: nil, url_builder: nil, window: 2, **options) ⇒ PaginationComponent
constructor
A new instance of PaginationComponent.
Methods inherited from BaseComponent
Methods included from Rails::Helpers::ClassNameHelper
Constructor Details
#initialize(collection: nil, pagy: nil, url_builder: nil, window: 2, **options) ⇒ PaginationComponent
Returns a new instance of PaginationComponent.
38 39 40 41 42 43 44 |
# File 'app/components/shadcn/pagination_component.rb', line 38 def initialize(collection: nil, pagy: nil, url_builder: nil, window: 2, **) super(**) @collection = collection @pagy = pagy @url_builder = url_builder || ->(page) { "?page=#{page}" } @window = window end |
Instance Method Details
#before_render ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/components/shadcn/pagination_component.rb', line 46 def before_render # Pre-compute auto-generated content if needed if auto_generate? @should_render = total_pages > 1 else @should_render = true end end |