Account Menu

Switch accounts and workspaces, and reach settings and sign-out.

Signed in as Maya Chen.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/account-menu

Usage

import { AccountMenu } from "./ui/uicontext/components/kit/AccountMenu.ts"
const Message = UiSchema.TaggedEnum({ RequestedSwitchWorkspace: { id: Schema.String }, RequestedSignOut: {} })export const Account = (h: Html.H<typeof Message.Type>) =>	AccountMenu(h, {		props: {			person: { id: "maya", name: "Maya Chen", kind: "person", email: "[email protected]" },			workspace: { id: "northwind", name: "Northwind Freight" },			workspaces: [				{ id: "northwind", name: "Northwind Freight" },				{ id: "halcyon", name: "Halcyon Health" },			],		},		onEmit: {			RequestedWorkspace: ({ id }) => Message.RequestedSwitchWorkspace({ id }),			RequestedItem: () => undefined,			RequestedSignOut: () => Message.RequestedSignOut(),		},	})

Examples

One person, no workspaces

Without workspace, the button shows the person, and the menu has no Workspaces group.

API reference

Props

AccountMenu props
NameTypeDescription
personrequired{ email }Who is signed in: an Actor, with the email shown under their name
workspaceAccountWorkspaceThe workspace shown on the button; without one, the button shows the person
workspacesAccountWorkspace[]Others to switch to; listed with the current one when there are any
itemsAccountMenuItem[]More entries between the workspaces and Sign out, such as Settings or Help
signOutbooleanFalse hides Sign out (a demo, a kiosk)
agentIdstringThis menu's id for agents, unique on the page

Events

AccountMenu events
EventPayloadDescription
RequestedItem{ id: string }One of items was chosen: the app goes there
RequestedWorkspace{ id: string }Another workspace was chosen: the app switches to it
RequestedSignOut{}Sign out was chosen: the app signs the person out

Agent actions

What agents can do with AccountMenu
ActionDescription
ClickedItemChoose one of the account menu's items by id (Settings, Members…)
ClickedWorkspaceSwitch to another workspace by id

Accessibility

  • A button named for the workspace or person opens a menu: the arrow keys move, Enter picks, and Escape closes with focus back on the button.
  • Workspaces are a radio group, so the current one reads as checked. Items with an href are real links.
  • Agents can choose an item or switch workspace, but signing out is left to the person.

Source