The personal finance app for everyone (by everyone)
Ruby
<%# locals: (account_group:, mobile: false, all_tab: false, open: nil, sortable: false, **args) %>
<% copy = account_group.dom_id(tab: all_tab ? :all : nil, mobile: mobile) %>
<div id="<%= copy %>" data-group-key="<%= account_group.key %>">
<% is_open = open.nil? ? (account_group.accounts.any? { |account| page_active?(account_path(account)) } || Current.user.always_expanded_account_group?(account_group.key)) : open %>
<%# The summary owns the name's slide: it is what a tap or keyboard focus
lands on (sidebar_name_marquee_controller). %>
<%= render DS::Disclosure.new(align: :left, open: is_open,
summary_data: { controller: "sidebar-name-marquee",
action: "focus->sidebar-name-marquee#focus pointerup->sidebar-name-marquee#tap" }) do |disclosure| %>
<% disclosure.with_summary_content do %>
<%# The name gives way (truncating) to the total, so a long group name
can't push the total out of line at a narrow sidebar width; the
title shows the full name on hover. With no hover (a touch screen)
or with keyboard focus, a cut name slides once to show its end
(sidebar_name_marquee_controller). With reduced motion the name
keeps its full width there instead, and a total that no longer
fits moves to the line below, still on the right; a tap on a
screen whose main pointer is fine does the same (the controller
marks the summary data-name-revealed). %>
<div class="flex items-center w-full min-w-0 gap-x-2 pointer-coarse:motion-reduce:flex-wrap [summary:focus-visible_&]:motion-reduce:flex-wrap in-data-name-revealed:flex-wrap">
<div class="flex items-center gap-3 min-w-0 pointer-coarse:motion-reduce:shrink-0 pointer-coarse:motion-reduce:max-w-full [summary:focus-visible_&]:motion-reduce:shrink-0 [summary:focus-visible_&]:motion-reduce:max-w-full in-data-name-revealed:shrink-0 in-data-name-revealed:max-w-full">
<%= icon "chevron-right", class: "shrink-0 group-open:transform group-open:rotate-90" %>
<%= tag.span class: class_names("text-sm text-primary font-medium truncate pointer-coarse:motion-reduce:whitespace-normal [summary:focus-visible_&]:motion-reduce:whitespace-normal in-data-name-revealed:whitespace-normal", "animate-pulse" => account_group.syncing?),
title: account_group.name,
data: { sidebar_name_marquee_target: "name" } do %>
<%= tag.span account_group.name, data: { sidebar_name_marquee_target: "text" } %>
<% end %>
</div>
<div class="ml-auto text-right shrink-0">
<%= tag.p format_money(account_group.total_money), class: "text-sm font-medium text-primary whitespace-nowrap privacy-sensitive" %>
<% group_version = sidebar_sparkline_versions(Current.family)[account_group.accountable_type] %>
<%= tag.div id: sidebar_sparkline_wrapper_id(copy, "total", group_version), data: kept_element_data do %>
<%= turbo_frame_tag "#{account_group.key}_sparkline",
src: accountable_sparkline_path(account_group.key, v: group_version),
loading: "lazy",
data: sparkline_frame_data do %>
<div class="flex items-center w-8 h-4 ml-auto">
<div class="w-6 h-px bg-loader"></div>
</div>
<% end %>
<% end %>
</div>
</div>
<% end %>
<%= tag.div class: "space-y-1",
data: sortable ? {
controller: "sortable-list",
sortable_list_url_value: reorder_accounts_path(group: account_group.key),
sortable_list_param_value: "account_ids",
sortable_list_hold_delay_value: 400,
sortable_list_save_timeout_value: 10_000,
sortable_list_mirror_lists_value: true,
action: "dragover->sortable-list#dragOver drop->sortable-list#drop account-sort-mode:stop@window->sortable-list#releaseKeyboardGrab turbo:before-visit@window->sortable-list#saveBeforeVisit"
} : {} do %>
<% account_group.accounts.each do |account| %>
<%# Rows become draggable only in sort mode (account-sort-mode). %>
<%= tag.div class: "flex items-center gap-1 rounded-lg",
data: sortable ? {
sortable_list_target: "item",
sortable_list_id: account.id,
action: "dragstart->sortable-list#dragStart dragend->sortable-list#dragEnd"
} : {} do %>
<% if sortable %>
<%# Hidden until the sidebar is in sort mode (account-sort-mode). %>
<%= render DS::Button.new(
variant: :icon,
icon: "grip-vertical",
size: :sm,
style: "display:none",
class: "shrink-0 cursor-grab active:cursor-grabbing touch-none [-webkit-touch-callout:none]",
aria_label: t("accounts.sidebar.reorder_account", account: account.name),
title: t("accounts.sidebar.reorder_hint"),
data: {
account_sort_mode_target: "handle",
action: "touchstart->sortable-list#touchStart touchmove->sortable-list#touchMove touchend->sortable-list#touchEnd touchcancel->sortable-list#touchCancel contextmenu->sortable-list#suppressContextMenu keydown->sortable-list#handleKeyDown"
}
) %>
<% end %>
<%= link_to account_path(account),
class: class_names(
"block flex items-center gap-2 px-3 py-2 rounded-lg min-w-0 grow",
page_active?(account_path(account)) ? "bg-container" : "hover:bg-surface-hover"
),
data: page_active?(account_path(account)) ? { active_account: true } : {},
title: account.name do %>
<%= tag.span id: sidebar_logo_wrapper_id(copy, account, account_group.color), class: "shrink-0", data: kept_element_data do %>
<%= render "accounts/logo", account: account, size: "sm", color: account_group.color %>
<% end %>
<div class="min-w-0 grow">
<div class="flex items-center gap-2 mb-0.5">
<%= tag.p account.name, class: class_names("text-sm text-primary font-medium truncate", "animate-pulse" => account.syncing?) %>
<% if account.shared? %>
<%= icon("users", class: "w-3 h-3 text-secondary shrink-0") %>
<% end %>
</div>
<%= tag.p account.short_subtype_label, class: "text-sm text-secondary truncate" %>
</div>
<div class="ml-auto text-right grow h-10">
<%= tag.p format_money(account.balance_money), class: "text-sm font-medium text-primary whitespace-nowrap privacy-sensitive" %>
<% account_version = sidebar_sparkline_versions(Current.family)[account.id] %>
<%= tag.div id: sidebar_sparkline_wrapper_id(copy, account.id, account_version), data: kept_element_data do %>
<%= turbo_frame_tag dom_id(account, :sparkline),
src: sparkline_account_path(account, v: account_version),
loading: "lazy",
data: sparkline_frame_data do %>
<div class="flex items-center w-8 h-4 ml-auto">
<div class="w-6 h-px bg-loader"></div>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
<% end %>
<% end %>
<div class="my-2">
<%= render DS::Link.new(
href: new_polymorphic_path(account_group.key, step: "method_select"),
text: t("accounts.sidebar.new_account_group", account_group: account_group.accountable_type.singular_display_name.downcase),
icon: "plus",
full_width: true,
variant: "ghost",
frame: :modal,
class: "justify-start"
) %>
</div>
<% end %>
</div>