({
className,
hideIcon = false,
payload,
verticalAlign = "bottom",
nameKey,
}: React.ComponentProps<"div"> &
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
hideIcon?: boolean
nameKey?: string
})
| 253 | const ChartLegend = RechartsPrimitive.Legend |
| 254 | |
| 255 | function ChartLegendContent({ |
| 256 | className, |
| 257 | hideIcon = false, |
| 258 | payload, |
| 259 | verticalAlign = "bottom", |
| 260 | nameKey, |
| 261 | }: React.ComponentProps<"div"> & |
| 262 | Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & { |
| 263 | hideIcon?: boolean |
| 264 | nameKey?: string |
| 265 | }) { |
| 266 | const { config } = useChart() |
| 267 | |
| 268 | if (!payload?.length) { |
| 269 | return null |
| 270 | } |
| 271 | |
| 272 | return ( |
| 273 | <div |
| 274 | className={cn( |
| 275 | "flex items-center justify-center gap-4", |
| 276 | verticalAlign === "top" ? "pb-3" : "pt-3", |
| 277 | className |
| 278 | )} |
| 279 | > |
| 280 | {payload |
| 281 | .filter((item) => item.type !== "none") |
| 282 | .map((item) => { |
| 283 | const key = `${nameKey || item.dataKey || "value"}` |
| 284 | const itemConfig = getPayloadConfigFromPayload(config, item, key) |
| 285 | |
| 286 | return ( |
| 287 | <div |
| 288 | key={item.value} |
| 289 | className={cn( |
| 290 | "[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3" |
| 291 | )} |
| 292 | > |
| 293 | {itemConfig?.icon && !hideIcon ? ( |
| 294 | <itemConfig.icon /> |
| 295 | ) : ( |
| 296 | <div |
| 297 | className="h-2 w-2 shrink-0 rounded-[2px]" |
| 298 | style={{ |
| 299 | backgroundColor: item.color, |
| 300 | }} |
| 301 | /> |
| 302 | )} |
| 303 | {itemConfig?.label} |
| 304 | </div> |
| 305 | ) |
| 306 | })} |
| 307 | </div> |
| 308 | ) |
| 309 | } |
| 310 | |
| 311 | // Helper to extract item config from a payload. |
| 312 | function getPayloadConfigFromPayload( |
nothing calls this directly
no test coverage detected