Created
March 3, 2024 21:56
-
-
Save bradgessler/d284fe36bd6c95a178640f9452566293 to your computer and use it in GitHub Desktop.
Playing around with a table component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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