Class: Panda::Core::Admin::TableComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/table_component.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#after_template, #attrs, #before_template, #default_attrs, #merge_attrs, #tailwind_merge_attrs

Constructor Details

#initialize(**props) ⇒ TableComponent

Returns a new instance of TableComponent.



13
14
15
16
# File 'app/components/panda/core/admin/table_component.rb', line 13

def initialize(**props)
  super
  @columns = []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



11
12
13
# File 'app/components/panda/core/admin/table_component.rb', line 11

def columns
  @columns
end

Instance Method Details

#column(label, width: nil, &cell_block) ⇒ Object



29
30
31
# File 'app/components/panda/core/admin/table_component.rb', line 29

def column(label, width: nil, &cell_block)
  @columns << Column.new(label, width, &cell_block)
end

#view_template(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/components/panda/core/admin/table_component.rb', line 18

def view_template(&block)
  # Capture the block to populate columns
  instance_eval(&block) if block_given?

  if @rows.any?
    render_table_with_rows
  else
    render_empty_table
  end
end