User Menu
Who is signed in, at the foot of a sidebar: a small picture and their name, opening a menu headed by them and their plan, with usage, invites, settings, help and logging out. Signed out, it's a Sign in button that opens the login form.
Installation
npx shadcn@latest add "@aiellie/user-menu"shadcn needs the @aiellie registry in components.json first. npx aiellie add user-menu adds it on its first run, then installs the same way.
User menu is the row at the foot of a sidebar with the person's avatar and name, and the account menu it opens: usage, inviting a friend, settings, help and logging out. Settings opens the Settings dialog, which comes with it, so the row works on its own. With no one signed in, the row is a Sign in button that opens the Login form in a dialog.
Getting started
Put it in the sidebar's footer
It is a
SidebarMenu, so it goes inside aSidebarunder aSidebarProvider. Pass who is signed in asuser.components/app-sidebar.tsx"use client" import { UserMenu } from "@/components/ui/user-menu" import { Sidebar, SidebarContent, SidebarFooter, } from "@/components/ui/sidebar" export function AppSidebar() { return ( <Sidebar> <SidebarContent>{/* chats */}</SidebarContent> <SidebarFooter> <UserMenu user={{ name: "Ada Lovelace", email: "ada@example.com", plan: "Pro" }} usage="72% left" onUsage={() => {}} onInvite={() => {}} onLogOut={() => signOut()} /> </SidebarFooter> </Sidebar> ) }Save what settings change
settingsis what the dialog starts from each time it opens, andonSettingsSavegets everything in it when saved.<UserMenu user={user} settings={{ theme, providers, providerKeys }} onSettingsSave={(values) => saveSettings(values)} />
Anatomy
<ul data-slot="user-menu"> {/* SidebarMenu */}
<li>
<button data-slot="sidebar-menu-button"> {/* the menu's trigger */}
<span data-slot="avatar" /> {/* their picture, or their initials */}
<span>{user.name}</span>
</button>
</li>
</ul>
<div data-slot="menu-content"> {/* as wide as the row, opening upward */}
<div>{/* avatar, name, plan badge */}</div>
<div data-slot="menu-separator" />
<div data-slot="menu-item" /> {/* Usage, with `usage` at its end */}
<div data-slot="menu-item" /> {/* Invite a friend */}
<div data-slot="menu-item" /> {/* Settings, opening the dialog */}
<div data-slot="menu-item" /> {/* Help */}
<div data-slot="menu-separator" />
<div data-slot="menu-item" /> {/* Log out */}
</div>
<div data-slot="dialog-content" /> {/* SettingsDialog */}The row keeps its sidebar-accent fill while the menu is open. The menu opens upward at the row's width, and repeats the name with the plan as a badge, so the account is named where its actions are. Without an avatar, the first letters of the first two words of the name stand in.
Examples
Signed out
Leave out user and the row offers to sign in. onSignIn gets the email to send a code to; return a promise and the dialog stays open, its button working, until it settles. A rejection's message shows in the form. Log out to see it again.
Settings that save
Change the name in Settings and save: onSettingsSave passes it back and the row follows.
Open settings from somewhere else
Control the dialog with settingsOpen and onSettingsOpenChange, so a shortcut or another button can open it too.
const [settingsOpen, setSettingsOpen] = React.useState(false)
<UserMenu
user={user}
settingsOpen={settingsOpen}
onSettingsOpenChange={setSettingsOpen}
/>API reference
UserMenu
| Prop | Type | Default | Description |
|---|---|---|---|
user | User | Who is signed in. Without one, the row is a Sign in button. | |
usage | string | How much of their plan is left, like 72% left, shown at the end of Usage. | |
onUsage | () => void | Runs when Usage is chosen. | |
onInvite | () => void | Runs when Invite a friend is chosen. | |
onSettings | () => void | Runs when Settings is chosen, as the dialog opens. | |
settings | { theme, apiKeys, providers, providerKeys, defaultSection } | What the settings dialog starts from each time it opens. | |
onSettingsSave | (values: SettingsValues) => void | Called with the dialog's values when saved. | |
settingsOpen / onSettingsOpenChange | boolean / (open: boolean) => void | Controls the settings dialog. | |
onHelp | () => void | Runs when Help is chosen. | |
onLogOut | () => void | Runs when Log out is chosen. | |
onSignIn | (values: { email: string }) => void | Promise<void> | Called with the email from the login form, to send it a code. The dialog closes once it resolves. | |
login | { providers, onProvider, emailDescription, title, description } | Passed on to the login dialog. |
User
| Field | Type | Description |
|---|---|---|
name | string | Shown in the row and the menu, and the source of the initials. |
email | string | Filled into the settings dialog. |
avatar | string | A picture of them. Without one, their initials stand in. |
plan | string | The plan they are on, like Pro, badged beside their name. |