Skip to content

Commit c9bf004

Browse files
author
Dylan Huang
committed
extract tooltip into its own component
1 parent df96919 commit c9bf004

File tree

2 files changed

+79
-40
lines changed

2 files changed

+79
-40
lines changed

vite-app/src/components/EvaluationRow.tsx

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { state } from "../App";
77
import { TableCell, TableRowInteractive } from "./TableContainer";
88
import { useState } from "react";
99
import type { FilterGroup, FilterConfig } from "../types/filters";
10+
import { Tooltip } from "./Tooltip";
1011

1112
// Add filter button component
1213
const AddFilterButton = observer(
@@ -61,47 +62,44 @@ const AddFilterButton = observer(
6162
};
6263

6364
return (
64-
<button
65-
className="text-gray-400 hover:text-gray-600 transition-colors relative group cursor-pointer"
66-
onClick={handleClick}
67-
title="Add filter for this value"
65+
<Tooltip
66+
content={added ? "Filter Added!" : `Add ${label} Filter`}
67+
position="top"
68+
className="text-gray-400 hover:text-gray-600 transition-colors"
6869
>
69-
{/* Tooltip */}
70-
<div className="absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-2 py-1 text-xs text-white bg-gray-800 rounded opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none whitespace-nowrap">
71-
{added ? "Filter Added!" : `Add ${label} Filter`}
72-
</div>
73-
74-
{/* Icon */}
75-
{added ? (
76-
<svg
77-
className="w-3 h-3 text-green-600"
78-
fill="none"
79-
stroke="currentColor"
80-
viewBox="0 0 24 24"
81-
>
82-
<path
83-
strokeLinecap="round"
84-
strokeLinejoin="round"
85-
strokeWidth={2}
86-
d="M5 13l4 4L19 7"
87-
/>
88-
</svg>
89-
) : (
90-
<svg
91-
className="w-3 h-3"
92-
fill="none"
93-
stroke="currentColor"
94-
viewBox="0 0 24 24"
95-
>
96-
<path
97-
strokeLinecap="round"
98-
strokeLinejoin="round"
99-
strokeWidth={2}
100-
d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.207A1 1 0 013 6.5V4z"
101-
/>
102-
</svg>
103-
)}
104-
</button>
70+
<button onClick={handleClick} title="Add filter for this value">
71+
{/* Icon */}
72+
{added ? (
73+
<svg
74+
className="w-3 h-3 text-green-600"
75+
fill="none"
76+
stroke="currentColor"
77+
viewBox="0 0 24 24"
78+
>
79+
<path
80+
strokeLinecap="round"
81+
strokeLinejoin="round"
82+
strokeWidth={2}
83+
d="M5 13l4 4L19 7"
84+
/>
85+
</svg>
86+
) : (
87+
<svg
88+
className="w-3 h-3"
89+
fill="none"
90+
stroke="currentColor"
91+
viewBox="0 0 24 24"
92+
>
93+
<path
94+
strokeLinecap="round"
95+
strokeLinejoin="round"
96+
strokeWidth={2}
97+
d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.207A1 1 0 013 6.5V4z"
98+
/>
99+
</svg>
100+
)}
101+
</button>
102+
</Tooltip>
105103
);
106104
}
107105
);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from "react";
2+
3+
interface TooltipProps {
4+
children: React.ReactNode;
5+
content: string;
6+
position?: "top" | "bottom" | "left" | "right";
7+
className?: string;
8+
}
9+
10+
export const Tooltip: React.FC<TooltipProps> = ({
11+
children,
12+
content,
13+
position = "top",
14+
className = "",
15+
}) => {
16+
const getPositionClasses = () => {
17+
switch (position) {
18+
case "top":
19+
return "bottom-full left-1/2 transform -translate-x-1/2 mb-2";
20+
case "bottom":
21+
return "top-full left-1/2 transform -translate-x-1/2 mt-2";
22+
case "left":
23+
return "right-full top-1/2 transform -translate-y-1/2 mr-2";
24+
case "right":
25+
return "left-full top-1/2 transform -translate-y-1/2 ml-2";
26+
default:
27+
return "bottom-full left-1/2 transform -translate-x-1/2 mb-2";
28+
}
29+
};
30+
31+
return (
32+
<div className={`relative group cursor-pointer ${className}`}>
33+
{children}
34+
<div
35+
className={`absolute ${getPositionClasses()} px-2 py-1 text-xs text-white bg-gray-800 rounded opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none whitespace-nowrap z-10`}
36+
>
37+
{content}
38+
</div>
39+
</div>
40+
);
41+
};

0 commit comments

Comments
 (0)