"use client" import { cn } from "@/lib/utils" import React from "react" import { Bar, BarChart as RechartsBarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts" interface BarChartProps extends React.HTMLAttributes { data: Record[] index: string categories: string[] strokeColors?: string[] fillColors?: string[] tooltipBgColor?: string tooltipBorderColor?: string gridColor?: string valueFormatter?: (value: number) => string showGrid?: boolean showTooltip?: boolean stacked?: boolean alignment?: "vertical" | "horizontal" className?: string } const BarChart = React.forwardRef( ( { data = [], index, categories = [], strokeColors = ["var(--foreground)"], fillColors = ["var(--primary)", "var(--secondary)"], tooltipBgColor = "var(--background)", tooltipBorderColor = "var(--border)", gridColor = "var(--muted)", valueFormatter = (value: number) => value.toString(), showGrid = true, showTooltip = true, stacked = false, alignment = "vertical", className, ...props }, ref ) => { return (
{showGrid && ( )} {alignment === "horizontal" ? ( <> ) : ( <> )} {showTooltip && ( { if (!active || !payload?.length) return null return (
{index} {label}
{payload.map((entry, index) => (
{entry.dataKey} {valueFormatter(entry.value as number)}
))}
) }} /> )} {categories.map((category, index) => { const fillColor = fillColors[index] || fillColors[0] const strokeColor = strokeColors[index] || strokeColors[0] return ( ) })}
) } ) BarChart.displayName = "BarChart" export { BarChart, type BarChartProps }