Class: CCS::Components::GovUK::SummaryList

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/summary_list.rb,
lib/ccs/components/govuk/summary_list/row.rb,
lib/ccs/components/govuk/summary_list/card.rb,
lib/ccs/components/govuk/summary_list/row/key.rb,
lib/ccs/components/govuk/summary_list/row/value.rb,
lib/ccs/components/govuk/summary_list/card/title.rb,
lib/ccs/components/govuk/summary_list/action/link.rb,
lib/ccs/components/govuk/summary_list/row/actions.rb,
lib/ccs/components/govuk/summary_list/card/actions.rb

Overview

GOV.UK Summary list

This is used for generating the summary list component from the GDS - Components - Summary list

Defined Under Namespace

Classes: Action, Card, Row

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the summary list

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

Instance Method Summary collapse

Constructor Details

#initialize(summary_list_items:, card: nil, **options) ⇒ SummaryList

Returns a new instance of SummaryList.

Parameters:

  • summary_list_items (Array<Hash>)

    An array of options for the summary list rows. See Row#initialize for details of the items in the array.

  • card (Hash) (defaults to: nil)

    attributes for the card, see Card#initialize for more details.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the summary list HTML

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



33
34
35
36
37
38
39
40
# File 'lib/ccs/components/govuk/summary_list.rb', line 33

def initialize(summary_list_items:, card: nil, **options)
  super(**options)

  any_row_has_actions = summary_list_items.any? { |summary_list_item| summary_list_item.dig(:actions, :items).present? }

  @summary_list_rows = summary_list_items.map { |summary_list_item| Row.new(any_row_has_actions: any_row_has_actions, card_title: card&.dig(:title, :text), context: @context, **summary_list_item) }
  @card = Card.new(context: @context, **card) if card
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Summary list component

Returns:

  • (ActiveSupport::SafeBuffer)


46
47
48
49
50
51
52
53
54
# File 'lib/ccs/components/govuk/summary_list.rb', line 46

def render
  if card
    card.render do
      render_summary_list
    end
  else
    render_summary_list
  end
end