Account menu
Avatar-triggered popover with signed-in identity, account links, and a slot for actions such as signing out.
pnpm dlx shadcn@latest add @haze/account-menu---
import { ChevronsUpDown, UserRound } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Avatar from "./avatar.astro";
import DropdownMenu from "./dropdown-menu.astro";
interface AccountLink { label: string; href: string; icon?: (props: Record<string, unknown>) => unknown }
interface Props {
id: string;
name: string;
identifier?: string;
avatarSrc?: string;
items: AccountLink[];
compact?: boolean;
label?: string;
align?: "start" | "end";
side?: "bottom" | "top";
class?: string;
}
const { id, name, identifier, avatarSrc, items, compact = false, label = "Account menu", align = "end", side = "bottom", class: className } = Astro.props;
---
<div class={cn("inline-block max-w-full", className)}>
<DropdownMenu id={id} items={items} ariaLabel={`${name}, ${label}`} align={align} side={side} variant="ghost" class="w-60">
<Fragment slot="trigger">
{avatarSrc
? <span aria-hidden="true"><Avatar name={name} src={avatarSrc} size="sm" /></span>
: <span class="grid size-6 shrink-0 place-items-center rounded-full border border-frame bg-muted text-muted-foreground" aria-hidden="true"><UserRound /></span>}
{!compact && <span class="max-w-36 truncate text-[0.8125rem]/5">{name}</span>}
<ChevronsUpDown aria-hidden="true" class="text-muted-foreground" />
</Fragment>
<div slot="header" class="mb-1 flex min-w-0 items-center gap-2.5 border-b border-border px-3 py-2.5">
<span aria-hidden="true"><Avatar name={name} src={avatarSrc} /></span>
<div class="min-w-0 wrap-anywhere">
<p class="text-[0.8125rem]/5 font-medium">{name}</p>
{identifier && <p class="text-[0.8125rem]/5 text-muted-foreground">{identifier}</p>}
</div>
</div>
{Astro.slots.has("actions") && <div slot="actions" class="mt-1 border-t border-border pt-1"><slot name="actions" /></div>}
</DropdownMenu>
</div>When to use
- A shell needs one place for personal settings and help links
- A narrow toolbar needs a compact avatar trigger with an accessible name
When not to use
- The menu controls an item unrelated to the current account. Use dropdown-menu.
Installation
Add the Haze registry to components.json once, then install Account menu with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/account-menunpx shadcn@latest add @haze/account-menuyarn dlx shadcn@latest add @haze/account-menubunx --bun shadcn@latest add @haze/account-menuFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique popover ID and CSS anchor name. |
| name* | string | – | Display name for the account and source of initials. |
| identifier | string | – | Optional account detail, such as an email address or handle. |
| avatarSrc | string | – | Optional avatar image URL. Without an image, the trigger shows an account icon and the panel shows initials. |
| items* | { label: string; href: string; icon?: AstroComponent }[] | – | Links to account-related destinations. |
| compact | boolean | false | Hide the name in the trigger while keeping it inside the popover. |
| label | string | "Account menu" | Localized description announced after the account holder's name. |
| align | "start" | "end" | "end" | Edge of the trigger to align with the popover. |
| side | "bottom" | "top" | "bottom" | Preferred placement. Use top for a sidebar footer. |
| class | string | – | Additional classes on the wrapper. |
Keyboard interactions
- EnterSpace
- Toggle the account popover.
- Tab
- Focus links and any supplied actions.
- Arrow keysHomeEndLetters
- Move among the account links or jump to one by name.
- Escape
- Close the popover.
Accessibility
- The trigger has a textual accessible name even in compact mode.
- Account links are native anchors and the popover preserves standard tab order.
- The actions slot can hold your application's authenticated sign-out form.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Account menu" with `npx shadcn@latest add @haze/account-menu`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AccountMenu from "@/components/haze/ui/account-menu.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/account-menu.md
Customize with real content
Adapt the Haze account-menu ui for our product. Replace the demo values of these props with our real content: id, name, identifier, avatarSrc, items, compact, label, align, side, class. Keep the layout, the heading level rules and these accessibility details: The trigger has a textual accessible name even in compact mode. Account links are native anchors and the popover preserves standard tab order. The actions slot can hold your application's authenticated sign-out form. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using account-menu, check it fits: use it when a shell needs one place for personal settings and help links; a narrow toolbar needs a compact avatar trigger with an accessible name. Avoid it when the menu controls an item unrelated to the current account. use dropdown-menu.. Alternatives: @haze/dropdown-menu, @haze/popover, @haze/sidebar, @haze/avatar.
Dependencies
- npm: @lucide/astro
- @haze/avatar
- @haze/dropdown-menu
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.