Class: Flowbite::Pagination

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/pagination.rb,
app/components/flowbite/pagination/gap.rb,
app/components/flowbite/pagination/link.rb,
app/components/flowbite/pagination/next_link.rb,
app/components/flowbite/pagination/previous_link.rb,
app/components/flowbite/pagination/chevron_left_icon.rb,
app/components/flowbite/pagination/chevron_right_icon.rb

Overview

Renders pagination controls for navigating between pages of results.

This component doesn't know about pages, page numbers, or any pagination library. The caller decides which pages to show (including where to place gaps) using the pages slot, and provides the URLs for the previous/next links directly.

Examples:

Usage

<%= render(Flowbite::Pagination.new(
  previous_url: (posts_path(page: @pagy.page - 1) if @pagy.page > 1),
  next_url: (posts_path(page: @pagy.page + 1) if @pagy.page < @pagy.pages)
)) do |pagination| %>
  <% ([email protected]).each do |page| %>
    <% pagination.with_page do %>
      <%= render(Flowbite::Pagination::Link.new(
        page: page,
        url: posts_path(page: page),
        current: page == @pagy.page
      )) %>
    <% end %>
  <% end %>
<% end %>

See Also:

Defined Under Namespace

Classes: ChevronLeftIcon, ChevronRightIcon, Gap, Link, NextLink, PreviousLink

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(next_url: nil, previous_url: nil, class: nil, **options) ⇒ Pagination

Returns a new instance of Pagination.

Parameters:

  • class (Array<String>) (defaults to: nil) —

    Additional CSS classes for the list element.

  • next_url (String) (defaults to: nil) —

    The URL for the next page. Omit to disable the next link, e.g. when already on the last page.

  • options (Hash) —

    Additional HTML options for the nav element.

  • previous_url (String) (defaults to: nil) —

    The URL for the previous page. Omit to disable the previous link, e.g. when already on the first page.



50
51
52
53
54
55
# File 'app/components/flowbite/pagination.rb', line 50

def initialize(next_url: nil, previous_url: nil, class: nil, **options)
  @next_url = next_url
  @previous_url = previous_url
  @class = Array.wrap(binding.local_variable_get(:class))
  @options = options
end

Instance Attribute Details

#next_url ⇒ Object (readonly)

Returns the value of attribute next_url.



42
43
44
# File 'app/components/flowbite/pagination.rb', line 42

def next_url
  @next_url
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



42
43
44
# File 'app/components/flowbite/pagination.rb', line 42

def options
  @options
end

#previous_url ⇒ Object (readonly)

Returns the value of attribute previous_url.



42
43
44
# File 'app/components/flowbite/pagination.rb', line 42

def previous_url
  @previous_url
end

Class Method Details

.classes ⇒ Object



37
38
39
# File 'app/components/flowbite/pagination.rb', line 37

def classes
  ["flex", "-space-x-px", "text-sm"]
end