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(wrapper: {}, **attrs) ⇒ Table

Returns a new instance of Table.



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

def initialize(wrapper: {}, **attrs)
  @wrapper = wrapper
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



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

def view_template(&block)
  # Caller attrs land on the <table>; wrapper: reaches the scroll
  # container (e.g. to cap its height) — same escape hatch as Switch.
  div(**mix({ class: "pk-table-wrapper" }, @wrapper)) do
    table(**mix({ class: "pk-table" }, @attrs), &block)
  end
end