({
active,
payload,
className,
indicator = "dot",
hideLabel = false,
hideIndicator = false,
label,
labelFormatter,
labelClassName,
formatter,
color,
nameKey,
labelKey,
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
React.ComponentProps<"div"> & {
hideLabel?: boolean;
hideIndicator?: boolean;
indicator?: "line" | "dot" | "dashed";
nameKey?: string;
labelKey?: string;
} & Omit<
RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>,
"accessibilityLayer"
>)
| 122 | const ChartTooltip = RechartsPrimitive.Tooltip; |
| 123 | |
| 124 | function ChartTooltipContent({ |
| 125 | active, |
| 126 | payload, |
| 127 | className, |
| 128 | indicator = "dot", |
| 129 | hideLabel = false, |
| 130 | hideIndicator = false, |
| 131 | label, |
| 132 | labelFormatter, |
| 133 | labelClassName, |
| 134 | formatter, |
| 135 | color, |
| 136 | nameKey, |
| 137 | labelKey, |
| 138 | }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & |
| 139 | React.ComponentProps<"div"> & { |
| 140 | hideLabel?: boolean; |
| 141 | hideIndicator?: boolean; |
| 142 | indicator?: "line" | "dot" | "dashed"; |
| 143 | nameKey?: string; |
| 144 | labelKey?: string; |
| 145 | } & Omit< |
| 146 | RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, |
| 147 | "accessibilityLayer" |
| 148 | >) { |
| 149 | const { config } = useChart(); |
| 150 | |
| 151 | const tooltipLabel = React.useMemo(() => { |
| 152 | if (hideLabel || !payload?.length) { |
| 153 | return null; |
| 154 | } |
| 155 | |
| 156 | const [item] = payload; |
| 157 | const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`; |
| 158 | const itemConfig = getPayloadConfigFromPayload(config, item, key); |
| 159 | const value = |
| 160 | !labelKey && typeof label === "string" ? (config[label]?.label ?? label) : itemConfig?.label; |
| 161 | |
| 162 | if (labelFormatter) { |
| 163 | return ( |
| 164 | <div className={cn("font-medium", labelClassName)}>{labelFormatter(value, payload)}</div> |
| 165 | ); |
| 166 | } |
| 167 | |
| 168 | if (!value) { |
| 169 | return null; |
| 170 | } |
| 171 | |
| 172 | return <div className={cn("font-medium", labelClassName)}>{value}</div>; |
| 173 | }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]); |
| 174 | |
| 175 | if (!active || !payload?.length) { |
| 176 | return null; |
| 177 | } |
| 178 | |
| 179 | const nestLabel = payload.length === 1 && indicator !== "dot"; |
| 180 | |
| 181 | return ( |
nothing calls this directly
no test coverage detected