diff --git a/client/package.json b/client/package.json index dd936e8..bcd4c8b 100644 --- a/client/package.json +++ b/client/package.json @@ -51,7 +51,7 @@ "i18next": "^23.11.5", "i18next-browser-languagedetector": "^8.0.0", "joi": "^17.13.1", - "lucide-react": "^0.379.0", + "lucide-react": "^0.408.0", "react": "^18.2.0", "react-beautiful-dnd": "^13.1.1", "react-currency-input-field": "^3.8.0", @@ -64,7 +64,8 @@ "react-router-dom": "^6.23.1", "react-secure-storage": "^1.3.2", "react-toastify": "^10.0.5", - "react-wrap-balancer": "^1.1.1" + "react-wrap-balancer": "^1.1.1", + "recharts": "^2.12.7" }, "devDependencies": { "@tanstack/react-query-devtools": "^5.39.0", diff --git a/client/src/ui/chart.tsx b/client/src/ui/chart.tsx new file mode 100644 index 0000000..a21d77e --- /dev/null +++ b/client/src/ui/chart.tsx @@ -0,0 +1,363 @@ +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 +} + +const ChartContainer = React.forwardRef< + HTMLDivElement, + React.ComponentProps<"div"> & { + config: ChartConfig + children: React.ComponentProps< + typeof RechartsPrimitive.ResponsiveContainer + >["children"] + } +>(({ 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 }: { id: string; config: ChartConfig }) => { + const colorConfig = Object.entries(config).filter( + ([_, config]) => config.theme || config.color + ) + + if (!colorConfig.length) { + return null + } + + return ( +