Switch accounts and workspaces, and reach settings and sign-out.
Installation
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
| Name | Type | Description |
|---|---|---|
personrequired | { email } | Who is signed in: an Actor, with the email shown under their name |
workspace | AccountWorkspace | The workspace shown on the button; without one, the button shows the person |
workspaces | AccountWorkspace[] | Others to switch to; listed with the current one when there are any |
items | AccountMenuItem[] | More entries between the workspaces and Sign out, such as Settings or Help |
signOut | boolean | False hides Sign out (a demo, a kiosk) |
agentId | string | This menu's id for agents, unique on the page |
Events
| Event | Payload | Description |
|---|---|---|
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
| Action | Description |
|---|---|
ClickedItem | Choose one of the account menu's items by id (Settings, Members…) |
ClickedWorkspace | Switch 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
hrefare real links. - Agents can choose an item or switch workspace, but signing out is left to the person.