Account Card
Show the signed-in account in a sidebar and open a menu with its actions, a list of accounts to switch to and sign out.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/account-cardComplete the one-time setup first. Registry JSON lists source files and dependencies.
Usage
import { AccountCard } from "@/siteplane/components/account-card";
<AccountCard
accounts={[{ email: "mara@example.com", id: "mara", name: "Mara Ellis" }]}
onSignOut={() => undefined}
/>;Parts
By default the account is a row of the Sidebar, its two-line row: 48 px high, a 32 px Avatar, the name in the 14 px text of the sidebar's rows over the email, 12 px in the tertiary text color, and a 16 px chevron at its end. The whole row is one button that opens the account menu. It has no card, border or shadow: it takes the hover, pressed and open fills of every sidebar row, and the kit's focus ring. The chevron is the still up-down caret of every switcher, SidebarMenuChevron with variant="switcher", which draws MenuTriggerIcon variant="switcher" of Menu: it rests in the tertiary text color and takes the primary one on hover, press and while the menu is open. trigger="card" shows the account in a card instead and trigger="avatar" the avatar alone. The menu is a Menu that holds, in this order:
AccountCard
├── trigger → one button
│ ├── row (default): avatar, name over email, chevron
│ ├── card: AvatarLabelGroup in a Card, chevron
│ └── avatar: the avatar alone
└── menu
├── header: the account's avatar, name and email
├── items: action rows with an icon, a label and a shortcut
├── separator
├── Switch account: a row per account, the current one checked
├── Add account
├── separator
└── Sign outEvery trigger opens the menu with a header band that shows whose menu it is: the account's avatar, name and email as an Avatar Label Group at md, the Menu header with a hairline under it. Each other part of the menu shows only when it has something to show: the action rows with items, the account list with more than one account, Add account with onAddAccount and Sign out with onSignOut. A separator stands between two parts that show. The rows are the rows of the kit's menus, with their icon in the leading slot and the shortcut at the end, and the menu is as wide as its rows, and at least as wide as the row trigger. A row with href is a link, and one without calls its onClick. Shortcuts are labels only; connect the keys in your application. Sign out is the last row, with its icon and without a shortcut.
Switching accounts
accounts lists the accounts and accountId names the current one, the first of accounts when none matches. The current account fills the trigger and the menu's header. With more than one account, the menu lists them all under accountsLabel, “Switch account” by default: each row starts with the account's avatar, 20 px in the slot of a row's icon, followed by the name, and the row of the current account ends with the kit's check. Give a company's or a workspace's account shape: "square": its avatar is then square wherever the account shows, as every company's Avatar is, and a person's stays round. Picking a row calls onAccountChange with the account's id and closes the menu; keep the current account in state and pass it back, as the examples do. onAddAccount adds the Add account row under the list.
In a sidebar
Put the account in the Sidebar's SidebarFooter. The row is then the sidebar's own row, a SidebarMenuButton in a SidebarMenu, and the menu opens beside the sidebar, toward the content, with its bottom on the row's. Below the mobile breakpoint the sidebar is a sheet, and the menu opens above the row instead, as wide as the row. On the collapsed icon rail of a sidebar with collapsible="icon", the row turns into the rail's 36 px square with a 20 px avatar, as every two-line row does, and still opens the menu beside the rail. For a slim sidebar that stays a rail, use the avatar trigger. Outside a Sidebar the row keeps its look and opens the menu beside it.
Card trigger
trigger="card" shows the account in a Card with 12 px inside its edge, as an Avatar Label Group at md: a 40 px avatar with a hairline ring beside the name and the email, both 14 px. The whole card is one button: a ghost Button covers the card and takes its corners, so its hover, pressed and open fills and its focus ring cover the whole card. The chevron is centered on the card's height, 12 px from the edge, and the text ends 8 px before it. The menu opens beside the card as from the row, with the same header.
<AccountCard
accounts={accounts}
items={items}
onSignOut={signOut}
trigger="card"
/>Avatar trigger
trigger="avatar" shows only the account's avatar, a 32 px avatar with a hairline ring in a 36 px round button, which opens the same menu. It suits the collapsed icon rail of a slim sidebar, where the row has no room. The avatar trigger of Header Navigation shows the same 32 px avatar, without the ring and the presence dot. The button shows no name, and its menu opens with the same header as from the row and the card: the account's avatar, name and email.
Accessibility
The row is one button in the tab order, and so is the card. Neither holds another control, the avatar and the chevron are hidden from assistive technology, and the button is named by the account's name followed by label, “Account menu” by default, such as “Mara Ellis, Account menu”. The card's avatar, name and email stay readable as the card's text. With trigger="avatar", label alone names the avatar button. The menu takes its name from the button that opens it, and works as every Menu does. Enter, Space and the Up and Down arrow keys on the button open it. The arrow keys move through the rows and wrap at the ends, Home and End go to the first and the last row, and typing the start of a label moves to its row. Enter or Space chooses a row, which closes the menu and returns focus to the button. Escape and a click outside close the menu too. The account list is a group named by accountsLabel, its rows are radio items, and the row of the current account is checked. The avatar in a row is hidden from assistive technology, so the account's name names the row. The menu's header is text and no row, so the arrow keys pass it by.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
Account | readonly AccountCardAccount[] | required | The accounts. The current one fills the trigger and the menu's header; with more than one, the menu lists them all. Without any, Account Card renders nothing. |
Account | string | the first account | The id of the current account. |
Account | (id: string) => void | unset | Called with the id of the account picked in the menu. |
Account | readonly AccountCardAction[] | [] | The action rows of the menu, after its header, such as View profile. |
Account | string | Switch account | The label above the account list, and the name of its group. |
Account | () => void | unset | Shows the Add account row under the account list and is called by it. |
Account | string | Add account | The label of the add row. |
Account | () => void | unset | Shows the Sign out row at the end of the menu and is called by it. |
Account | string | Sign out | The label of the sign out row. |
Account | string | Account menu | What the button that opens the menu does. It follows the account's name on the row and the card, such as “Mara Ellis, Account menu”, and names the avatar button alone; the menu takes its name from the button. |
Account | "row" | "card" | "avatar" | "row" | row shows the account as the sidebar's two-line row, one button with a 32 px avatar, the name over the email and a chevron at its end; card shows the avatar, name and email in a card that is one button; avatar shows only the avatar, as the button. Every trigger opens the menu with the account's avatar, name and email. |
Account | { id: string; name: string; email?: string; src?: string; initials?: string; shape?: AvatarShape; status?: AvatarStatus } | — | An account. email shows under the name, in the row, on the card and in the menu's header; initials show while the avatar has no image, the first letter of name without them; shape="square" draws a company's or a workspace's avatar square in the row, on the card, the avatar button, its menu row and the header band, where a person keeps the circle; status adds the presence dot of an Avatar to the current account's avatar in the row, on the card or on the avatar button. |
Account | { label: string; icon?: ReactNode; shortcut?: string; href?: string; onClick?: () => void } | — | An action row: a link with href, an action without. Give the icon aria-hidden. |
AccountCardProps extends the props of a div, except children. With
trigger="row" they reach the row's root, a div with
data-slot="account-card", and with trigger="card" the Card, each with a ref;
with trigger="avatar" only className applies, to the avatar button. The
button of the row and of the card carries data-slot="account-card-trigger".
The row's text is the Sidebar's two-line text (sidebar-menu-button-text), and
its chevron is sidebar-menu-chevron; the card's chevron is the Menu's
menu-trigger-icon with data-variant="switcher". The menu's parts carry the
slots of the Menu parts, such as menu-popup,
menu-header, menu-radio-item and menu-separator. The types
AccountCardAccount and AccountCardAction are exported.
Usage notes
Use an Account Card for the signed-in account at the foot of an application sidebar. For an account control in a header bar, use the account menu of Header Navigation, which opens this same menu, or a Menu with an avatar trigger. The texts of the menu are the accountCard group of the messages, for both.
Account Card keeps no state of its own: the current account, adding an account and signing out are your application's. The menu has no controlled open state, and choosing a row closes it, so a row that leads to another page should be a link with href.