Overlays
Account menu
The avatar at the end of a top bar. It opens a menu with who's signed in, the organizations they can switch between, your own items and signing out, so organization switching doesn't need a control of its own.
Installation
npx sinaui add account-menuCopy src/lib/ui/AccountMenu.svelte with Avatar, Icon, Dropdown and tokens.css. Needs @hugeicons/core-free-icons.
Examples
With organizations
Open it, switch between three libraries, or add a new one. Account settings is an item passed in as children.
<script lang="ts">
import { Settings01Icon } from '@hugeicons/core-free-icons';
import AccountMenu from '#lib/ui/AccountMenu.svelte';
import Icon from '#lib/ui/Icon.svelte';
import * as Dropdown from '#lib/ui/dropdown/index.js';
import { toast } from '#lib/ui/toast/index.js';
const orgs = [
{ id: 'baghdad', name: 'House of Wisdom, Baghdad' },
{ id: 'cordoba', name: 'Library of Córdoba' },
{ id: 'fez', name: 'Al-Qarawiyyin, Fez' }
];
let org = $state('baghdad');
</script>
<AccountMenu
user={{ name: 'Fatima al-Fihri', email: 'fatima@qarawiyyin.example' }}
{orgs}
{org}
onorg={(o) => {
org = o.id;
toast(`Switched to ${o.name}.`);
}}
onneworg={() => toast('A new organization would be created here.')}
onsignout={() => toast('Signed out.')}
theme
>
<Dropdown.Item onselect={() => toast('Account settings would open here.')}>
<Icon icon={Settings01Icon} /> Account settings
</Dropdown.Item>
</AccountMenu>Props
| Prop | Type | Default |
|---|---|---|
user | { name, email?, image? } (required) | |
orgs | { id, name }[] | [] |
org | string: the current organization, ticked | |
onorg | (org) => void | |
onneworg | () => void: shows “New organization” | |
children | Snippet: your own Dropdown items | |
onsignout | () => void: shows “Sign out” | |
theme | boolean: a light/dark switch under the name | false |
labels | { account, organizations, newOrg, signOut, darkTheme, lightTheme } | English |
Accessibility
- The button is named “Account: ” and the person's name, and opens a menu like Dropdown.
- The current organization is marked with
aria-currentas well as the tick. - The name, email and section title are plain text in the menu, never focus stops.