Class: GovukComponent::SummaryListComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/summary_list_component.rb

Defined Under Namespace

Classes: ActionComponent, CardComponent, KeyComponent, RowComponent, ValueComponent

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, card: {}, visually_hidden_action_suffix: nil, classes: [], html_attributes: {}) ⇒ SummaryListComponent

Returns a new instance of SummaryListComponent.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/govuk_component/summary_list_component.rb', line 15

def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, card: {}, visually_hidden_action_suffix: nil, classes: [], html_attributes: {})
  @borders                       = borders
  @show_actions_column           = actions
  @card                          = GovukComponent::SummaryListComponent::CardComponent.new(**card) if card.present?
  @visually_hidden_action_suffix = visually_hidden_action_suffix

  super(classes:, html_attributes:)

  return unless rows.presence

  build(rows)
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



3
4
5
# File 'app/components/govuk_component/summary_list_component.rb', line 3

def actions
  @actions
end

#bordersObject (readonly)

Returns the value of attribute borders.



3
4
5
# File 'app/components/govuk_component/summary_list_component.rb', line 3

def borders
  @borders
end

#cardObject (readonly)

Returns the value of attribute card.



3
4
5
# File 'app/components/govuk_component/summary_list_component.rb', line 3

def card
  @card
end

#visually_hidden_action_suffixObject (readonly)

Returns the value of attribute visually_hidden_action_suffix.



3
4
5
# File 'app/components/govuk_component/summary_list_component.rb', line 3

def visually_hidden_action_suffix
  @visually_hidden_action_suffix
end

Instance Method Details

#callObject



28
29
30
31
32
# File 'app/components/govuk_component/summary_list_component.rb', line 28

def call
  summary_list = tag.dl(**html_attributes) { safe_join(rows) }

  (card?) ? card_with(summary_list) : summary_list
end