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