Class: CCS::Components::GovUK::Pagination
- Defined in:
- lib/ccs/components/govuk/pagination.rb,
lib/ccs/components/govuk/pagination/item.rb,
lib/ccs/components/govuk/pagination/item/tag.rb,
lib/ccs/components/govuk/pagination/increment.rb,
lib/ccs/components/govuk/pagination/item/form.rb,
lib/ccs/components/govuk/pagination/item/ellipsis.rb,
lib/ccs/components/govuk/pagination/increment/next.rb,
lib/ccs/components/govuk/pagination/increment/previous.rb
Overview
GOV.UK Pagination
This helper is used for generating the pagination component from the GDS - Components - Pagination
Defined Under Namespace
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the pagination
{ class: 'govuk-pagination' }.freeze
Instance Method Summary collapse
-
#initialize(pagination_previous: nil, pagination_items: nil, pagination_next: nil, **options) ⇒ Pagination
constructor
A new instance of Pagination.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK pagination component.
Constructor Details
#initialize(pagination_previous: nil, pagination_items: nil, pagination_next: nil, **options) ⇒ Pagination
Returns a new instance of Pagination.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ccs/components/govuk/pagination.rb', line 43 def initialize(pagination_previous: nil, pagination_items: nil, pagination_next: nil, **) super(**) block_is_level = pagination_items.blank? && (pagination_previous.present? || pagination_next.present?) @options[:attributes][:class] << ' govuk-pagination--block' if block_is_level (@options[:attributes][:aria] ||= {})[:label] ||= 'Pagination' @pagination_previous = Increment::Previous.new(block_is_level: block_is_level, form: @options[:form], context: @context, **pagination_previous) if pagination_previous @pagination_next = Increment::Next.new(block_is_level: block_is_level, form: @options[:form], context: @context, **pagination_next) if pagination_next initialize_pagination_items(pagination_items, @options[:form]) end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK pagination component
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ccs/components/govuk/pagination.rb', line 62 def render tag.nav(**[:attributes]) do concat(pagination_previous.render) if pagination_previous if pagination_items concat(tag.ul(class: 'govuk-pagination__list') do pagination_items.each { |pagination_item| concat(pagination_item.render) } end) end concat(pagination_next.render) if pagination_next end end |