Class: CCS::Components::GovUK::SummaryList::Card::Actions

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/summary_list/card/actions.rb

Overview

GOV.UK Summary list card actions

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the summary list card actions

{ class: 'govuk-summary-card__actions' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(items:, card_title:, **options) ⇒ Actions

Returns a new instance of Actions.

Parameters:

  • items (Array<Hash>)

    An array of attributes for the action links. See Action::Link#initialize for details of the items in the array.

  • card_title (String)

    the text for the card title

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the summary list card actions HTML



28
29
30
31
32
# File 'lib/ccs/components/govuk/summary_list/card/actions.rb', line 28

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

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

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Summary list card actions

Returns:

  • (ActiveSupport::SafeBuffer)


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ccs/components/govuk/summary_list/card/actions.rb', line 38

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