Skip to content

Commit db228bc

Browse files
committed
[chrome] ux: animate tooltip appear/dissapear
1 parent c1bb064 commit db228bc

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

packages/chrome/src/components/TabStrip/TabTooltip.tsx

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1-
import { css } from "dreamland/core";
1+
import { css, type ComponentContext } from "dreamland/core";
22
import type { Tab } from "../../Tab";
33
import { isFirefox } from "../../utils";
44

5-
export function TabTooltip(props: { active: boolean; tab: Tab }) {
5+
export function TabTooltip(
6+
props: { active: boolean; tab: Tab },
7+
cx: ComponentContext
8+
) {
9+
let wasActive = props.active;
10+
11+
const duration = 150;
12+
const visible = {
13+
opacity: "1",
14+
transform: "scale(100%)",
15+
};
16+
const hidden = {
17+
opacity: "0",
18+
transform: "scale(95%)",
19+
};
20+
21+
use(props.active).listen((active) => {
22+
if (active && !wasActive) {
23+
wasActive = true;
24+
cx.root.animate([hidden, visible], {
25+
duration,
26+
fill: "forwards",
27+
});
28+
} else if (!active && wasActive) {
29+
wasActive = false;
30+
cx.root.animate([visible, hidden], {
31+
duration,
32+
fill: "forwards",
33+
});
34+
}
35+
});
636
return (
7-
<div class:active={use(props.active)}>
37+
<div>
838
<div class="text">
939
<span class="title">{use(props.tab.title)}</span>
1040
<span class="hostname">{use(props.tab.url.hostname)}</span>
@@ -35,12 +65,9 @@ TabTooltip.style = css`
3565
width: 17em;
3666
gap: 0.25em;
3767
flex-direction: column;
38-
display: none;
68+
opacity: 0;
3969
border-radius: 4px;
4070
}
41-
:scope.active {
42-
display: flex;
43-
}
4471
.text {
4572
padding: 0.5em;
4673
display: flex;

0 commit comments

Comments
 (0)