MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / ChartLegendContent

Function ChartLegendContent

packages/react/src/components/chart.tsx:265–318  ·  view source on GitHub ↗
({
  className,
  hideIcon = false,
  payload,
  verticalAlign = "bottom",
  nameKey,
}: React.ComponentProps<"div"> & {
  hideIcon?: boolean;
  nameKey?: string;
} & RechartsPrimitive.DefaultLegendContentProps)

Source from the content-addressed store, hash-verified

263const ChartLegend = RechartsPrimitive.Legend;
264
265function ChartLegendContent({
266 className,
267 hideIcon = false,
268 payload,
269 verticalAlign = "bottom",
270 nameKey,
271}: React.ComponentProps<"div"> & {
272 hideIcon?: boolean;
273 nameKey?: string;
274} & RechartsPrimitive.DefaultLegendContentProps) {
275 const { config } = useChart();
276
277 if (!payload?.length) {
278 return null;
279 }
280
281 return (
282 <div
283 className={cn(
284 "flex items-center justify-center gap-4",
285 verticalAlign === "top" ? "pb-3" : "pt-3",
286 className,
287 )}
288 >
289 {payload
290 .filter((item) => item.type !== "none")
291 .map((item, index) => {
292 const key = `${nameKey ?? item.dataKey ?? "value"}`;
293 const itemConfig = getPayloadConfigFromPayload(config, item, key);
294
295 return (
296 <div
297 key={index}
298 className={cn(
299 "flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
300 )}
301 >
302 {itemConfig?.icon && !hideIcon ? (
303 <itemConfig.icon />
304 ) : (
305 <div
306 className="h-2 w-2 shrink-0 rounded-[2px]"
307 style={{
308 backgroundColor: item.color,
309 }}
310 />
311 )}
312 {itemConfig?.label}
313 </div>
314 );
315 })}
316 </div>
317 );
318}
319
320// Helper to extract item config from a payload.
321const isRecord = (value: unknown): value is Record<string, unknown> =>

Callers

nothing calls this directly

Calls 3

cnFunction · 0.90
useChartFunction · 0.85

Tested by

no test coverage detected