The personal finance app for everyone (by everyone)
Ruby
<%= tag.details class: details_classes, open: open, **details_opts do %>
<%= tag.summary class: summary_classes, aria: summary_aria_attrs, data: summary_data do %>
<% if summary_content? %>
<% if variant.in?(%i[default bare]) %>
<%# `:default` summary is already `flex justify-between`, so
caller-provided sibling divs get distributed directly.
Wrapping would collapse them into a single flex child and
kill the justify-between distribution. %>
<%= summary_content %>
<% else %>
<%# Non-default summaries are `list-item` (no flex), so a flex
caller div would shrink-wrap to content width and any
`justify-between` inside has nothing to distribute. Wrap
in `w-full` so caller flex rows stretch across the card. %>
<div class="w-full">
<%= summary_content %>
</div>
<% end %>
<% else %>
<%# The chevrons follow their own <details>, not `group-open:`, which
matches any open ancestor group: a disclosure inside an open one
would show open while closed. %>
<div class="flex items-center gap-3">
<% if align == :left %>
<%= helpers.icon "chevron-right", class: "[details[open]>summary_&]:rotate-90 motion-safe:transition-transform motion-safe:duration-150" %>
<% end %>
<%= tag.span class: class_names("font-medium", align == :left ? "text-sm text-primary" : "text-xs uppercase text-secondary") do %>
<%= title %>
<% end %>
</div>
<% if align == :right %>
<%= helpers.icon "chevron-down", class: "[details[open]>summary_&]:rotate-180 motion-safe:transition-transform motion-safe:duration-150" %>
<% end %>
<% end %>
<% end %>
<% if variant == :bare %>
<%= content %>
<% else %>
<%= tag.div class: body_class.presence do %>
<%= content %>
<% end %>
<% end %>
<% end %>