Sha256: ca85ff0952a61d33ff6723ca66f56f68277a0c7fe4576fe206f45bace14ceab8

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require_relative '../../base'
require_relative 'link'

module CCS::Components
  module CCS
    class Footer < Base
      # = CCS Footer Meta
      #
      # The footer meta section
      #
      # @!attribute [r] meta_links
      #   @return [Array<Link>] An array of the initialised meta links
      # @!attribute [r] visually_hidden_title
      #   @return [String] Title for the meta section
      # @!attribute [r] text
      #   @return [String] Text to add to the meta section of the footer

      class Meta
        include ActionView::Context
        include ActionView::Helpers

        private

        attr_reader :meta_links, :visually_hidden_title, :text

        public

        # @param items [Array<Hash>] an array of links for the meta section.
        #                            See {Components::CCS::Footer::Link#initialize Link#initialize} for details of the items in the array.
        # @param visually_hidden_title [String] ('Support links') title for the meta section
        # @param text [String] text to add to the meta section of the footer
        # @param context [ActionView::Base] the view context

        def initialize(context:, items: nil, visually_hidden_title: nil, text: nil)
          @meta_links = items&.map { |meta_link| Link.new(li_class: 'ccs-footer__inline-list-item', context: context, **meta_link) }
          @visually_hidden_title = visually_hidden_title || 'Support links'
          @text = text
        end

        # Generates the HTML for the CCS Footer Meta sections
        #
        # @return [ActiveSupport::SafeBuffer]

        def render
          capture do
            concat(tag.h2(visually_hidden_title, class: 'govuk-visually-hidden'))
            if meta_links
              concat(tag.ul(class: 'ccs-footer__inline-list') do
                meta_links.each { |meta_link| concat(meta_link.render) }
              end)
            end
            concat(tag.div(text, class: 'ccs-footer__meta-custom')) if text
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.1.0.rc.2 lib/ccs/components/ccs/footer/meta.rb