From d89d70f3c7a465e55cfc6253977a93134ca10044 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 16 Mar 2026 12:13:10 +0100 Subject: [PATCH] feat(01-01): install shadcn chart and collapsible primitives - Add chart.tsx with ChartContainer, ChartTooltip, ChartTooltipContent wrappers - Apply Recharts v3 initialDimension patch (shadcn-ui/ui#9892) - Add collapsible.tsx with Collapsible, CollapsibleTrigger, CollapsibleContent Co-Authored-By: Claude Opus 4.6 --- src/components/ui/chart.tsx | 357 ++++++++++++++++++++++++++++++ src/components/ui/collapsible.tsx | 31 +++ 2 files changed, 388 insertions(+) create mode 100644 src/components/ui/chart.tsx create mode 100644 src/components/ui/collapsible.tsx diff --git a/src/components/ui/chart.tsx b/src/components/ui/chart.tsx new file mode 100644 index 0000000..cd77e0f --- /dev/null +++ b/src/components/ui/chart.tsx @@ -0,0 +1,357 @@ +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 +} + +function 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 ( +