import { cn } from "cn"; import type * as React from "react"; type AllocationSegment = { label: string; /** Weight in percent (any positive number; bars are proportional). */ value: number; /** Any CSS color; defaults cycle `--chart-1…5`. */ color?: string; }; // Weights bar with a legend of label + mono percentage. function AllocationBar({ className, segments, showLegend = true, size = "default", ...props }: Omit, "children"> & { segments: AllocationSegment[]; showLegend?: boolean; /** ✦ `sm`: slimmer bar and a compact mono legend (cards). */ size?: "default" | "sm"; }) { const sm = size === "sm"; const colored = segments.map((s, i) => ({ ...s, color: s.color ?? `var(--chart-${(i % 5) + 1})`, })); return (
`${s.label} ${s.value}%`).join(", ")} > {colored.map((s) => ( ))}
{showLegend ? ( ) : null}
); } export type { AllocationSegment }; export { AllocationBar };