Class: SdrViewComponents::Tables::RowComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/tables/row_component.rb

Overview

Component for rendering a table row.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #merge_actions, #merge_classes

Constructor Details

#initialize(label: nil, first_value: nil, values: [], value: nil, tooltip: nil, **row_options) ⇒ RowComponent

rubocop:disable Metrics/ParameterLists

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/sdr_view_components/tables/row_component.rb', line 10

def initialize(label: nil, first_value: nil, values: [], value: nil, tooltip: nil, **row_options) # rubocop:disable Metrics/ParameterLists
  # Provide either label or first_value but not both; these are rendered in the first column
  # label renders with <th> (bold), first_value is a normal <td>
  @label = label
  @first_value = first_value
  # Provide either value, values or cells (e.g. for content files).
  @values = Array(value).presence || values
  @tooltip = tooltip
  @row_options = row_options

  raise ArgumentError if label.present? && first_value.present?

  super()
end

Instance Attribute Details

#first_valueObject (readonly)

Returns the value of attribute first_value.



25
26
27
# File 'app/components/sdr_view_components/tables/row_component.rb', line 25

def first_value
  @first_value
end

#labelObject (readonly)

Returns the value of attribute label.



25
26
27
# File 'app/components/sdr_view_components/tables/row_component.rb', line 25

def label
  @label
end

#row_optionsObject (readonly)

Returns the value of attribute row_options.



25
26
27
# File 'app/components/sdr_view_components/tables/row_component.rb', line 25

def row_options
  @row_options
end

#tooltipObject (readonly)

Returns the value of attribute tooltip.



25
26
27
# File 'app/components/sdr_view_components/tables/row_component.rb', line 25

def tooltip
  @tooltip
end

#valuesObject (readonly)

Returns the value of attribute values.



25
26
27
# File 'app/components/sdr_view_components/tables/row_component.rb', line 25

def values
  @values
end

Instance Method Details

#empty_cell?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/components/sdr_view_components/tables/row_component.rb', line 27

def empty_cell?
  label.present? && values.empty? && !cells?
end