Skip to content

Commit d50d770

Browse files
committed
Modularize Tooltip
1 parent 879b4b1 commit d50d770

File tree

2 files changed

+81
-65
lines changed

2 files changed

+81
-65
lines changed

app/src/components/Tooltip.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useState } from 'react';
2+
3+
interface TooltipProps {
4+
label: string;
5+
isCollabTab: boolean;
6+
children: React.ReactNode;
7+
}
8+
9+
const Tooltip: React.FC<TooltipProps> = ({ label, isCollabTab, children }) => {
10+
const [showTooltip, setShowTooltip] = useState(false);
11+
12+
const handleMouseEnter = () => {
13+
setShowTooltip(true);
14+
};
15+
16+
const handleMouseLeave = () => {
17+
setShowTooltip(false);
18+
};
19+
20+
return (
21+
<div onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
22+
{children}
23+
{showTooltip && (
24+
<div
25+
style={{
26+
position: 'absolute',
27+
bottom: isCollabTab ? '120px' : 'none',
28+
marginTop: !isCollabTab ? '45px' : 'none',
29+
left: '50%',
30+
transform: 'translateX(-50%)',
31+
padding: '5px 10px',
32+
backgroundColor: '#333',
33+
color: '#f0f0f0',
34+
borderRadius: '4px',
35+
fontSize: '11px',
36+
textTransform: 'none',
37+
whiteSpace: 'nowrap',
38+
zIndex: 1,
39+
transition: 'opacity 0.3s ease'
40+
}}
41+
>
42+
{label}
43+
<div
44+
style={{
45+
position: 'absolute',
46+
top: isCollabTab ? '100%' : '-5px',
47+
left: '50%',
48+
transform: 'translateX(-50%)',
49+
width: '0',
50+
height: '0',
51+
borderLeft: '5px solid transparent',
52+
borderRight: '5px solid transparent',
53+
borderBottom: !isCollabTab ? '5px solid #333' : 'none',
54+
borderTop: isCollabTab ? '5px solid #333' : 'none'
55+
}}
56+
/>
57+
</div>
58+
)}
59+
</div>
60+
);
61+
};
62+
63+
export default Tooltip;

app/src/components/left/TabWithTooltip.tsx

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { Tab } from '@mui/material';
33
import { AddBox, Folder, Groups2 } from '@mui/icons-material';
4+
import Tooltip from '../Tooltip';
45

56
interface TabWithTooltipProps {
67
label: string;
@@ -13,18 +14,8 @@ const TabWithTooltip: React.FC<TabWithTooltipProps> = ({
1314
label,
1415
value,
1516
activeTab,
16-
handleTabChange
17+
handleTabChange,
1718
}) => {
18-
const [showTooltip, setShowTooltip] = useState(false);
19-
20-
const handleMouseEnter = () => {
21-
setShowTooltip(true);
22-
};
23-
24-
const handleMouseLeave = () => {
25-
setShowTooltip(false);
26-
};
27-
2819
let iconType;
2920
if (value === 0) {
3021
iconType = <Folder sx={{ fontSize: '25px' }} />;
@@ -37,63 +28,25 @@ const TabWithTooltip: React.FC<TabWithTooltipProps> = ({
3728
const isCollabTab = label === 'Collab';
3829

3930
return (
40-
<div onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
41-
{/* Tooltip */}
42-
{showTooltip && (
43-
<div
44-
style={{
45-
position: 'absolute',
46-
bottom: isCollabTab ? '120px' : 'none',
47-
marginTop: !isCollabTab ? '45px' : 'none',
48-
left: '50%',
49-
transform: 'translateX(-50%)',
50-
padding: '5px 10px',
51-
backgroundColor: '#333',
52-
color: '#f0f0f0',
53-
borderRadius: '4px',
31+
<div>
32+
<Tooltip label={label} isCollabTab={isCollabTab}>
33+
<Tab
34+
sx={{
35+
color: activeTab === value ? '#f88e16' : '#9C9D9F',
36+
backgroundColor: activeTab === value && '#2D313A',
37+
'&.Mui-selected': { color: '#f88e16' },
38+
'&:hover': { color: '#f88e16' },
5439
fontSize: '11px',
5540
textTransform: 'none',
56-
whiteSpace: 'nowrap',
57-
zIndex: 1,
58-
transition: 'opacity 0.3s ease',
41+
position: isCollabTab ? 'absolute' : 'relative',
42+
bottom: isCollabTab ? '80px' : 'auto',
43+
opacity: 1,
5944
}}
60-
>
61-
{label}
62-
<div
63-
style={{
64-
position: 'absolute',
65-
top: isCollabTab ? '100%' : '-5px',
66-
left: '50%',
67-
transform: 'translateX(-50%)',
68-
width: '0',
69-
height: '0',
70-
borderLeft: '5px solid transparent',
71-
borderRight: '5px solid transparent',
72-
borderBottom: !isCollabTab ? '5px solid #333' : 'none',
73-
borderTop: isCollabTab ? '5px solid #333' : 'none',
74-
75-
}}
76-
/>
77-
</div>
78-
)}
79-
80-
{/* Tab */}
81-
<Tab
82-
sx={{
83-
color: activeTab === value ? '#f88e16' : '#9C9D9F',
84-
backgroundColor: activeTab === value && '#2D313A',
85-
'&.Mui-selected': { color: '#f88e16' },
86-
'&:hover': { color: '#f88e16' },
87-
fontSize: '11px',
88-
textTransform: 'none',
89-
position: isCollabTab ? 'absolute' : 'relative',
90-
bottom: isCollabTab ? '80px' : 'auto',
91-
opacity: 1,
92-
}}
93-
icon={iconType}
94-
value={value}
95-
onClick={(event) => handleTabChange(event, value)}
96-
/>
45+
icon={iconType}
46+
value={value}
47+
onClick={(event) => handleTabChange(event, value)}
48+
/>
49+
</Tooltip>
9750
</div>
9851
);
9952
};

0 commit comments

Comments
 (0)