Class: DesignSystem::Generic::SummaryListComponent

Inherits:
BaseComponent
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CssHelper

#css_class_options_merge

Methods included from BrandDerivable

#brand

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_listObject (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)
  options = action[:options].dup
  path = options.delete(:path) || '#'
  hidden_text = options.delete(:hidden_text)

  link_to(path, { class: "#{brand}-link" }.merge(options)) 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

  (:p, content, class: value_paragraph_class)
end