Class: AhoyCaptain::Tables::DynamicTableComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/ahoy_captain/tables/dynamic_table_component.rb

Defined Under Namespace

Classes: TableDefinition

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, table, options = {}) ⇒ DynamicTableComponent

Returns a new instance of DynamicTableComponent.



184
185
186
187
188
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 184

def initialize(klass, table, options = {})
  @klass = klass
  @table = table
  @options = options
end

Class Method Details

.build(klass, options = {}, &block) ⇒ Object



176
177
178
179
180
181
182
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 176

def self.build(klass, options = {}, &block)
  if options.key?(:fixed_height)
    options[:header_options] = { fixed_height: options.delete(:fixed_height) }
  end
  table = TableDefinition.new(klass).instance_exec(&block)
  new(klass, table, options)
end

Instance Method Details

#for(item) ⇒ Object



190
191
192
193
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 190

def for(item)
  @item = item
  self
end

#headersObject



199
200
201
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 199

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



195
196
197
# File 'app/components/ahoy_captain/tables/dynamic_table_component.rb', line 195

def row(item, view_context)
  @table.row(item, view_context)
end