diff --git a/src/components/ui/chart.jsx b/src/components/ui/chart.jsx new file mode 100644 index 0000000..bcef106 --- /dev/null +++ b/src/components/ui/chart.jsx @@ -0,0 +1,309 @@ +"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" +} + +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 +} + +const ChartContainer = React.forwardRef(({ id, className, children, config, ...props }, ref) => { + const uniqueId = React.useId() + const chartId = `chart-${id || uniqueId.replace(/:/g, "")}` + + return ( + ( +
+ + + {children} + +
+
) + ); +}) +ChartContainer.displayName = "Chart" + +const ChartStyle = ({ + id, + config +}) => { + const colorConfig = Object.entries(config).filter(([, config]) => config.theme || config.color) + + if (!colorConfig.length) { + return null + } + + return ( + (