Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

4.2 KB
Raw Blame
<%#
# Navigation

From `lg` up it is a sidebar, like the agent dashboard's: the brand, the main
links and the account menu at the bottom. On Settings and Monitor the links give
way to that section's own, with a way back to the main ones.

Below `lg` it is a top bar: the brand and the account menu, with the links in a
second row that stays pinned while the brand row scrolls away. Below `md` that
row is a tab bar. From `sm` up it shows every link; on phones only the pinned
ones show, the rest sit behind "More".
%>

<%
  items = primary_nav_items
  more_items = items.reject { |item| item[:pinned] }
  section = section_nav
  brand = render("brand")
  tab = %w[
    flex h-14 min-w-0 flex-col items-center justify-center gap-0.5 border-b-2 border-transparent text-xxs font-medium text-n-slate-11 transition-colors
    hover:text-n-slate-12 aria-[current=page]:border-n-brand aria-[current=page]:text-n-slate-12
    md:h-9 md:flex-row md:rounded-lg md:border-0 md:px-2.5 md:text-body-main md:hover:bg-n-alpha-2
    md:aria-[current=page]:bg-n-alpha-2 md:aria-[current=page]:font-medium
  ].join(" ")
%>

<aside class="hidden border-e border-n-weak bg-n-slate-2 dark:bg-n-solid-1 lg:sticky lg:top-0 lg:flex lg:h-dvh lg:w-52 lg:shrink-0 lg:flex-col">
  <div class="relative shrink-0 px-4">
    <div class="relative"><%= brand %></div>
  </div>
  <div class="shrink-0 px-3 pt-1">
    <button type="button" class="flex h-9 w-full items-center gap-2 rounded-lg border border-n-weak bg-n-solid-1 px-2.5 text-body-main text-n-slate-10 transition-colors hover:border-n-slate-7 hover:text-n-slate-11" data-dialog-open="command-bar" aria-haspopup="dialog">
      <span class="i-lucide-search size-4 shrink-0"></span>
      <span class="min-w-0 flex-1 truncate text-start"><%= t("super_admin.command_bar.trigger") %></span>
      <%= render "kbd", label: request.user_agent.to_s.include?("Mac") ? "⌘K" : "Ctrl K" %>
    </button>
  </div>
  <nav class="min-h-0 flex-1 overflow-y-auto px-3 pb-4 pt-3" aria-label="<%= section ? section[:label] : t("super_admin.navigation.label") %>">
    <% if section %>
      <ul class="mb-4">
        <%= render "nav_item", item: { label: t("super_admin.navigation.back"), url: super_admin_root_path, icon: "i-lucide-arrow-left" } %>
      </ul>
      <h2 class="mb-2 px-2.5 text-heading-3 text-n-slate-12"><%= section[:label] %></h2>
      <%= render "section_links", items: section[:items] %>
    <% else %>
      <%= render "section_links", items: items %>
    <% end %>
  </nav>
  <div class="shrink-0 border-t border-n-weak px-1 py-1"><%= render "account_menu", expanded: true %></div>
</aside>

<header class="sticky -top-14 z-30 border-b border-n-weak bg-n-background lg:hidden">
  <div class="flex flex-wrap items-center gap-x-3 px-[clamp(1rem,3vw,3rem)]">
    <%= brand %>
    <%= render "icon_button", extra: "ms-auto", data: { dialog_open: "command-bar" }, aria: { haspopup: "dialog", label: t("super_admin.command_bar.trigger") } do %>
      <span class="i-lucide-search size-5"></span>
    <% end %>
    <%= render "account_menu" %>

    <nav class="grid w-full auto-cols-fr grid-flow-col md:flex md:gap-0.5 md:pb-2.5" aria-label="<%= t("super_admin.navigation.label") %>">
      <% items.each do |item| %>
        <%= link_to item[:url], class: class_names(tab, "hidden sm:flex" => !item[:pinned]), aria: { current: ("page" if item[:active]) } do %>
          <span class="<%= item[:icon] %> size-5 md:hidden"></span>
          <% if item[:tab_label] %>
            <span class="md:hidden"><%= item[:tab_label] %></span>
            <span class="hidden md:inline"><%= item[:label] %></span>
          <% else %>
            <span class="max-w-full truncate"><%= item[:label] %></span>
          <% end %>
        <% end %>
      <% end %>
      <%= tag.button type: "button", class: "#{tab} sm:hidden", data: { dialog_open: "nav-more" },
                     aria: { haspopup: "dialog", current: ("page" if more_items.any? { |item| item[:active] }) } do %>
        <span class="i-lucide-ellipsis size-5"></span>
        <%= t("super_admin.navigation.more") %>
      <% end %>
    </nav>
  </div>
</header>

<%= render "sheet", id: "nav-more", title: t("super_admin.navigation.more") do %>
  <ul class="space-y-0.5">
    <%= render partial: "nav_item", collection: more_items, as: :item %>
  </ul>
<% end %>