PhiaUi.Components.Sidebar (phia_ui v0.1.17)

Copy Markdown View Source

Sidebar navigation component with brand area, scrollable nav, and pinned footer.

Provides three components:

  • sidebar/1 — collapsible 240 px aside with :default/:dark variants
  • sidebar_item/1 — navigation link with active highlight, icon, and badge
  • sidebar_section/1 — groups nav items under an uppercase section label

Example

<.sidebar variant={:default}>
  <:brand>
    <img src="/logo.svg" alt="Acme" class="h-6 w-auto" />
  </:brand>
  <:nav_items>
    <.sidebar_section label="Main Menu">
      <.sidebar_item href="/dashboard" active={@live_action == :index}>
        Dashboard
      </.sidebar_item>
    </.sidebar_section>
  </:nav_items>
  <:footer_items>
    <.sidebar_item href="/settings">Settings</.sidebar_item>
  </:footer_items>
</.sidebar>

Summary

Functions

Responsive sidebar with brand area, scrollable nav, and pinned footer.

A navigation link inside the sidebar.

Collapsible sidebar section using native <details>/<summary>.

Groups sidebar navigation items under an optional section label.

Functions

sidebar(assigns)

Responsive sidebar with brand area, scrollable nav, and pinned footer.

The sidebar is always 240 px wide (set on the CSS Grid column). On desktop it is a static grid cell with flex flex-col and border-r. On mobile the parent shell/1 component manages its visibility as an overlay.

The layout is a vertical flex container divided into three parts:

   h-14 brand area (shrink-0, border-b)
  brand slot              

                             flex-1, overflow-y-auto
  nav_items slot          
                          
   shrink-0, border-t
  footer_items slot       

Example

<.sidebar variant={:default}>
  <:brand>
    <img src="/logo.svg" alt="Acme" class="h-6 w-auto" />
  </:brand>
  <:nav_items>
    <.sidebar_item href="/dashboard" active>Dashboard</.sidebar_item>
  </:nav_items>
  <:footer_items>
    <.sidebar_item href="/settings">Settings</.sidebar_item>
  </:footer_items>
</.sidebar>

Attributes

  • id (:string) - Element ID used by mobile_sidebar_toggle/1's JS.toggle/1 call. Keep the default unless you render multiple shells on the same page.

    Defaults to "sidebar-drawer".

  • collapsed (:boolean) - When true, translates the sidebar off-screen via -translate-x-full. Useful for programmatic collapse without the mobile overlay pattern.

    Defaults to false.

  • class (:string) - Additional CSS classes. Defaults to nil.

  • variant (:atom) - Visual variant for the sidebar background.

    • :default — uses --sidebar-background and --sidebar-foreground tokens, which respect the current color theme and dark mode.
    • :dark — forces a dark background regardless of color mode. Applies dark bg-sidebar-background text-sidebar-foreground classes directly, producing the "always dark" look used by tools like Vercel or Linear.

    Defaults to :default. Must be one of :default, or :dark.

  • Global attributes are accepted. HTML attributes forwarded to the aside element.

Slots

  • brand - Logo or application name area rendered at the top of the sidebar inside a h-14 row that aligns with the topbar height. Typically holds a wordmark, icon-plus-name combo, or workspace switcher.

  • nav_items - Primary navigation items (the main middle section of the sidebar). This slot is placed in an overflow-y-auto <nav> element so that long navigation lists scroll independently of the footer. Use sidebar_section/1 and sidebar_item/1 inside this slot.

  • footer_items - Secondary items anchored to the bottom of the sidebar (above the fold). Typically holds Settings and Help links. Rendered in a shrink-0 div with a top border separating it from the primary nav.

  • inner_block - Fallback slot for fully custom sidebar content when the named slots (:brand, :nav_items, :footer_items) do not provide enough structure. Only rendered when :nav_items is empty.