Class: DesignSystem::Generic::SummaryListComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- DesignSystem::Generic::SummaryListComponent
- Defined in:
- app/components/design_system/generic/summary_list_component.rb
Overview
Summary list (dl) rendered by ds_summary_list. Each row has a key, one or more values, and optional actions. Brands override paragraph class and hidden text via subclasses.
Direct Known Subclasses
DesignSystem::Govuk::SummaryListComponent, Nhsuk::SummaryListComponent
Instance Attribute Summary collapse
-
#summary_list ⇒ Object
readonly
Returns the value of attribute summary_list.
Instance Method Summary collapse
-
#initialize(summary_list:) ⇒ SummaryListComponent
constructor
A new instance of SummaryListComponent.
- #render_action(action) ⇒ Object
- #value_content(row) ⇒ Object
- #wrap_value(value, paragraph: false) ⇒ Object
Methods included from Helpers::CssHelper
Methods included from BrandDerivable
Constructor Details
#initialize(summary_list:) ⇒ SummaryListComponent
Returns a new instance of SummaryListComponent.
7 8 9 10 |
# File 'app/components/design_system/generic/summary_list_component.rb', line 7 def initialize(summary_list:) super() @summary_list = summary_list end |
Instance Attribute Details
#summary_list ⇒ Object (readonly)
Returns the value of attribute summary_list.
12 13 14 |
# File 'app/components/design_system/generic/summary_list_component.rb', line 12 def summary_list @summary_list end |
Instance Method Details
#render_action(action) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/components/design_system/generic/summary_list_component.rb', line 24 def render_action(action) = action[:options].dup path = .delete(:path) || '#' hidden_text = .delete(:hidden_text) link_to(path, { class: "#{brand}-link" }.merge()) do safe_join([action[:content], render_hidden_text(hidden_text)]) end end |
#value_content(row) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/components/design_system/generic/summary_list_component.rb', line 14 def value_content(row) if row[:values].blank? '' elsif row[:values].length == 1 wrap_value(row[:values].first) else safe_join(row[:values].map { |value| wrap_value(value, paragraph: true) }) end end |
#wrap_value(value, paragraph: false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/design_system/generic/summary_list_component.rb', line 34 def wrap_value(value, paragraph: false) content = if value[:options]&.dig(:path) link_to(value[:content], value[:options][:path] || '#', class: "#{brand}-link") else value[:content] end return content unless paragraph content_tag(:p, content, class: value_paragraph_class) end |