Class: BetterUi::Pagination::PaginationComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- BetterUi::Pagination::PaginationComponent
- Defined in:
- app/components/better_ui/pagination/pagination_component.rb
Constant Summary collapse
- STYLES =
%i[solid outline ghost soft].freeze
- SIZES =
{ xs: { item: "min-w-6 h-6 text-xs px-1.5", gap: "gap-0.5", icon: "w-3 h-3" }, sm: { item: "min-w-7 h-7 text-sm px-2", gap: "gap-1", icon: "w-3.5 h-3.5" }, md: { item: "min-w-9 h-9 text-sm px-3", gap: "gap-1.5", icon: "w-4 h-4" }, lg: { item: "min-w-11 h-11 text-base px-3.5", gap: "gap-2", icon: "w-5 h-5" }, xl: { item: "min-w-12 h-12 text-lg px-4", gap: "gap-2.5", icon: "w-5 h-5" } }.freeze
- ROUNDED =
{ none: "rounded-none", sm: "rounded-sm", md: "rounded-md", lg: "rounded-lg", full: "rounded-full" }.freeze
Constants inherited from ApplicationComponent
ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED
Instance Method Summary collapse
- #auto_info_text ⇒ Object
- #first_page? ⇒ Boolean
-
#initialize(current_page:, total_pages:, url:, variant: :primary, style: :outline, size: :md, rounded: :md, shadow: :none, window: 2, show_first_last: false, show_prev_next: true, show_page_numbers: true, show_info: false, per_page: nil, total_count: nil, prev_label: nil, next_label: nil, first_label: nil, last_label: nil, gap_label: "\u2026", container_classes: nil) ⇒ PaginationComponent
constructor
A new instance of PaginationComponent.
- #last_page? ⇒ Boolean
- #page_items ⇒ Object
- #page_url(page) ⇒ Object
- #render? ⇒ Boolean
Constructor Details
#initialize(current_page:, total_pages:, url:, variant: :primary, style: :outline, size: :md, rounded: :md, shadow: :none, window: 2, show_first_last: false, show_prev_next: true, show_page_numbers: true, show_info: false, per_page: nil, total_count: nil, prev_label: nil, next_label: nil, first_label: nil, last_label: nil, gap_label: "\u2026", container_classes: nil) ⇒ PaginationComponent
Returns a new instance of PaginationComponent.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 26 def initialize( current_page:, total_pages:, url:, variant: :primary, style: :outline, size: :md, rounded: :md, shadow: :none, window: 2, show_first_last: false, show_prev_next: true, show_page_numbers: true, show_info: false, per_page: nil, total_count: nil, prev_label: nil, next_label: nil, first_label: nil, last_label: nil, gap_label: "\u2026", container_classes: nil ) @current_page = current_page @total_pages = total_pages @url = url @variant = validate_variant(variant) @style = validate_style(style) @size = validate_size(size) @rounded = validate_rounded(rounded) @shadow = normalize_shadow(shadow) @window = window @show_first_last = show_first_last @show_prev_next = show_prev_next @show_page_numbers = show_page_numbers @show_info = show_info @per_page = per_page @total_count = total_count @prev_label = prev_label @next_label = next_label @first_label = first_label @last_label = last_label @gap_label = gap_label @container_classes = container_classes validate_pages! validate_url! end |
Instance Method Details
#auto_info_text ⇒ Object
98 99 100 101 102 103 104 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 98 def auto_info_text return nil unless @show_info && @per_page && @total_count from = ((@current_page - 1) * @per_page) + 1 to = [ @current_page * @per_page, @total_count ].min "Showing #{from}-#{to} of #{@total_count} results" end |
#first_page? ⇒ Boolean
90 91 92 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 90 def first_page? @current_page == 1 end |
#last_page? ⇒ Boolean
94 95 96 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 94 def last_page? @current_page == @total_pages end |
#page_items ⇒ Object
79 80 81 82 83 84 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 79 def page_items return [] if @total_pages <= 0 return [ 1 ] if @total_pages == 1 build_page_items end |
#page_url(page) ⇒ Object
86 87 88 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 86 def page_url(page) @url.call(page) end |
#render? ⇒ Boolean
75 76 77 |
# File 'app/components/better_ui/pagination/pagination_component.rb', line 75 def render? @total_pages > 1 end |