'use client'; import * as React from 'react'; import * as RechartsPrimitive from 'recharts'; import {cn} from '../../lib'; // ============================================ // TYPES // ============================================ export type ChartConfig = Record< string, { label?: React.ReactNode; icon?: React.ComponentType; color?: string; theme?: { light?: string; dark?: string; }; } >; interface ChartContextProps { config: ChartConfig; } const ChartContext = React.createContext(null); function useChart() { const context = React.use(ChartContext); if (!context) { throw new Error('useChart must be used within a '); } return context; } // ============================================ // CHART CONTAINER // ============================================ interface ChartContainerProps extends React.ComponentProps<'div'> { config: ChartConfig; children: React.ComponentProps['children']; } function ChartContainer({id, className, children, config, ref, ...props}: ChartContainerProps) { const uniqueId = React.useId(); const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`; return (
{children}
); } ChartContainer.displayName = 'ChartContainer'; // ============================================ // CHART STYLE // ============================================ 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 (