Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
1.8 KB
Raw Blame
<%= render DS::Menu.new(variant: :button, placement: placement) do |menu| %>
  <% menu.with_button(
       type: "button",
       class: "inline-flex items-center gap-1.5 bg-container border border-secondary font-medium rounded-lg pl-3 pr-2 py-2 text-sm cursor-pointer text-primary hover:bg-container-inset-hover focus:outline-hidden focus:ring-0",
       aria: { label: t("UI.period_picker.aria_label", period: selected_label) }
     ) do %>
    <span class="whitespace-nowrap"><%= selected_label %></span>
    <%= helpers.icon("chevron-down", size: "sm") %>
  <% end %>

  <%# Both pickers navigate a Turbo frame — the dashboard's `dashboard_sections`
      and, implicitly, the account page's own container frame — and a frame
      navigation leaves the address bar alone. Without an explicit visit action
      a stale ?start_date/&end_date from a chart drag-select would outlive a
      preset pick and come back on refresh. See `turbo_action_for` for why the
      checked row replaces rather than advances. %>
  <% items.each do |key, label| %>
    <% item_selected = selected?(key) %>
    <% menu.with_item(
         variant: :link,
         text: label,
         href: href_for(key),
         frame: frame,
         selected: item_selected,
         data: { turbo_action: turbo_action_for(item_selected) }
       ) %>
  <% end %>

  <% if custom_row? %>
    <%# Last, so the presets keep their positions. Without this row a custom
        range leaves the list with nothing checked, which reads as "no selection"
        and hides the fact that picking a preset is how you leave it. %>
    <% menu.with_item(
         variant: :link,
         text: selected.label_short,
         href: custom_href,
         frame: frame,
         selected: true,
         data: { turbo_action: turbo_action_for(true) }
       ) %>
  <% end %>
<% end %>