CwProfileMenu

User avatar with dropdown menu. Shows name, role, and action items.

With initials (no avatar image)

CwProfileMenu example Copy code
{#snippet refreshIcon()}
  <svg viewBox="0 0 16 16" fill="none" aria-hidden="true">
    <path d="M13 8a5 5 0 1 1-1.28-3.36" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
    <path d="M13 3.5v3.2H9.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
  </svg>
{/snippet}

<CwProfileMenu
	name="kevin@cropwatch.io"
	subtitle="Administrator"
	icon={refreshIcon}
	{menuItems}
	onselect={(item) => console.log(item.id)}
/>

With avatar image

Compact (no subtitle)

In a toolbar

CropWatch
Documentation Upgrade

Start here

CwProfileMenu combines a user trigger, optional avatar, and action menu. The menu stays simple: you pass the items and react to whichever item the user picks.

How to think about it

  1. Always provide a name The name is used for visible identity and for initials when there is no avatar image.
  2. Model actions as plain data Build `menuItems` as an array of ids and labels, then switch on `item.id` inside `onselect`.
  3. Customize the trigger only when necessary Most apps only need `avatarUrl` or initials. Use `icon` or `avatar` snippets for more custom branding.

Props and callbacks

APITypeDetails
name Required
stringVisible user name or identifier.
subtitle
stringSecondary role or account text.
avatarUrl
stringImage URL for the avatar. Falls back to initials when omitted.
menuItems

Default: []

CwProfileMenuItem[]Menu actions shown when the trigger opens.
onselect
(item: CwProfileMenuItem) => voidCalled when a menu item is chosen.
icon
SnippetOptional custom icon rendered in the trigger.
avatar
SnippetCustom avatar markup. Overrides initials and `avatarUrl`.

Copy-paste examples

These snippets intentionally show the full public API surface the live demo relies on.

Standard profile menu

Use `onselect` to branch on the selected item id.

Standard profile menu Copy code
<script lang="ts">
	const menuItems = [
		{ id: 'profile', label: 'My profile' },
		{ id: 'settings', label: 'Account settings' },
		{ id: 'signout', label: 'Sign out', separator: true, danger: true }
	];
</script>

<CwProfileMenu
	name="kevin@cropwatch.io"
	subtitle="Administrator"
	menuItems={menuItems}
	onselect={(item) => {
		if (item.id === 'signout') signOut();
	}}
/>
Custom avatar and trigger icon

Use snippets when the default initials or avatar image are not enough.

Custom avatar and trigger icon Copy code
<CwProfileMenu name="North greenhouse" menuItems={menuItems}>
	{#snippet avatar()}
		<div style="width:100%;height:100%;display:grid;place-items:center;background:#0f766e;color:white;font-weight:700">
			NG
		</div>
	{/snippet}
	{#snippet icon()}
		<svg viewBox="0 0 16 16" fill="none" style="width:1rem;height:1rem">
			<path d="M4 6l4 4 4-4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
		</svg>
	{/snippet}
</CwProfileMenu>