The personal finance app for everyone (by everyone)
Ruby
<%# locals: (sections:, namespace:, url:, i18n_scope:, collapse_url: nil) %>
<%# The section list Reports and the portfolio page share: each visible section
drags to reorder (saved to `url` as preferences.<namespace>_section_order)
and collapses (saved under <namespace>_collapsed_sections). The collapse
state posts to the Reports endpoint unless `collapse_url` is given.
`i18n_scope` holds the page's `sections_aria` and `section_aria` labels. %>
<div data-controller="sortable-list"
data-sortable-list-url-value="<%= url %>"
data-sortable-list-param-value="preferences.<%= namespace %>_section_order"
data-sortable-list-hold-delay-value="800"
data-sortable-list-own-keys-only-value="true"
data-action="dragover->sortable-list#dragOver drop->sortable-list#drop turbo:before-visit@window->sortable-list#saveBeforeVisit"
role="list"
aria-label="<%= t("#{i18n_scope}.sections_aria") %>">
<% sections.each do |section| %>
<% next unless section[:visible] %>
<% collapsed = Current.user.section_collapsed?(namespace, section[:key]) %>
<%# The section is the list item that drags and takes the reorder keys;
the DS::Disclosure inside it is the card that opens and closes.
[-webkit-touch-callout:none] keeps iOS Safari's long-press link preview
on links inside a section from cancelling the touch, which would stop
the press-and-hold drag from ever starting. %>
<section
class="rounded-xl transition-all mb-6 focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 [-webkit-touch-callout:none]"
data-sortable-list-target="item"
data-sortable-list-id="<%= section[:key] %>"
data-section-key="<%= section[:key] %>"
data-controller="reports-section"
data-reports-section-section-key-value="<%= section[:key] %>"
data-reports-section-collapsed-value="<%= collapsed %>"
<% if collapse_url %>
data-reports-section-url-value="<%= collapse_url %>"
data-reports-section-preference-key-value="<%= namespace %>"
<% end %>
draggable="true"
tabindex="0"
role="listitem"
aria-grabbed="false"
aria-label="<%= t("#{i18n_scope}.section_aria", title: t(section[:title])) %>"
data-action="
dragstart->sortable-list#dragStart
dragend->sortable-list#dragEnd
touchstart->sortable-list#touchStart
touchmove->sortable-list#touchMove
touchend->sortable-list#touchEnd
touchcancel->sortable-list#touchCancel
contextmenu->sortable-list#suppressContextMenu
keydown->sortable-list#handleKeyDown">
<%= render DS::Disclosure.new(
variant: :card,
open: !collapsed,
body_class: "mt-4",
data: { reports_section_target: "details", action: "toggle->reports-section#save" }
) do |disclosure| %>
<% disclosure.with_summary_content do %>
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<%= disclosure_chevron %>
<h2 class="text-base font-medium">
<%= t(section[:title]) %>
</h2>
<% if section[:preview] %>
<%= render DS::Pill.new(label: t("shared.preview")) %>
<% end %>
</div>
<%# Optional controls on the title row. A click on a button in here
activates the button, not the summary, so it doesn't collapse the section. %>
<% if section[:header_partial] %>
<div class="ml-auto flex items-center gap-2">
<%= render partial: section[:header_partial], locals: section[:header_locals] || {} %>
</div>
<% end %>
<%# A mouse grab hint. Keys only grab the section itself, so the
hint stays out of the tab order instead of being an invisible
stop. %>
<span
class="cursor-grab active:cursor-grabbing hidden lg:flex items-center justify-center w-6 h-6 text-secondary hover:text-primary transition-colors opacity-0 group-hover:opacity-100"
aria-hidden="true">
<%= icon("grip-vertical", size: "sm") %>
</span>
</div>
<% end %>
<%# A cached page (Reports) hands over its section content already rendered. %>
<%= section[:html] ? section[:html].html_safe : render(partial: section[:partial], locals: section[:locals]) %>
<% end %>
</section>
<% end %>
</div>