Skip to content

Instantly share code, notes, and snippets.

@bradgessler
Created March 3, 2024 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradgessler/d284fe36bd6c95a178640f9452566293 to your computer and use it in GitHub Desktop.
Save bradgessler/d284fe36bd6c95a178640f9452566293 to your computer and use it in GitHub Desktop.
Playing around with a table component
TableComponent.new @items do |table|
# Emmits a `thead > th` with "Name" and a `tbody > td` with the name of each item.
table.column("Name") { _1.name }
# Emmits a `thead > th` with "Name" and a `tbody > td` with the name of each item.
table.column(:name)
# Emmits a `thead > th` with "Interview Times" and a `tbody > th` with the name of each item.
table.column("Name").th(class: "bg-read-100") { show(_1, :name) }
# Emmits a `thead > th` with "Interview Times" and a `tbody > th` with the name of each item.
table.column do |it|
it.thead { th(class: "bg-red-100") { "Interview Times" } }
it.tbody { th(class: "bg-read-100") { |item| show(item, :name) } }
end
# Modify the thead tag and iterator
table.head(class: "bg-red-100") { thead_columns }
# When a block isn't provided, it will call `tbody_columns`
table.body(class: "bg-blue-100")
table.foot(class: "bg-orange-100"){ tfoot_columns }
end
# Additionally, a table can be inheritted and modified
class MyTableComponent < TableComponent
def head(**, &)
thead(class: "bg-red-900", **, &)
end
def body(**, &)
tbody(class: "bg-red-900", **, &)
end
def foot(**, &)
tfoot(class: "bg-red-900", **, &)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment