Sha256: e17f89337c2d7785f42f1febad6e4e69d354a74742311123e1af33d5ea1f72c3

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

require_relative '../../base'

module CCS
  module Components
    module GovUK
      class Pagination < Base
        # = GOV.UK Pagination Item
        #
        # This generates the HTML for the pagination item
        #
        # @!attribute [r] number
        #   @return [String] The number for the item
        # @!attribute [r] li_classes
        #   @return [String] HTML classes for pagination item +li+ element

        class Item < Base
          private

          attr_reader :number, :li_classes

          public

          # @param number [String] the number for the item
          # @param current [Boolean] flag to indicate if this item is the current page
          #
          # @option options [String] :classes additional CSS classes for the item HTML
          # @option options [Symbol] :type the type of item. If the value is +:ellipsis+ then an ellipsis will be rendered
          # @option options [Hash] :attributes any additional attributes that will added as part of the HTML

          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

          # Generates the HTML for the GOV.UK Pagination item
          #
          # @yield the HTML for the pagination item link/button
          #
          # @return [ActiveSupport::SafeBuffer]

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

          # The default attributes for the pagination link

          DEFAULT_ATTRIBUTES = { class: 'govuk-link govuk-pagination__link' }.freeze
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/pagination/item.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/pagination/item.rb