{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"user-menus-avatar-dropdown","type":"registry:component","title":"User menus · Avatar dropdown","description":"Top-bar avatar menu with a workspace switcher whose check glides between rows, a light/dark/system row and shortcut hints.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/user-menus/avatar-dropdown.tsx","type":"registry:component","target":"components/examples/user-menus/avatar-dropdown.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { Check, ChevronDown, CreditCard, LogOut, Monitor, Moon, Plus, Settings, Sun, UserRound } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface MenuAccount {\n  id: string;\n  name: string;\n  plan: string;\n}\n\nexport type MenuTheme = \"light\" | \"dark\" | \"system\";\n\nexport interface AvatarDropdownProps {\n  name?: string;\n  email?: string;\n  accounts?: MenuAccount[];\n  defaultAccountId?: string;\n  defaultTheme?: MenuTheme;\n  /** Called with \"profile\", \"billing\", \"settings\", \"add-account\" or \"sign-out\". */\n  onSelect?: (action: string) => void;\n  onAccountChange?: (account: MenuAccount) => void;\n  /** Local preference only; wire it to your theme provider. */\n  onThemeChange?: (theme: MenuTheme) => void;\n  align?: \"start\" | \"end\";\n  /** Render open on mount (without moving focus), e.g. for previews. */\n  defaultOpen?: boolean;\n  className?: string;\n}\n\nconst ACCOUNTS: MenuAccount[] = [\n  { id: \"northwind\", name: \"Northwind Studio\", plan: \"Pro\" },\n  { id: \"halcyon\", name: \"Halcyon Labs\", plan: \"Team\" },\n  { id: \"personal\", name: \"Personal\", plan: \"Free\" },\n];\nconst THEMES = [\n  { id: \"light\", label: \"Light\", Icon: Sun },\n  { id: \"dark\", label: \"Dark\", Icon: Moon },\n  { id: \"system\", label: \"System\", Icon: Monitor },\n] as const;\nconst ITEMS = [\n  { id: \"profile\", label: \"Profile\", Icon: UserRound, kbd: \"⇧P\" },\n  { id: \"billing\", label: \"Billing\", Icon: CreditCard, kbd: \"⇧B\" },\n  { id: \"settings\", label: \"Settings\", Icon: Settings, kbd: \"⌘,\" },\n];\nconst spring = { type: \"spring\", stiffness: 420, damping: 32 } as const;\nconst initials = (n: string) => n.split(\" \").map((p) => p[0]).slice(0, 2).join(\"\");\n\n/** Avatar dropdown with an account switcher, a theme row and roving keyboard focus; the panel springs from the trigger corner. */\nexport function AvatarDropdown({\n  name = \"Maya Kerrigan\",\n  email = \"maya@northwind.studio\",\n  accounts = ACCOUNTS,\n  defaultAccountId = \"northwind\",\n  defaultTheme = \"system\",\n  onSelect,\n  onAccountChange,\n  onThemeChange,\n  align = \"end\",\n  defaultOpen = false,\n  className,\n}: AvatarDropdownProps) {\n  const reduce = useReducedMotion();\n  const uid = React.useId();\n  const [open, setOpen] = React.useState(defaultOpen);\n  const focusOnOpen = React.useRef(false);\n  const [account, setAccount] = React.useState(defaultAccountId);\n  const [theme, setTheme] = React.useState<MenuTheme>(defaultTheme);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const menuRef = React.useRef<HTMLDivElement>(null);\n  const current = accounts.find((a) => a.id === account) ?? accounts[0];\n\n  const items = () => Array.from(menuRef.current?.querySelectorAll<HTMLElement>(\"[data-item]\") ?? []);\n\n  React.useEffect(() => {\n    if (!open) return;\n    if (focusOnOpen.current) requestAnimationFrame(() => menuRef.current?.querySelector<HTMLElement>(\"[data-item]\")?.focus());\n    const onDown = (e: PointerEvent) => !rootRef.current?.contains(e.target as Node) && setOpen(false);\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open]);\n\n  function close(refocus = true) {\n    setOpen(false);\n    if (refocus) triggerRef.current?.focus();\n  }\n\n  function onKey(e: React.KeyboardEvent) {\n    const list = items();\n    const i = list.indexOf(document.activeElement as HTMLElement);\n    const go = (n: number) => list[(n + list.length) % list.length]?.focus();\n    if (e.key === \"ArrowDown\") go(i + 1);\n    else if (e.key === \"ArrowUp\") go(i - 1);\n    else if (e.key === \"Home\") go(0);\n    else if (e.key === \"End\") go(list.length - 1);\n    else if (e.key === \"Escape\") close();\n    else if (e.key === \"Tab\") return close(false);\n    else return;\n    e.preventDefault();\n  }\n\n  function act(id: string) {\n    onSelect?.(id);\n    close();\n  }\n\n  const row = \"flex w-full items-center gap-2.5 rounded-sm px-2.5 py-2 text-left text-[13px] text-ink outline-none transition-colors hover:bg-surface-hover focus-visible:bg-surface-hover\";\n\n  return (\n    <div ref={rootRef} className={cn(\"relative inline-block\", className)}>\n      <motion.button\n        ref={triggerRef}\n        type=\"button\"\n        aria-haspopup=\"menu\"\n        aria-expanded={open}\n        aria-controls={`${uid}-menu`}\n        whileTap={{ scale: 0.96 }}\n        onClick={() => {\n          focusOnOpen.current = true;\n          setOpen((o) => !o);\n        }}\n        onKeyDown={(e) => {\n          if (e.key !== \"ArrowDown\") return;\n          e.preventDefault();\n          focusOnOpen.current = true;\n          setOpen(true);\n        }}\n        className=\"flex items-center gap-2 rounded-full border border-border bg-surface-raised py-1 pl-1 pr-2.5 shadow-sm outline-none transition-colors hover:bg-surface-hover focus-visible:shadow-[var(--focus-ring)]\"\n      >\n        <span aria-hidden className=\"grid size-7 place-items-center rounded-full bg-ink text-[11px] font-semibold text-bg\">{initials(name)}</span>\n        <span className=\"text-[13px] font-medium text-ink\">{name.split(\" \")[0]}</span>\n        <motion.span aria-hidden animate={{ rotate: open ? 180 : 0 }} transition={spring} className=\"text-ink-subtle\">\n          <ChevronDown className=\"size-3.5\" />\n        </motion.span>\n      </motion.button>\n\n      <AnimatePresence>\n        {open && (\n          <motion.div\n            ref={menuRef}\n            id={`${uid}-menu`}\n            role=\"menu\"\n            aria-label=\"Account\"\n            onKeyDown={onKey}\n            initial={{ opacity: 0, scale: reduce ? 1 : 0.94, y: reduce ? 0 : -6 }}\n            animate={{ opacity: 1, scale: 1, y: 0 }}\n            exit={{ opacity: 0, scale: reduce ? 1 : 0.96, y: reduce ? 0 : -4, transition: { duration: 0.12 } }}\n            transition={spring}\n            style={{ transformOrigin: align === \"end\" ? \"top right\" : \"top left\" }}\n            className={cn(\"absolute top-full z-30 mt-2 w-[min(288px,calc(100vw-32px))] rounded-md border border-border bg-surface-raised p-1.5 shadow-lg\", align === \"end\" ? \"right-0\" : \"left-0\")}\n          >\n            <div className=\"px-2.5 pb-2 pt-1.5\">\n              <p className=\"text-[13.5px] font-semibold text-ink\">{name}</p>\n              <p className=\"truncate text-[12px] text-ink-subtle\">{email}</p>\n            </div>\n            <div className=\"h-px bg-border\" />\n            <p className=\"px-2.5 pb-1 pt-2 text-[11px] font-medium text-ink-subtle\">Workspaces</p>\n            <div role=\"group\" aria-label=\"Workspaces\">\n              {accounts.map((a) => (\n                <button\n                  key={a.id}\n                  type=\"button\"\n                  role=\"menuitemradio\"\n                  aria-checked={a.id === account}\n                  data-item\n                  tabIndex={-1}\n                  onClick={() => {\n                    setAccount(a.id);\n                    onAccountChange?.(a);\n                  }}\n                  className={row}\n                >\n                  <span aria-hidden className=\"grid size-6 place-items-center rounded-xs bg-surface-sunken text-[10.5px] font-semibold text-ink-muted ring-1 ring-border\">{initials(a.name)}</span>\n                  <span className=\"flex-1 truncate\">{a.name}</span>\n                  <span className=\"text-[11px] text-ink-subtle\">{a.plan}</span>\n                  <span className=\"grid size-4 place-items-center\">\n                    {a.id === current.id && (\n                      <motion.span layoutId={`${uid}-check`} transition={spring}>\n                        <Check aria-hidden className=\"size-4 text-volt-ink\" />\n                      </motion.span>\n                    )}\n                  </span>\n                </button>\n              ))}\n              <button type=\"button\" role=\"menuitem\" data-item tabIndex={-1} onClick={() => act(\"add-account\")} className={cn(row, \"text-ink-muted\")}>\n                <span aria-hidden className=\"grid size-6 place-items-center rounded-xs border border-dashed border-border-strong\"><Plus className=\"size-3.5\" /></span>\n                Add workspace\n              </button>\n            </div>\n            <div className=\"my-1.5 h-px bg-border\" />\n            {ITEMS.map(({ id, label, Icon, kbd }) => (\n              <button key={id} type=\"button\" role=\"menuitem\" data-item tabIndex={-1} onClick={() => act(id)} className={row}>\n                <Icon aria-hidden className=\"size-4 text-ink-subtle\" />\n                <span className=\"flex-1\">{label}</span>\n                <kbd className=\"font-mono text-[11px] text-ink-subtle\">{kbd}</kbd>\n              </button>\n            ))}\n            <div className=\"flex items-center justify-between gap-2 px-2.5 py-1.5\">\n              <span className=\"text-[13px] text-ink\">Theme</span>\n              <div role=\"group\" aria-label=\"Theme\" className=\"flex rounded-full border border-border bg-surface-sunken p-0.5\">\n                {THEMES.map(({ id, label, Icon }) => (\n                  <button\n                    key={id}\n                    type=\"button\"\n                    role=\"menuitemradio\"\n                    aria-checked={theme === id}\n                    aria-label={label}\n                    data-item\n                    tabIndex={-1}\n                    onClick={() => {\n                      setTheme(id);\n                      onThemeChange?.(id);\n                    }}\n                    className=\"relative grid size-7 place-items-center rounded-full outline-none focus-visible:shadow-[var(--focus-ring)]\"\n                  >\n                    {theme === id && <motion.span layoutId={`${uid}-theme`} transition={spring} className=\"absolute inset-0 rounded-full bg-surface-raised shadow-sm ring-1 ring-border\" />}\n                    <Icon aria-hidden className={cn(\"relative size-3.5\", theme === id ? \"text-ink\" : \"text-ink-subtle\")} />\n                  </button>\n                ))}\n              </div>\n            </div>\n            <div className=\"my-1.5 h-px bg-border\" />\n            <button type=\"button\" role=\"menuitem\" data-item tabIndex={-1} onClick={() => act(\"sign-out\")} className={row}>\n              <LogOut aria-hidden className=\"size-4 text-ink-subtle\" />\n              Sign out\n            </button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["examples","user menu","account","avatar","dropdown","profile","workspace switcher","sidebar","command","menu"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/user-menus#avatar-dropdown"}}