Class: Lookout::Tables::DynamicTableComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Lookout::Tables::DynamicTableComponent
- Defined in:
- app/components/lookout/tables/dynamic_table_component.rb
Defined Under Namespace
Classes: TableDefinition
Class Method Summary collapse
Instance Method Summary collapse
- #for(item) ⇒ Object
- #headers ⇒ Object
-
#initialize(klass, table, options = {}) ⇒ DynamicTableComponent
constructor
A new instance of DynamicTableComponent.
- #row(item, view_context) ⇒ Object
Constructor Details
#initialize(klass, table, options = {}) ⇒ DynamicTableComponent
Returns a new instance of DynamicTableComponent.
187 188 189 190 191 |
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 187 def initialize(klass, table, = {}) @klass = klass @table = table @options = end |
Class Method Details
.build(klass, options = {}, &block) ⇒ Object
179 180 181 182 183 184 185 |
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 179 def self.build(klass, = {}, &block) if .key?(:fixed_height) [:header_options] = { fixed_height: .delete(:fixed_height) } end table = TableDefinition.new(klass).instance_exec(&block) new(klass, table, ) end |
Instance Method Details
#for(item) ⇒ Object
193 194 195 196 |
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 193 def for(item) @item = item self end |
#headers ⇒ Object
202 203 204 |
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 202 def headers HeaderComponent.new(@table.rows.map.with_index { |row, index| { label: row.header, grow: index.zero? } }, @options[:header_options] || {}) end |
#row(item, view_context) ⇒ Object
198 199 200 |
# File 'app/components/lookout/tables/dynamic_table_component.rb', line 198 def row(item, view_context) @table.row(item, view_context) end |