Skip to content

Instantly share code, notes, and snippets.

@AndreaBarghigiani
Created July 30, 2021 06:04
Show Gist options
  • Save AndreaBarghigiani/cea8c4406dec32390830c06005b5e65c to your computer and use it in GitHub Desktop.
Save AndreaBarghigiani/cea8c4406dec32390830c06005b5e65c to your computer and use it in GitHub Desktop.
Simple Table with ViewComponents
<table class="<%= classes %>">
<thead class='bg-gray-300 font-medium'>
<% head %>
</thead>
<tbody>
<% body %>
</tbody>
</table>
# frozen_string_literal: true
class TableComponent < ViewComponent::Base
renders_many :head, THeadComponent
renders_many :body, TBodyComponent
def initialize(classname: nil)
@classname = classname
end
def classes
c = ["w-full"]
c << @classname
c.join(' ')
end
end
<%= render TableComponent.new do |t| %>
<% t.head(["Text", "Text", "Text", "Text"]) %>
<% t.body(["Text", "Text", "Text", "Text"]) %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment