Created
July 30, 2021 06:04
-
-
Save AndreaBarghigiani/cea8c4406dec32390830c06005b5e65c to your computer and use it in GitHub Desktop.
Simple Table with ViewComponents
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
<table class="<%= classes %>"> | |
<thead class='bg-gray-300 font-medium'> | |
<% head %> | |
</thead> | |
<tbody> | |
<% body %> | |
</tbody> | |
</table> |
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
# 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 |
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
<%= 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