Class: LightningUiKit::PaginationComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/lightning_ui_kit/pagination_component.rb

Instance Method Summary collapse

Methods inherited from BaseComponent

#merge_classes

Methods included from HeroiconHelper

#heroicon

Constructor Details

#initialize(current_page:, total_pages:, path:, page_param: "page", with_arrows: false, **options) ⇒ PaginationComponent

Returns a new instance of PaginationComponent.



4
5
6
7
8
9
10
11
# File 'app/components/lightning_ui_kit/pagination_component.rb', line 4

def initialize(current_page:, total_pages:, path:, page_param: "page", with_arrows: false, **options)
  @current_page = current_page
  @total_pages = total_pages
  @with_arrows = with_arrows
  @path = path
  @page_param = page_param
  @options = options
end

Instance Method Details

#data(disabled: false, active: false) ⇒ Object



13
14
15
16
17
18
# File 'app/components/lightning_ui_kit/pagination_component.rb', line 13

def data(disabled: false, active: false)
  {}.tap do |data|
    data[:disabled] = true if disabled
    data[:active] = true if active
  end
end


20
21
22
23
24
25
26
# File 'app/components/lightning_ui_kit/pagination_component.rb', line 20

def link_classes
  "lui:min-w-[2.25rem] lui:flex lui:items-center lui:justify-center lui:rounded-lg lui:border lui:text-base/6 lui:font-semibold lui:px-[calc(--spacing(3.5)-1px)] \
   lui:py-[calc(--spacing(2.5)-1px)] lui:sm:px-[calc(--spacing(3)-1px)] lui:sm:py-[calc(--spacing(1.5)-1px)] lui:sm:text-sm/6 \
   lui:focus:outline-hidden lui:focus:outline lui:focus:outline-2 lui:focus:outline-offset-2 lui:focus:outline-blue-500 \
   lui:data-[disabled]:opacity-50 lui:data-[disabled]:pointer-events-none lui:border-transparent lui:text-zinc-950 \
   lui:data-[active]:bg-zinc-950/5 lui:hover:bg-zinc-950/5"
end

#pages_with_gapsObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/components/lightning_ui_kit/pagination_component.rb', line 28

def pages_with_gaps
  return (1..@total_pages).to_a if @total_pages <= 7

  (1..@total_pages).to_a.each_with_object([]) do |page, pages|
    if page == 1 || page == @total_pages || page == @current_page || (page - @current_page).abs <= 2
      pages << page
    elsif pages.last != :gap
      pages << :gap
    end
  end
end

#url(page) ⇒ Object



40
41
42
# File 'app/components/lightning_ui_kit/pagination_component.rb', line 40

def url(page)
  "#{@path}?#{@page_param}=#{page}"
end