Skip to content

Commit

Permalink
CardComponent: Gray the Footer, pull Classes into HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
zspencer committed Jan 14, 2024
1 parent 04e0391 commit 384ad63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
8 changes: 4 additions & 4 deletions app/components/card_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div <%==attributes(classes: card_classes_wrapper) %>>
<div <%==attributes(classes: "shadow rounded-lg bg-white group-hover:bg-slate-50 flex flex-col justify-between #{header_classes}") %>>
<% if header? %>
<header>
<header class="p-2 sm:p-4">
<%= header%>
</header>

Expand All @@ -9,12 +9,12 @@
NOTE: content? is not always working as described, and is returning a proc in some cases rather than a boolean
%>
<% if content.present? %>
<div class="<%== card_classes_content %>">
<div class="flex flex-col h-full justify-between p-2 sm:p-4 <%= content_classes%>">
<%= content %>
</div>
<% end %>
<% if footer? %>
<div class="<%== card_classes_footer %>">
<div class="bg-slate-50 p-2 sm:p-4 <%= "rounded-t-none" if content.blank? %> <%= footer_classes %>">
<%= footer %>
</div>
<% end %>
Expand Down
34 changes: 8 additions & 26 deletions app/components/card_component.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
class CardComponent < ApplicationComponent
renders_one :header
renders_one :footer
attr_accessor :wrapper_classes

private
renders_one :header
attr_accessor :header_classes

def card_classes_content
[
"p-4",
"sm:p-6"
].compact.join(" ")
end
attr_accessor :content_classes

def card_classes_wrapper
[
"shadow",
"rounded-lg",
"h-full",
"bg-white",
"group-hover:bg-slate-50"
].compact.join(" ")
end
renders_one :footer
attr_accessor :footer_classes

def card_classes_footer
[
"bg-orange-50",
"p-4",
"sm:p-6",
# content? is not always working as described, and is returning a proc in some cases rather than a boolean
("rounded-t-none" if content.blank?)
].compact.join(" ")
def initialize(header_classes: "", content_classes: "", wrapper_classes: "", **kwargs)
super(**kwargs)
end
end

0 comments on commit 384ad63

Please sign in to comment.