Skip to content

Commit f4e81f5

Browse files
committed
fix: navbar dropdown (close on esc)
1 parent ed4ec92 commit f4e81f5

File tree

1 file changed

+69
-100
lines changed

1 file changed

+69
-100
lines changed

src/lib/components/navbar.svelte

Lines changed: 69 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
Navbar,
2424
Icon,
2525
Layout,
26-
Link,
2726
Tooltip,
28-
Card,
2927
ActionMenu,
3028
ToggleButton,
3129
Button,
3230
Avatar,
33-
Typography
31+
Typography,
32+
Popover
3433
} from '@appwrite.io/pink-svelte';
3534
import { toggleCommandCenter } from '$lib/commandCenter/commandCenter.svelte';
3635
import {
@@ -209,91 +208,79 @@
209208
</Button.Button>
210209
<span slot="tooltip">{isMac() ? '⌘ + K' : 'Ctrl + K'}</span></Tooltip>
211210
</Layout.Stack>
212-
<Link.Button
213-
on:click={() => {
214-
showAccountMenu = !showAccountMenu;
215-
shouldAnimateThemeToggle = false;
216-
if (showAccountMenu) {
217-
trackEvent(Click.MenuDropDownClick);
218-
}
219-
}}>
220-
<div style:user-select="none">
211+
<Popover let:toggle let:showing>
212+
<button
213+
type="button"
214+
on:click|preventDefault={(e) => {
215+
toggle(e);
216+
shouldAnimateThemeToggle = false;
217+
if (showing) {
218+
trackEvent(Click.MenuDropDownClick);
219+
}
220+
}}
221+
style:user-select="none">
221222
<Avatar size="s" src={avatar} />
222-
</div>
223-
</Link.Button>
224-
{#if showAccountMenu}
225-
<div class="account-container">
226-
<Card.Base padding="xxxs" shadow={true}>
223+
</button>
224+
<svelte:fragment slot="tooltip" let:toggle>
225+
<ActionMenu.Root noPadding>
227226
<Layout.Stack gap="xxs">
228-
<ActionMenu.Root>
229-
<Layout.Stack gap="xxs">
230-
<div
231-
style:padding-inline-start="10px"
232-
style:padding-inline-end="8px"
233-
style:padding-block="4px">
234-
<Typography.Text variant="m-500">
235-
{$user.email}
236-
</Typography.Text>
237-
</div>
238-
<ActionMenu.Item.Anchor
239-
trailingIcon={IconUser}
240-
size="l"
241-
href={`${base}/account`}>
242-
Account</ActionMenu.Item.Anchor>
227+
<div
228+
style:padding-inline-start="10px"
229+
style:padding-inline-end="8px"
230+
style:padding-block="4px">
231+
<Typography.Text variant="m-500">
232+
{$user.email}
233+
</Typography.Text>
234+
</div>
235+
<ActionMenu.Item.Anchor
236+
trailingIcon={IconUser}
237+
on:click={toggle}
238+
size="l"
239+
href={`${base}/account`}>
240+
Account</ActionMenu.Item.Anchor>
243241

244-
<ActionMenu.Item.Button
245-
trailingIcon={IconLogoutRight}
246-
size="l"
247-
on:click={() => logout()}>Sign out</ActionMenu.Item.Button>
248-
<div
249-
style:padding-inline-start="10px"
250-
style:padding-inline-end="8px">
251-
<Layout.Stack
252-
justifyContent="space-between"
253-
direction="row"
254-
alignItems="center">
255-
<Typography.Text>Theme</Typography.Text>
256-
<div
257-
class:keepTransformTransition={shouldAnimateThemeToggle}>
258-
<ToggleButton
259-
bind:active={activeTheme}
260-
on:change={() => {
261-
setTimeout(() => {
262-
shouldAnimateThemeToggle = true;
263-
}, 150);
264-
}}
265-
buttons={[
266-
{
267-
id: 'light',
268-
label: 'Light',
269-
icon: IconSun
270-
},
271-
{
272-
id: 'dark',
273-
label: 'Dark',
274-
icon: IconMoon
275-
},
276-
{
277-
id: 'auto',
278-
label: 'System',
279-
icon: IconMode
280-
}
281-
]}></ToggleButton>
282-
</div>
283-
</Layout.Stack>
242+
<ActionMenu.Item.Button
243+
trailingIcon={IconLogoutRight}
244+
size="l"
245+
on:click={() => logout()}>Sign out</ActionMenu.Item.Button>
246+
<div style:padding-inline-start="10px" style:padding-inline-end="8px">
247+
<Layout.Stack
248+
justifyContent="space-between"
249+
direction="row"
250+
alignItems="center">
251+
<Typography.Text>Theme</Typography.Text>
252+
<div class:keepTransformTransition={shouldAnimateThemeToggle}>
253+
<ToggleButton
254+
bind:active={activeTheme}
255+
on:change={() => {
256+
setTimeout(() => {
257+
shouldAnimateThemeToggle = true;
258+
}, 150);
259+
}}
260+
buttons={[
261+
{
262+
id: 'light',
263+
label: 'Light',
264+
icon: IconSun
265+
},
266+
{
267+
id: 'dark',
268+
label: 'Dark',
269+
icon: IconMoon
270+
},
271+
{
272+
id: 'auto',
273+
label: 'System',
274+
icon: IconMode
275+
}
276+
]}></ToggleButton>
284277
</div>
285278
</Layout.Stack>
286-
</ActionMenu.Root>
279+
</div>
287280
</Layout.Stack>
288-
</Card.Base>
289-
</div>
290-
<button
291-
class="account-backdrop"
292-
aria-label="Account menu"
293-
on:click={() => {
294-
showAccountMenu = false;
295-
}}></button>
296-
{/if}
281+
</ActionMenu.Root>
282+
</svelte:fragment>
283+
</Popover>
297284
</div>
298285
</div>
299286
</Navbar.Base>
@@ -405,24 +392,6 @@
405392
}
406393
}
407394
408-
.account-container {
409-
position: absolute;
410-
right: var(--space-7);
411-
top: var(--base-44);
412-
width: 244px;
413-
display: flex;
414-
z-index: 1;
415-
}
416-
417-
.account-backdrop {
418-
position: absolute;
419-
left: 0;
420-
top: 0;
421-
width: 100vw;
422-
height: 100vh;
423-
background-color: transparent;
424-
}
425-
426395
/* The default drop list has a max-inline width of 280px, which squeezes the support modal. */
427396
:global(.extended-width) {
428397
max-inline-size: none;

0 commit comments

Comments
 (0)