recharts-chart
evilcharts/recharts-chartFreeComponent
EvilCharts publishes no description for this item.
Install it
npx shadcn@latest add https://evilcharts.com/r/recharts-chart.jsonSource
1"use client";23import * as RechartsPrimitive from "recharts";4import { cn } from "@/lib/utils";5import * as React from "react";67// Format: { THEME_NAME: CSS_SELECTOR }8const THEMES = { light: "", dark: ".dark" } as const;910type ThemeKey = keyof typeof THEMES;1112// All Keys are optional at first13type ThemeColorsBase = {14 [K in ThemeKey]?: string[];15};1617// Require at least one theme key18type AtLeastOneThemeColor = {19 [K in ThemeKey]: Required<Pick<ThemeColorsBase, K>> & Partial<Omit<ThemeColorsBase, K>>;20}[ThemeKey];2122const VALID_THEME_KEYS = Object.keys(THEMES) as ThemeKey[];2324// Validation for chart config colors at runtime25function validateChartConfigColors(config: ChartConfig): void {26 for (const [key, value] of Object.entries(config)) {27 if (value.colors) {28 const hasValidThemeKey = VALID_THEME_KEYS.some(29 (themeKey) => value.colors?.[themeKey] !== undefined,30 );3132 if (!hasValidThemeKey) {33 throw new Error(34 `[EvilCharts] Invalid chart config for "${key}": colors object must have at least one theme key (${VALID_THEME_KEYS.join(", ")}). Received empty object or invalid keys.`,35 );36 }37 }38 }39}4041export type ChartConfig = Record<42 string,43 {44 label?: React.ReactNode;45 icon?: React.ComponentType;46 colors?: AtLeastOneThemeColor;47 }48>;4950interface ChartContextProps {51 config: ChartConfig;52}5354const ChartContext = React.createContext<ChartContextProps | null>(null);5556export function useChart() {57 const context = React.useContext(ChartContext);5859 if (!context) {60 throw new Error("useChart must be used within a <ChartContainer />");61 }6263 return context;64}6566interface ChartContainerProps67 extends68 Omit<React.ComponentProps<"div">, "children">,69 Pick<70 React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>,71 | "initialDimension"72 | "aspect"73 | "debounce"74 | "minHeight"75 | "minWidth"76 | "maxHeight"77 | "height"78 | "width"79 | "onResize"80 | "children"81 > {82 config: ChartConfig;83 innerResponsiveContainerStyle?: React.ComponentProps<84 typeof RechartsPrimitive.ResponsiveContainer85 >["style"];86 /** Optional content rendered below the chart (e.g. EvilBrush) */87 footer?: React.ReactNode;88}8990function ChartContainer({91 id,92 config,93 initialDimension = { width: 320, height: 200 },94 className,95 children,96 footer,97 ...props98}: Readonly<ChartContainerProps>) {99 const uniqueId = React.useId();100// … truncated
What it pulls in
npm packages
Files it writes
More from EvilCharts
All 271 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| echarts-area-chartecharts-area-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-bar-chartecharts-bar-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-brushecharts-brush | EvilCharts | Components | Free | 1 dep | |
| echarts-chartecharts-chart | EvilCharts | Components | Free | 1 dep | |
| echarts-composed-chartecharts-composed-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-dotecharts-dot | EvilCharts | Components | Free | 1 dep | |
| echarts-legendecharts-legend | EvilCharts | Components | Free | no deps | |
| echarts-line-chartecharts-line-chart | EvilCharts | Components | Free | 2 deps |
