Skip to content

Commit 898d3f6

Browse files
committed
[frontend] add open/close animation to menus
1 parent 71a3cf0 commit 898d3f6

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

frontend/src/components/Menu.tsx

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@ import type { IconifyIcon } from "@iconify/types";
1212

1313
export const closeMenu = createDelegate<void>();
1414

15-
export const Menu: Component<{
16-
x: number;
17-
y: number;
18-
items?: MenuItem[];
19-
custom?: HTMLElement;
20-
}> = function (cx) {
15+
export const Menu: Component<
16+
{
17+
x: number;
18+
y: number;
19+
items?: MenuItem[];
20+
custom?: HTMLElement;
21+
},
22+
{
23+
closing: boolean;
24+
}
25+
> = function (cx) {
26+
this.closing = true;
27+
requestAnimationFrame(() => {
28+
this.closing = false;
29+
});
2130
const close = () => {
22-
cx.root.remove();
2331
browser.unfocusframes = false;
2432

2533
window.removeEventListener("click", ev, { capture: true });
2634
window.removeEventListener("contextmenu", ev, { capture: true });
35+
36+
this.closing = true;
37+
cx.root.addEventListener("transitionend", () => {
38+
cx.root.remove();
39+
});
2740
};
2841
closeMenu.listen(close);
2942

@@ -57,7 +70,10 @@ export const Menu: Component<{
5770
});
5871
};
5972
return (
60-
<div style={use`--x: ${this.x}px; --y: ${this.y}px;`}>
73+
<div
74+
style={use`--x: ${this.x}px; --y: ${this.y}px;`}
75+
class:closing={use(this.closing)}
76+
>
6177
{this.items
6278
? use(this.items).mapEach((item) =>
6379
item.checkbox ? (
@@ -110,6 +126,16 @@ Menu.style = css`
110126
flex-direction: column;
111127
min-width: 10em;
112128
overflow: hidden;
129+
130+
transition:
131+
opacity 0.15s ease,
132+
transform 0.15s ease;
133+
opacity: 1;
134+
transform: scale(100%);
135+
}
136+
:scope.closing {
137+
transform: scale(95%);
138+
opacity: 0;
113139
}
114140
.item {
115141
background: none;

frontend/src/components/Omnibox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const DownloadsPopup: Component<{}> = function (cx) {
149149
class="footer"
150150
on:click={() => {
151151
browser.newTab(new URL("puter://downloads"));
152+
closeMenu();
152153
}}
153154
>
154155
<span>Full Download History</span>
@@ -205,7 +206,6 @@ DownloadsPopup.style = css`
205206
padding: 1em;
206207
display: flex;
207208
gap: 1em;
208-
cursor: pointer;
209209
font-size: 0.9em;
210210
}
211211
.entry:hover {

0 commit comments

Comments
 (0)