Class: DesignSystem::Generic::TableComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- DesignSystem::Generic::TableComponent
show all
- Defined in:
- app/components/design_system/generic/table_component.rb
Overview
Table rendered by ds_table. Wraps a caption, header row and body rows
built via the Table data object. Brands override markup via their own
templates; cell helpers live here for reuse.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#css_class_options_merge
#brand
Constructor Details
#initialize(table:, **options) ⇒ TableComponent
Returns a new instance of TableComponent.
7
8
9
10
11
|
# File 'app/components/design_system/generic/table_component.rb', line 7
def initialize(table:, **options)
super()
@table = table
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
13
14
15
|
# File 'app/components/design_system/generic/table_component.rb', line 13
def options
@options
end
|
#table ⇒ Object
Returns the value of attribute table.
13
14
15
|
# File 'app/components/design_system/generic/table_component.rb', line 13
def table
@table
end
|
Instance Method Details
#cell_content(cell) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'app/components/design_system/generic/table_component.rb', line 15
def cell_content(cell)
if cell[:content].is_a?(Numeric)
cell[:content].to_s
elsif cell[:content].is_a?(Proc)
capture(&cell[:content])
else
cell[:content]
end
end
|
#cell_numeric?(cell) ⇒ Boolean
25
26
27
|
# File 'app/components/design_system/generic/table_component.rb', line 25
def cell_numeric?(cell)
cell[:options][:type] == 'numeric'
end
|
#data_cell_classes(cell) ⇒ Object
39
40
41
42
43
|
# File 'app/components/design_system/generic/table_component.rb', line 39
def data_cell_classes(cell)
classes = "#{brand}-table__cell"
classes += " #{brand}-table__cell--numeric" if cell_numeric?(cell)
classes
end
|
33
34
35
36
37
|
# File 'app/components/design_system/generic/table_component.rb', line 33
def (cell)
classes = "#{brand}-table__header"
classes += " #{brand}-table__header--numeric" if cell_numeric?(cell)
classes
end
|
#html_cell_options(cell, **extra) ⇒ Object
29
30
31
|
# File 'app/components/design_system/generic/table_component.rb', line 29
def html_cell_options(cell, **)
cell[:options].except(:type).merge()
end
|