'use client'; import * as React from 'react'; import * as RechartsPrimitive from 'recharts'; import { cn } from '@gib/ui'; // Format: { THEME_NAME: CSS_SELECTOR } const THEMES = { light: '', dark: '.dark' } as const; export type ChartConfig = Record< string, { label?: React.ReactNode; icon?: React.ComponentType; } & ( | { color?: string; theme?: never } | { color?: never; theme: Record } ) >; interface ChartContextProps { config: ChartConfig; } const ChartContext = React.createContext(null); const useChart = () => { const context = React.useContext(ChartContext); if (!context) { throw new Error('useChart must be used within a '); } return context; }; const ChartContainer = ({ id, className, children, config, ...props }: React.ComponentProps<'div'> & { config: ChartConfig; children: React.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >['children']; }) => { const uniqueId = React.useId(); const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`; return (
{children}
); }; 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 (