Skip to Content

Mobile Menu

Mobile menu for a site header: a menu button that opens a sheet with the navigation links and the header's primary and secondary actions. Closes on a link pick and when the window widens past the button; the caller sets the breakpoint that hides it and can make the panel dark.

Installation

pnpm dlx shadcn@latest add @01orbital/mobile-menu

Usage

import { CircleIcon } from "@phosphor-icons/react/ssr"

import { MobileMenu } from "@/components/mobile-menu/mobile-menu"

// Every word on the page. Change copy here, not in the markup.
const COPY = {
  brand: "Orbcore",
} as const

const LINKS = [
  { label: "Product", href: "#" },
  { label: "Pricing", href: "#" },
  { label: "Changelog", href: "#" },
] as const

const ACTION = { label: "Sign up", href: "#" } as const
const SECONDARY_ACTION = { label: "Log in", href: "#" } as const

export default function MobileMenuDemo() {
  return (
    <header className="flex w-full max-w-sm items-center justify-between gap-4 rounded-xl border px-4 py-2">
      <span className="flex items-center gap-2 font-medium">
        <CircleIcon weight="light" aria-hidden="true" className="size-5" />
        {COPY.brand}
      </span>
      <MobileMenu
        links={LINKS}
        action={ACTION}
        secondaryAction={SECONDARY_ACTION}
      />
    </header>
  )
}

This example installs with everything it uses:

pnpm dlx shadcn@latest add @01orbital/mobile-menu-demo

API reference

A header's menu for narrow screens: a menu button that opens a Sheet with the navigation links and the header's actions. Picking a link closes it, and so does widening the window until the button hides. The caller hides the button where its desktop links show (className="lg:hidden") and can theme the panel (contentClassName="dark").

Prop

Type

Dependencies

npm: @phosphor-icons/react, cn. The CLI installs them for you.

Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:

The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.

Used in blocks

2 blocks are built with Mobile Menu:

Last updated on