Skip to content
Components

Mobile navigation

A floating navigation pill and an expanding stack of quick actions.

Open preview ↗

Interact with the example above, or open it in a full window.

After setting up the library, copy the example files into your app and adapt the content. These are composition references, with no block API to install or import.

Load the copied stylesheet from your application layout. Place the controller in your Stimulus controller directory and register it using your app's usual loading convention.

Choose a small set of primary destinations and replace the sample quick actions.

lc_dock keeps the safe-area spacing, reserves room at the end of the page and hides while the keyboard is open. The panel switching in this preview is the example's own controller.

The preview renders this ERB and loads these styles and interactions.

app/views/shared/_mobile_navigation.html.erb

<div class="min-h-screen" data-controller="blocks-mobile-navigation">
  <header class="mx-auto flex max-w-2xl items-center justify-between gap-4 px-5 pt-7 pb-6 sm:px-8">
    <a href="#projects" class="flex min-h-11 items-center gap-2 font-semibold" data-action="blocks-mobile-navigation#home"><%= lc_icon "square-3-stack-3d", options: { class: "size-5", "aria-hidden": true } %> Studio</a>
    <%= lc_avatar "AL", class: "bg-primary-soft text-primary", aria: { label: "Alex Lee" } %>
  </header>

  <main class="isolate mx-auto flex max-w-2xl flex-col gap-7 px-5 pt-3 sm:px-8">
    <div class="flex flex-col gap-2"><%= lc_text "A space to make things", size: :caption, tone: :muted %><h1 class="text-4xl font-semibold tracking-tight">Your little studio.</h1><p class="text-muted-foreground">A few good ideas, and room for a few more.</p></div>
    <p class="text-sm text-muted-foreground" role="status" aria-live="polite" data-blocks-mobile-navigation-target="status"></p>

    <section id="projects" class="flex flex-col gap-4" data-blocks-mobile-navigation-target="panel">
      <div class="flex min-h-11 items-center justify-between gap-3"><h2 class="text-xl font-semibold">On your desk</h2><%= lc_badge "This week" %></div>
      <div class="flex flex-col gap-4" data-blocks-mobile-navigation-target="projects">
        <% [ [ "Brand refresh", "Finding a fresh perspective.", "swatch", :primary, "In progress" ], [ "Field notes", "Small observations, collected.", "book-open", :success, "Taking shape" ], [ "Summer collection", "Objects for everyday moments.", "sun", :neutral, "Just getting started" ] ].each do |title, description, icon, tone, status| %>
          <%= lc_card class: "flex flex-col gap-content" do %>
            <div class="flex items-center justify-between gap-3"><%= lc_icon_badge shape: :circle, icon: icon, size: :lg, tone: tone%><%= lc_badge status %></div>
            <div class="flex flex-col gap-1"><h3 class="text-lg font-semibold"><%= title %></h3><p class="text-sm text-muted-foreground"><%= description %></p></div>
            <div class="flex items-center gap-2 text-sm text-muted-foreground"><%= lc_avatar "AL", size: :sm, class: "bg-background text-muted-foreground" %><span>You and your collaborators</span></div>
          <% end %>
        <% end %>
      </div>
    </section>

    <section id="notes" class="flex flex-col gap-4" data-blocks-mobile-navigation-target="panel" hidden>
      <h2 class="text-xl font-semibold">Notes to self</h2>
      <div class="flex flex-col gap-4" data-blocks-mobile-navigation-target="notes">
        <%= lc_card class: "flex flex-col gap-3" do %><%= lc_text "A thought for today", size: :caption, tone: :muted %><h3 class="text-lg font-semibold">Leave a little room.</h3><p class="text-sm text-muted-foreground">The best ideas sometimes arrive between the things you planned.</p><% end %>
      </div>
      <%= lc_field label: "Capture a thought", id: "studio-thought", hint: "A small idea is a good place to start." do |field| %><%= lc_textarea name: "thought", placeholder: "What’s on your mind?", rows: 4, **field %><% end %>
    </section>

    <section id="people" class="flex flex-col gap-4" data-blocks-mobile-navigation-target="panel" hidden>
      <h2 class="text-xl font-semibold">Good company</h2>
      <%= lc_card class: "flex flex-col gap-content" do %>
        <% [ [ "AL", "Alex Lee", "Designer" ], [ "SK", "Sam Kim", "Writer" ], [ "JR", "Jamie Reed", "Maker" ] ].each do |initials, name, role| %>
          <div class="flex items-center gap-3"><%= lc_avatar initials, class: "bg-background text-muted-foreground" %><div class="flex-1"><h3 class="text-sm font-semibold"><%= name %></h3><p class="text-sm text-muted-foreground"><%= role %></p></div><%= lc_badge "Available", tone: :primary, class: "rounded-full text-sm" %></div>
        <% end %>
      <% end %>
    </section>
  </main>

  <%= lc_dock do |dock| %>
    <%= dock.nav label: "Studio sections" do |nav| %>
      <% [ [ "Projects", "projects", "rectangle-stack" ], [ "Notes", "notes", "document-text" ], [ "People", "people", "users" ] ].each do |label, id, icon| %>
        <%= nav.link label, "##{id}", icon:, current: id == "projects", data: { action: "blocks-mobile-navigation#select" } %>
      <% end %>
    <% end %>
    <%= dock.menu label: "Create something", id: "studio-create-menu" do |menu| %>
      <%= menu.action "New project", icon: "rectangle-stack", data: { action: "blocks-mobile-navigation#add", blocks_mobile_navigation_destination_param: "projects" } %>
      <%= menu.action "Add a note", icon: "pencil-square", data: { action: "blocks-mobile-navigation#add", blocks_mobile_navigation_destination_param: "notes" } %>
    <% end %>
  <% end %>

  <template data-blocks-mobile-navigation-target="draft">
    <%= lc_card class: "flex flex-col gap-3" do %><%= lc_badge "Draft" %><h3 class="text-lg font-semibold" data-draft-title></h3><p class="text-sm text-muted-foreground">A fresh start. Make it your own.</p><% end %>
  </template>
</div>

app/javascript/controllers/blocks_mobile_navigation_controller.js

import { Controller } from "@hotwired/stimulus"

// The preview's sections are panels on one page, so the dock's links switch panels instead of visiting pages.
export default class extends Controller {
  static targets = ["panel", "status", "projects", "notes", "draft"]

  select(event) {
    event.preventDefault()
    this.show(event.currentTarget.hash.slice(1))
  }

  home(event) {
    event.preventDefault()
    this.open("projects")
  }

  // Clicking the dock link moves its indicator and shows the panel.
  open(id) {
    this.element.querySelector(`[data-slot=dock] a[href="#${id}"]`)?.click()
  }

  show(id) {
    for (const panel of this.panelTargets) panel.hidden = panel.id !== id
  }

  add({ params: { destination } }) {
    const draft = this.draftTarget.content.cloneNode(true)
    const title = destination === "projects" ? "Untitled project" : "A new thought"
    draft.querySelector("[data-draft-title]").textContent = title
    const list = destination === "projects" ? this.projectsTarget : this.notesTarget
    list.prepend(draft)
    this.open(destination)
    this.statusTarget.textContent = `${title} added. Your next idea starts here.`
  }
}
← All blocks