Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit bccf685

Browse files
committed
add tooltip component
1 parent b656540 commit bccf685

File tree

3 files changed

+67
-31
lines changed

3 files changed

+67
-31
lines changed

frontend/src/components/elevator/car.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { ChainTheme, chainThemeAtom } from "../../states/atoms";
1818
import ElevatorCapacity from "./capacity";
1919
import { JSX } from "preact/jsx-runtime";
2020
import { bodyToScreenPosition, createTooltipContent } from "../../util/scene";
21-
import { toShortHex } from "../../util/type";
2221

2322
export interface ElevatorCarProp {
2423
transactions: Transaction[];

frontend/src/components/elevator/miner.tsx

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ChainTheme, chainThemeAtom } from "../../states/atoms";
44
import { Hex } from "@ckb-ccc/core";
55
import { useMemo } from "preact/hooks";
66
import { getApeRunningGif, getRunningSpeedClass } from "./util";
7+
import Tooltip from "../tooltip";
78

89
export interface ElevatorUpButtonProps {
910
difficultyInEH: number;
@@ -72,40 +73,49 @@ const ElevatorMiner: FunctionComponent<ElevatorUpButtonProps> = ({
7273
<div className="w-[10px] h-[20px] bg-black" />
7374

7475
<div>
75-
<div className="relative">
76-
<img
77-
className="absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2"
78-
src={doorClosing ? minerJumpSvg : minerApeRunning}
79-
alt="Miner Ape"
80-
/>
81-
<img
82-
className={`${doorClosing ? "" : spinClass}`}
83-
src={minerWheel}
84-
alt="Miner Wheel"
85-
/>
86-
87-
{/* 气泡元素 */}
88-
{doorClosing && (
89-
<div
90-
className={`absolute left-[calc(70%+8px)] top-1/4 -translate-y-1/2 ${bgBrand} text-white px-3 py-1 rounded-full animate-bubble-up`}
91-
>
92-
Found a new nonce {nonce}
93-
</div>
94-
)}
95-
</div>
96-
97-
<div className="relative">
98-
<div className="absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2 text-text-inverse">
99-
<div
76+
<Tooltip text="I am a Miner, I work hard to find the nonce for the block for coins!">
77+
<div className="relative">
78+
<img
10079
className={
101-
"truncate overflow-hidden whitespace-nowrap"
80+
"absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2 z-50"
10281
}
103-
>
104-
Difficulty {difficultyInEH} EH
82+
src={
83+
doorClosing ? minerJumpSvg : minerApeRunning
84+
}
85+
alt="Miner Ape"
86+
/>
87+
88+
<img
89+
className={`${doorClosing ? "" : spinClass}`}
90+
src={minerWheel}
91+
alt="Miner Wheel"
92+
/>
93+
94+
{/* 气泡元素 */}
95+
{doorClosing && (
96+
<div
97+
className={`absolute left-[calc(70%+8px)] top-1/4 -translate-y-1/2 ${bgBrand} text-white px-3 py-1 rounded-full animate-bubble-up`}
98+
>
99+
Found a new nonce {nonce}
100+
</div>
101+
)}
102+
</div>
103+
</Tooltip>
104+
105+
<Tooltip text="The miner difficulty is the number of leading zeros in the hash of the block header. The higher the difficulty, the harder it is to find the nonce.">
106+
<div className="relative">
107+
<div className="absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2 text-text-inverse">
108+
<div
109+
className={
110+
"truncate overflow-hidden whitespace-nowrap"
111+
}
112+
>
113+
Difficulty {difficultyInEH} EH
114+
</div>
105115
</div>
116+
<img src={minerBaseSvg} alt="Miner Base" />
106117
</div>
107-
<img src={minerBaseSvg} alt="Miner Base" />
108-
</div>
118+
</Tooltip>
109119
</div>
110120
</div>
111121
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useState } from "preact/hooks";
2+
3+
interface TooltipProps {
4+
text: string;
5+
children: React.ReactNode;
6+
}
7+
8+
const Tooltip = ({ text, children }: TooltipProps) => {
9+
const [isVisible, setIsVisible] = useState(false);
10+
11+
return (
12+
<div
13+
className={`relative`}
14+
onMouseEnter={() => setIsVisible(true)}
15+
onMouseLeave={() => setIsVisible(false)}
16+
>
17+
{children}
18+
{isVisible && (
19+
<div className="absolute bottom-full mb-2 w-full left-1/2 transform -translate-x-1/2 bg-surface-DEFAULT-03 text-text-primary text-sm p-2 rounded-md shadow-lg z-50">
20+
{text}
21+
</div>
22+
)}
23+
</div>
24+
);
25+
};
26+
27+
export default Tooltip;

0 commit comments

Comments
 (0)