Sha256: c2506b9c44448e451880aa39cc44b78ed9bc32b204bae50e084c158b505f3927

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

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

module CCS
  module Components
    module GovUK
      class SummaryList < Base
        class Card < Base
          # = GOV.UK Summary list card actions
          #
          # @!attribute [r] action_links
          #   @return [Array<Action::Link>] An array of the initialised aummary list card action links

          class Actions < Base
            private

            attr_reader :action_links

            public

            # @param items [Array<Hash>] An array of attributes for the action links.
            #                            See {Components::GovUK::SummaryList::Action::Link#initialize Action::Link#initialize} for details of the items in the array.
            # @param options [Hash] options that will be used in customising the HTML
            #
            # @option options [String] :classes additional CSS classes for the summary list card actions HTML

            def initialize(items:, **options)
              super(**options)

              @action_links = items.map { |item| Action::Link.new(context: @context, **item) }
            end

            # Generates the HTML for the GOV.UK Summary list card actions
            #
            # @return [ActiveSupport::SafeBuffer]

            def render
              if action_links.length == 1
                tag.div(class: @options[:attributes][:class]) do
                  action_links.first.render
                end
              else
                tag.ul(class: @options[:attributes][:class]) do
                  action_links.each do |action_link|
                    concat(tag.li(action_link.render, class: 'govuk-summary-card__action'))
                  end
                end
              end
            end

            # The default attributes for the summary list card actions

            DEFAULT_ATTRIBUTES = { class: 'govuk-summary-card__actions' }.freeze
          end
        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/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/summary_list/card/actions.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/summary_list/card/actions.rb