Class: RUI::Table

Inherits:
Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::DOMID
Defined in:
lib/rui/table.rb

Defined Under Namespace

Classes: Row

Instance Method Summary collapse

Constructor Details

#initialize(rows, **attrs) ⇒ Table

Returns a new instance of Table.



4
5
6
7
8
# File 'lib/rui/table.rb', line 4

def initialize(rows, **attrs)
  @rows = rows
  @columns = []
  @attrs = attrs
end

Instance Method Details

#column(header = "", **attrs, &content) ⇒ Object



30
31
32
# File 'lib/rui/table.rb', line 30

def column(header = "", **attrs, &content)
  @columns << { header:, attrs:, content: }
end

#view_templateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rui/table.rb', line 10

def view_template(&)
  vanish(&)

  table(class: "bg-white w-full table-auto border-collapse rounded", **@attrs) do
    thead(class: "bg-blue-50") do
      @columns.each do |column|
        th(class: classes(column[:attrs][:class])) do
          column[:header]
        end
      end
    end

    tbody do
      @rows.each do |row|
        render Row.new(row:, columns: @columns)
      end
    end
  end
end