Skip to content

Commit a501bcf

Browse files
committed
Legend items truncate and show tooltip
1 parent 3beb783 commit a501bcf

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

apps/webapp/app/components/primitives/charts/ChartLegendCompound.tsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useSeriesTotal } from "./ChartRoot";
55
import { aggregateValues } from "./aggregation";
66
import { cn } from "~/utils/cn";
77
import { AnimatedNumber } from "../AnimatedNumber";
8+
import { SimpleTooltip } from "../Tooltip";
89

910
const aggregationLabels: Record<AggregationType, string> = {
1011
sum: "Sum",
@@ -204,7 +205,7 @@ export function ChartLegendCompound({
204205
<div
205206
key={item.dataKey}
206207
className={cn(
207-
"relative flex w-full cursor-pointer items-center justify-between gap-2 rounded px-2 py-1 transition",
208+
"relative flex w-full cursor-default items-center justify-between gap-2 rounded px-2 py-1 transition",
208209
(total == null || total === 0) && "opacity-50"
209210
)}
210211
onMouseEnter={() => highlight.setHoveredLegendItem(item.dataKey)}
@@ -217,18 +218,32 @@ export function ChartLegendCompound({
217218
style={{ backgroundColor: item.color }}
218219
/>
219220
)}
220-
<div className="relative flex w-full items-center justify-between gap-3">
221-
<div className="flex items-center gap-1.5">
222-
{item.color && (
223-
<div
224-
className="w-1 shrink-0 self-stretch rounded-[2px]"
225-
style={{ backgroundColor: item.color }}
226-
/>
227-
)}
228-
<span className={isActive ? "text-text-bright" : "text-text-dimmed"}>
229-
{item.label}
230-
</span>
231-
</div>
221+
<div className="relative flex w-full items-center justify-between gap-3 overflow-hidden">
222+
<SimpleTooltip
223+
button={
224+
<div className="flex min-w-0 items-center gap-1.5">
225+
{item.color && (
226+
<div
227+
className="w-1 shrink-0 self-stretch rounded-[2px]"
228+
style={{ backgroundColor: item.color }}
229+
/>
230+
)}
231+
<span
232+
className={cn(
233+
"truncate",
234+
isActive ? "text-text-bright" : "text-text-dimmed"
235+
)}
236+
>
237+
{item.label}
238+
</span>
239+
</div>
240+
}
241+
content={item.label}
242+
side="top"
243+
disableHoverableContent
244+
className="max-w-xs break-words"
245+
buttonClassName="cursor-default min-w-0"
246+
/>
232247
<span
233248
className={cn(
234249
"self-start tabular-nums",

0 commit comments

Comments
 (0)