Class: GovukComponent::PaginationComponent::Item

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/pagination_component/item.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(number: nil, href: nil, current: false, ellipsis: false, from_pagy: false, visually_hidden_text: nil, classes: [], html_attributes: {}) ⇒ Item

Returns a new instance of Item.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/govuk_component/pagination_component/item.rb', line 4

def initialize(number: nil, href: nil, current: false, ellipsis: false, from_pagy: false, visually_hidden_text: nil, classes: [], html_attributes: {})
  @number               = number
  @href                 = href
  @visually_hidden_text = visually_hidden_text

  # We have three modes for rendering links:
  #
  #  * link    (a link to another page)
  #  * current (a link to the current page)
  #  * gap     (an ellipsis symbol)
  #
  # Pagy sets these by object type:
  # Integer = link
  # String  = current
  # :gap    = gap
  #
  # The original Nunjucks component has two boolean settings instead,
  # ellipsis and current. When ellipsis is true all other arguments are
  # ignored
  @mode = from_pagy ? pagy_mode(number) : manual_mode(ellipsis, current)

  super(classes:, html_attributes:)
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



2
3
4
# File 'app/components/govuk_component/pagination_component/item.rb', line 2

def href
  @href
end

#modeObject (readonly)

Returns the value of attribute mode.



2
3
4
# File 'app/components/govuk_component/pagination_component/item.rb', line 2

def mode
  @mode
end

#numberObject (readonly)

Returns the value of attribute number.



2
3
4
# File 'app/components/govuk_component/pagination_component/item.rb', line 2

def number
  @number
end

#visually_hidden_textObject (readonly)

Returns the value of attribute visually_hidden_text.



2
3
4
# File 'app/components/govuk_component/pagination_component/item.rb', line 2

def visually_hidden_text
  @visually_hidden_text
end

Instance Method Details

#callObject



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

def call
  case mode
  when :link
    link(current: false)
  when :current
    link(current: true)
  when :gap
    ellipsis_item
  end
end