Skip to content

Commit 0ab5627

Browse files
committed
use headless dropdown menu for user menu in topbar
1 parent a7cb26f commit 0ab5627

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

app/components/TopBar.tsx

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8+
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'
9+
import cn from 'classnames'
810
import React from 'react'
11+
import { Link } from 'react-router-dom'
912

1013
import { navToLogin, useApiMutation } from '@oxide/api'
1114
import { DirectionDownIcon, Profile16Icon } from '@oxide/design-system/icons/react'
1215

1316
import { useCurrentUser } from '~/layouts/AuthenticatedLayout'
14-
import { Button } from '~/ui/lib/Button'
15-
import { DropdownMenu } from '~/ui/lib/DropdownMenu'
17+
import { buttonStyle } from '~/ui/lib/Button'
1618
import { pb } from '~/util/path-builder'
1719

1820
export function TopBar({ children }: { children: React.ReactNode }) {
@@ -40,31 +42,42 @@ export function TopBar({ children }: { children: React.ReactNode }) {
4042
<div className="mx-3 flex h-[60px] shrink-0 items-center justify-between">
4143
<div className="flex items-center">{otherPickers}</div>
4244
<div className="flex items-center gap-2">
43-
{/* <Button variant="secondary" size="icon" className="ml-2" title="Notifications">
44-
<Notifications16Icon className="text-quaternary" />
45-
</Button> */}
46-
<DropdownMenu.Root>
47-
<DropdownMenu.Trigger asChild>
48-
<Button
49-
size="sm"
50-
variant="secondary"
51-
aria-label="User menu"
52-
innerClassName="space-x-2"
53-
>
54-
<Profile16Icon className="text-quaternary" />
55-
<span className="normal-case text-sans-md text-secondary">
56-
{me.displayName || 'User'}
57-
</span>
58-
<DirectionDownIcon className="!w-2.5" />
59-
</Button>
60-
</DropdownMenu.Trigger>
61-
<DropdownMenu.Content align="end" sideOffset={8}>
62-
<DropdownMenu.LinkItem to={pb.profile()}>Settings</DropdownMenu.LinkItem>
63-
<DropdownMenu.Item onSelect={() => logout.mutate({})}>
64-
Sign out
65-
</DropdownMenu.Item>
66-
</DropdownMenu.Content>
67-
</DropdownMenu.Root>
45+
<Menu>
46+
<MenuButton
47+
className={cn(
48+
'flex items-center gap-2',
49+
buttonStyle({ size: 'sm', variant: 'secondary' })
50+
)}
51+
aria-label="User menu"
52+
>
53+
<Profile16Icon className="text-quaternary" />
54+
<span className="normal-case text-sans-md text-secondary">
55+
{me.displayName || 'User'}
56+
</span>
57+
<DirectionDownIcon className="!w-2.5" />
58+
</MenuButton>
59+
{/* TODO: fix hover style + should be able to click anywhere in the menu item */}
60+
<MenuItems
61+
anchor="bottom end"
62+
className="DropdownMenuContent [--anchor-gap:8px]"
63+
>
64+
{/* TODO: extract Item and LinkItem components*/}
65+
<MenuItem>
66+
<Link className="DropdownMenuItem ox-menu-item" to={pb.profile()}>
67+
Settings
68+
</Link>
69+
</MenuItem>
70+
<MenuItem>
71+
<button
72+
type="button"
73+
onClick={() => logout.mutate({})}
74+
className="DropdownMenuItem ox-menu-item"
75+
>
76+
Sign out
77+
</button>
78+
</MenuItem>
79+
</MenuItems>
80+
</Menu>
6881
</div>
6982
</div>
7083
</div>

0 commit comments

Comments
 (0)