Class: PhlexKit::Table

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/table/table.rb

Overview

Data table, ported from ruby_ui's RubyUI::Table. Presentational, no JS. Multi-part, like PhlexKit::Card — the lead Table wraps a

in an overflow container; the rest map 1:1 onto the table elements:

render PhlexKit::Table.new do
render PhlexKit::TableHeader.new do
  render PhlexKit::TableRow.new do
    render PhlexKit::TableHead.new { "Name" }
    render PhlexKit::TableHead.new { "Email" }
  end
end
render PhlexKit::TableBody.new do
  @users.each do |u|
    render PhlexKit::TableRow.new do
      render PhlexKit::TableCell.new { u.name }
      render PhlexKit::TableCell.new { u.email }
    end
  end
end
end

Tailwind → vanilla .pk-table-* (table.css), palette from the global tokens.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(**attrs) ⇒ Table

Returns a new instance of Table.



25
26
27
# File 'app/components/phlex_kit/table/table.rb', line 25

def initialize(**attrs)
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



29
30
31
32
33
# File 'app/components/phlex_kit/table/table.rb', line 29

def view_template(&block)
  div(class: "pk-table-wrapper") do
    table(**mix({ class: "pk-table" }, @attrs), &block)
  end
end