Class: CCS::Components::GovUK::Pagination::Item

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/pagination/item.rb,
lib/ccs/components/govuk/pagination/item/tag.rb,
lib/ccs/components/govuk/pagination/item/form.rb,
lib/ccs/components/govuk/pagination/item/ellipsis.rb

Overview

GOV.UK Pagination Item

This generates the HTML for the pagination item

Direct Known Subclasses

Form, Tag

Defined Under Namespace

Classes: Ellipsis, Form, Tag

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the pagination link

{ class: 'govuk-link govuk-pagination__link' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(number:, current: false, **options) ⇒ Item

Returns a new instance of Item.

Parameters:

  • number (String)

    the number for the item

  • current (Boolean) (defaults to: false)

    flag to indicate if this item is the current page

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the item HTML

  • :ellipsis (Boolean)

    If the value is true then an ellipsis will be rendered

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ccs/components/govuk/pagination/item.rb', line 30

def initialize(number:, current: false, **options)
  super(**options)

  @number = number

  (@options[:attributes][:aria] ||= {})[:label] ||= "Page #{@number}"

  li_classes = 'govuk-pagination__item'

  if current
    li_classes << ' govuk-pagination__item--current'
    @options[:attributes][:aria][:current] = 'page'
  end

  @li_classes = li_classes
end

Instance Method Details

#render { ... } ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Pagination item

Yields:

  • the HTML for the pagination item link/button

Returns:

  • (ActiveSupport::SafeBuffer)


53
54
55
# File 'lib/ccs/components/govuk/pagination/item.rb', line 53

def render(&)
  tag.li(class: li_classes, &)
end