"use client" import * as React from "react" import * as RechartsPrimitive from "recharts" import { cn } from "@/lib/utils" // Format: { THEME_NAME: CSS_SELECTOR } const THEMES = { light: "", dark: ".dark" } as const export type ChartConfig = { [k in string]: { label?: React.ReactNode icon?: React.ComponentType } & ({ color?: string; theme?: never } | { color?: never; theme: Record }) } type ChartContextProps = { config: ChartConfig } const ChartContext = React.createContext(null) function useChart() { const context = React.useContext(ChartContext) if (!context) { throw new Error("useChart must be used within a ") } return context } interface ChartContainerProps extends React.HTMLAttributes { config: Record } const ChartContainer = React.forwardRef( ({ className, config, children, ...props }, ref) => { const colorVars = Object.entries(config).reduce( (acc, [key, value]) => { acc[`--color-${key}`] = value.color return acc }, {} as Record, ) return (
{children}
) }, ) ChartContainer.displayName = "ChartContainer" const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => { const colorConfig = Object.entries(config).filter(([_, config]) => config.theme || config.color) if (!colorConfig.length) { return null } return (