LedgerUI.Components.Navbar (LedgerUI v0.2.0)

Copy Markdown View Source

The app top bar: a container (navbar/1) and small pieces to put in it. The right side keeps the same vocabulary (search, notifications, theme, language and the user); the variants change what goes on the left and the visual weight.

<.navbar>
  <.navbar_crumbs items={[%{label: "Início", navigate: ~p"/"}, %{label: "Site novo"}]} />
  <:end>
    <.navbar_search placeholder="Buscar…" phx-click={JS.exec("data-show", to: "#palette")} />
    <.navbar_bell dot />
    <.theme_switch id="theme" variant="icons" size="sm" />
    <.navbar_user id="me" user={@user}>
      <:menu>
        <.navbar_menu_head user={@user} />
        <.navbar_menu_item icon="user" navigate={~p"/perfil"}>Perfil</.navbar_menu_item>
        <.navbar_menu_item icon="logout" danger href={~p"/sair"} method="delete">Sair</.navbar_menu_item>
      </:menu>
    </.navbar_user>
  </:end>
</.navbar>

variant: "default" (64px, a line under it), "float" (a detached raised bar), "clear" (transparent, over a hero), "dense" (48px) or "mobile" (56px). size="sm" is 52px. Slots: inner_block (the left side), :center, :end (the right side) and :tabs, which makes the bar two rows (the tabs row under the content).

The slots are rendered straight inside <header class="lu-topbar"> (flex row), so the items are its direct children and the crumbs take the free space.

Summary

Functions

The people on the page, as overlapping avatars; the rest is a +N bubble.

The notifications button; dot shows the dot of something unread.

The logo and the name of the app.

A selector in a path of selectors (organization, project). phx-click opens the list.

The path to the page. Each item is %{label: "...", navigate: path} (or href / patch); the last one, the page itself, is the current one, and an item with no link is plain text.

The environment pill (Produção, Homologação); tone is ok (green) or warn (amber).

An icon button of the bar (search on a small screen, help, the menu of the mobile bar).

The language switcher: a small segmented group. locales is a list of codes (["PT", "EN"], with current) or of maps %{code:, navigate:, active:, click:, label:}.

The main links, centered. Items are %{label:, navigate:, active:} (href / patch work too). The active one is the item with active: true or the one whose link equals current.

The head of the user menu: the avatar, the name and the email, and a :badge (the role) at the end.

An item of the menu: a link (navigate, href, patch, with method="delete" for a sign-out) or, with only phx-click, an action.

A row of the menu with a label and a control at the end (theme_switch/1, navbar_lang/1).

The status line of the menu: a green dot, the label and an :action at the end.

The search field of the bar. It is a trigger, not an input: with phx-click it becomes a button (role and tabindex) that opens the command palette.

The thin vertical line between the icons and the user.

The / between two selectors.

The save state: a green check and a muted text (Salvo há 2 min).

The tabs of the page, for the :tabs slot of navbar/1. Items are those of navbar_links/1 plus an optional count.

The centered title of the mobile bar.

The user of the bar: the avatar, with a status ring ("ring") or with the name ("named"). Without the :menu slot it is a plain avatar (a button when it has phx-click). With it, the button opens a raised panel (role="menu", hidden at first; id is required) toggled with Phoenix.LiveView.JS: a click outside closes it.

The workspace switcher: logo, name, a line under it and a chevron. phx-click opens your menu.

Functions