Pagination
Pagination with page navigation, next and previous links.
Usage
Example
This is the default appearance of a Pagination
Pagination do PaginationContent do PaginationItem(href: "#") do chevrons_left_icon plain "First" end PaginationItem(href: "#") do chevron_left_icon plain "Prev" end PaginationEllipsis PaginationItem(href: "#") { "4" } PaginationItem(href: "#", active: true) { "5" } PaginationItem(href: "#") { "6" } PaginationEllipsis PaginationItem(href: "#") do plain "Next" chevron_right_icon end PaginationItem(href: "#") do plain "Last" chevrons_right_icon end end end
Copied!
Copy failed!
Installation
Using RubyUI CLI
Run the install command
rails g ruby_ui:component Pagination
Copied!
Copy failed!
Manual installation
1
Add RubyUI::Pagination
to app/components/ruby_ui/pagination.rb
# frozen_string_literal: true module RubyUI class Pagination < Base def view_template(&) nav(**attrs, &) end private def default_attrs { aria: {label: "pagination"}, class: "mx-auto flex w-full justify-center", role: "navigation" } end end end
Copied!
Copy failed!
2
Add RubyUI::PaginationContent
to app/components/ruby_ui/pagination/pagination_content.rb
# frozen_string_literal: true module RubyUI class PaginationContent < Base def view_template(&) ul(**attrs, &) end private def default_attrs { class: "flex flex-row items-center gap-1" } end end end
Copied!
Copy failed!
3
Add RubyUI::PaginationEllipsis
to app/components/ruby_ui/pagination/pagination_ellipsis.rb
# frozen_string_literal: true module RubyUI class PaginationEllipsis < Base def view_template(&block) li do span(**attrs) do icon span(class: "sr-only") { "More pages" } end end end private def icon svg( xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewbox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: "2", stroke_linecap: "round", stroke_linejoin: "round", class: "h-4 w-4" ) do |s| s.circle(cx: "12", cy: "12", r: "1") s.circle(cx: "19", cy: "12", r: "1") s.circle(cx: "5", cy: "12", r: "1") end end def default_attrs { aria: {hidden: true}, class: "flex h-9 w-9 items-center justify-center" } end end end
Copied!
Copy failed!
4
Add RubyUI::PaginationItem
to app/components/ruby_ui/pagination/pagination_item.rb
# frozen_string_literal: true module RubyUI class PaginationItem < Base def initialize(href: "#", active: false, **attrs) @href = href @active = active super(**attrs) end def view_template(&block) li do a(href: @href, **attrs, &block) end end private def default_attrs { aria: {current: @active ? "page" : nil}, class: [ RubyUI::Button.new(variant: @active ? :outline : :ghost).attrs[:class] ] } end end end
Copied!
Copy failed!
5
Install required components
Component Pagination
relies on the following RubyUI components. Refer to their individual installation guides for setup instructions:
Components
Component | Built using | Source |
---|---|---|
Pagination | Phlex | |
PaginationContent | Phlex | |
PaginationEllipsis | Phlex | |
PaginationItem | Phlex |