# 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.

Account card with two accounts

[Complete TSX file](/examples/account-card/default.tsx)

```tsx
"use client";

import {
  BookOpenIcon,
  GearIcon,
  UserIcon,
} from "@phosphor-icons/react/dist/ssr";
import { useState } from "react";
import {
  AccountCard,
  type AccountCardAccount,
  type AccountCardAction,
} from "@/siteplane/components/account-card";

const accounts: AccountCardAccount[] = [
  {
    email: "mara@example.com",
    id: "mara",
    initials: "ME",
    name: "Mara Ellis",
    src: "https://ui.siteplane.io/avatars/mara.webp",
    status: "online",
  },
  {
    email: "jonas@northlight.studio",
    id: "jonas",
    initials: "JK",
    name: "Jonas Kramer",
    src: "https://ui.siteplane.io/avatars/jonas.webp",
  },
];

// Rows with an href are links; the others call their onClick. Shortcuts are
// labels only: connect the keys in your application.
const items: AccountCardAction[] = [
  {
    href: "#profile",
    icon: <UserIcon aria-hidden="true" />,
    label: "View profile",
    shortcut: "⌘P",
  },
  {
    href: "#settings",
    icon: <GearIcon aria-hidden="true" />,
    label: "Account settings",
    shortcut: "⌘,",
  },
  {
    href: "#docs",
    icon: <BookOpenIcon aria-hidden="true" />,
    label: "Documentation",
  },
];

export default function Example() {
  const [accountId, setAccountId] = useState("mara");
  return (
    <div className="w-full max-w-60">
      {/* The whole row is the button that opens the menu. */}
      <AccountCard
        accountId={accountId}
        accounts={accounts}
        items={items}
        onAccountChange={setAccountId}
        onAddAccount={() => undefined}
        onSignOut={() => undefined}
      />
    </div>
  );
}
```

## Installation

Complete [one-time setup](/docs/installation/) first.

```bash
pnpm dlx shadcn@4.18.0 add @siteplane/account-card
```

With npm: `npx shadcn@4.18.0 add @siteplane/account-card`. [Registry JSON](/registry/account-card.json) lists source files and dependencies.

## Usage

```tsx
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](/docs/components/sidebar/), its [two-line row](/docs/components/sidebar/#two-line-rows): 48 px high, a 32 px [Avatar](/docs/components/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](/docs/components/menu/#trigger-chevron): 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](/docs/components/menu/) that holds, in this order:

```text
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 out
```

Every 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](/docs/components/avatar-label-group/) at `md`, the [Menu](/docs/components/menu/#header-and-footer) 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](/docs/components/avatar/#size-and-shape) 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](/docs/components/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](#avatar-trigger). Outside a Sidebar the row keeps its look and opens the menu beside it.

Account card at the foot of a sidebar

[Complete TSX file](/examples/account-card/sidebar.tsx)

```tsx
"use client";

import type { Icon as PhosphorIcon } from "@phosphor-icons/react";
import {
  ChartBarIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  UserIcon,
} from "@phosphor-icons/react/dist/ssr";
import { useState } from "react";
import {
  AccountCard,
  type AccountCardAccount,
} from "@/siteplane/components/account-card";
import {
  Sidebar,
  SidebarBrand,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarHeader,
  SidebarInset,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
} from "@/siteplane/components/sidebar";

const pages: { label: string; icon: PhosphorIcon }[] = [
  { label: "Home", icon: HouseIcon },
  { label: "Projects", icon: FolderIcon },
  { label: "Reports", icon: ChartBarIcon },
];

const accounts: AccountCardAccount[] = [
  {
    email: "mara@example.com",
    id: "mara",
    initials: "ME",
    name: "Mara Ellis",
    src: "https://ui.siteplane.io/avatars/mara.webp",
  },
  {
    email: "mara@northlight.studio",
    id: "studio",
    initials: "NS",
    name: "Northlight Studio",
  },
];

export default function Example() {
  const [page, setPage] = useState("Home");
  const [accountId, setAccountId] = useState("mara");
  return (
    <div className="h-[32rem] w-full">
      <SidebarProvider contained keyboardShortcut={false} stateCookie={false}>
        <Sidebar>
          <SidebarHeader>
            <SidebarBrand>Northlight</SidebarBrand>
          </SidebarHeader>
          <SidebarContent>
            <SidebarGroup>
              <SidebarMenu>
                {pages.map((item) => (
                  <SidebarMenuItem key={item.label}>
                    <SidebarMenuButton
                      active={item.label === page}
                      onClick={() => setPage(item.label)}
                    >
                      <item.icon aria-hidden="true" />
                      <span>{item.label}</span>
                    </SidebarMenuButton>
                  </SidebarMenuItem>
                ))}
              </SidebarMenu>
            </SidebarGroup>
          </SidebarContent>
          {/* The account at the foot of the sidebar, as its own row. The
              row opens its menu beside the sidebar, toward the content. */}
          <SidebarFooter>
            <AccountCard
              accountId={accountId}
              accounts={accounts}
              items={[
                {
                  href: "#profile",
                  icon: <UserIcon aria-hidden="true" />,
                  label: "View profile",
                },
                {
                  href: "#settings",
                  icon: <GearIcon aria-hidden="true" />,
                  label: "Account settings",
                },
              ]}
              onAccountChange={setAccountId}
              onSignOut={() => undefined}
            />
          </SidebarFooter>
        </Sidebar>
        <SidebarInset>
          <header className="flex items-center gap-2 border-b p-3">
            <h1 className="font-semibold">{page}</h1>
          </header>
          <div className="p-4 text-sm">Your workspace content.</div>
        </SidebarInset>
      </SidebarProvider>
    </div>
  );
}
```

## Card trigger

`trigger="card"` shows the account in a [Card](/docs/components/card/) with 12 px inside its edge, as an [Avatar Label Group](/docs/components/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](/docs/components/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.

```tsx
<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](/docs/patterns/header-navigation/#account-menu) 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.

Avatar trigger at the foot of a slim sidebar

[Complete TSX file](/examples/account-card/avatar.tsx)

```tsx
"use client";

import type { Icon as PhosphorIcon } from "@phosphor-icons/react";
import {
  ChartBarIcon,
  FolderIcon,
  GearIcon,
  HouseIcon,
  UserIcon,
} from "@phosphor-icons/react/dist/ssr";
import { useState } from "react";
import {
  AccountCard,
  type AccountCardAccount,
} from "@/siteplane/components/account-card";
import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarInset,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
} from "@/siteplane/components/sidebar";

const pages: { label: string; icon: PhosphorIcon }[] = [
  { label: "Home", icon: HouseIcon },
  { label: "Projects", icon: FolderIcon },
  { label: "Reports", icon: ChartBarIcon },
];

const accounts: AccountCardAccount[] = [
  {
    email: "mara@example.com",
    id: "mara",
    initials: "ME",
    name: "Mara Ellis",
    src: "https://ui.siteplane.io/avatars/mara.webp",
    status: "online",
  },
];

export default function Example() {
  const [page, setPage] = useState("Home");
  return (
    <div className="h-[32rem] w-full">
      {/* A slim sidebar: the collapsed floating icon rail. */}
      <SidebarProvider
        contained
        defaultOpen={false}
        keyboardShortcut={false}
        stateCookie={false}
      >
        <Sidebar collapsible="icon" variant="floating">
          <SidebarContent>
            <SidebarGroup>
              <SidebarMenu>
                {pages.map((item) => (
                  <SidebarMenuItem key={item.label}>
                    <SidebarMenuButton
                      active={item.label === page}
                      onClick={() => setPage(item.label)}
                      tooltip={item.label}
                    >
                      <item.icon aria-hidden="true" />
                      <span>{item.label}</span>
                    </SidebarMenuButton>
                  </SidebarMenuItem>
                ))}
              </SidebarMenu>
            </SidebarGroup>
          </SidebarContent>
          {/* The avatar alone, for the rail. Its menu opens with the
              account's avatar, name and email, as from the row. */}
          <SidebarFooter>
            <AccountCard
              accounts={accounts}
              items={[
                {
                  href: "#profile",
                  icon: <UserIcon aria-hidden="true" />,
                  label: "View profile",
                },
                {
                  href: "#settings",
                  icon: <GearIcon aria-hidden="true" />,
                  label: "Account settings",
                },
              ]}
              onSignOut={() => undefined}
              trigger="avatar"
            />
          </SidebarFooter>
        </Sidebar>
        <SidebarInset>
          <header className="flex items-center gap-2 border-b p-3">
            <h1 className="font-semibold">{page}</h1>
          </header>
          <div className="p-4 text-sm">Your workspace content.</div>
        </SidebarInset>
      </SidebarProvider>
    </div>
  );
}
```

## 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](/docs/components/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 |
| --- | --- | --- | --- |
| AccountCard.accounts | 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. |
| AccountCard.accountId | string | the first account | The id of the current account. |
| AccountCard.onAccountChange | (id: string) => void | unset | Called with the id of the account picked in the menu. |
| AccountCard.items | readonly AccountCardAction[] | [] | The action rows of the menu, after its header, such as View profile. |
| AccountCard.accountsLabel | string | Switch account | The label above the account list, and the name of its group. |
| AccountCard.onAddAccount | () => void | unset | Shows the Add account row under the account list and is called by it. |
| AccountCard.addAccountLabel | string | Add account | The label of the add row. |
| AccountCard.onSignOut | () => void | unset | Shows the Sign out row at the end of the menu and is called by it. |
| AccountCard.signOutLabel | string | Sign out | The label of the sign out row. |
| AccountCard.label | 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. |
| AccountCard.trigger | "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. |
| AccountCardAccount | { 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. |
| AccountCardAction | { 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](/docs/components/menu/) parts, such as `menu-popup`,
`menu-header`, `menu-radio-item` and `menu-separator`. The types
`AccountCardAccount` and `AccountCardAction` are exported.

[Read the installed source](/source/account-card).

## 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](/docs/patterns/header-navigation/#account-menu), which opens this same menu, or a [Menu](/docs/components/menu/) with an avatar trigger. The texts of the menu are the `accountCard` group of the [messages](/docs/customization/localization/#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`.
