Chart
neobrutal-ui/chartFreeComponent
neobrutal-ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by neobrutal-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://neobrutal-ui.andongmin.com/r/chart.jsonSource
1"use client";23import * as React from "react";4import * as RechartsPrimitive from "recharts";5import type { TooltipValueType } from "recharts";67import { cn } from "@/lib/utils";89// Format: { THEME_NAME: CSS_SELECTOR }10const THEMES = { light: "", dark: ".dark" } as const;1112const INITIAL_DIMENSION = { width: 320, height: 200 } as const;13type TooltipNameType = number | string;1415export type ChartConfig = Record<16 string,17 {18 label?: React.ReactNode;19 icon?: React.ComponentType;20 } & (21 | { color?: string; theme?: never }22 | { color?: never; theme: Record<keyof typeof THEMES, string> }23 )24>;2526type ChartContextProps = {27 config: ChartConfig;28};2930const ChartContext = React.createContext<ChartContextProps | null>(null);3132function useChart() {33 const context = React.useContext(ChartContext);3435 if (!context) {36 throw new Error("useChart must be used within a <ChartContainer />");37 }3839 return context;40}4142function ChartContainer({43 id,44 className,45 children,46 config,47 initialDimension = INITIAL_DIMENSION,48 ...props49}: React.ComponentProps<"div"> & {50 config: ChartConfig;51 children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];52 initialDimension?: {53 width: number;54 height: number;55 };56}) {57 const uniqueId = React.useId();58 const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;5960 return (61 <ChartContext.Provider value={{ config }}>62 <div63 data-slot="chart"64 data-chart={chartId}65 className={cn(66 "flex min-w-[232px] aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-[#80808080] [&_.recharts-curve.recharts-tooltip-cursor]:stroke-[#80808080] [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer_path]:[fill-opacity:1] [&_.recharts-layer_path]:[stroke-width:2] [&_.recharts-layer_path]:[stroke:var(--color-border)] [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-black [&_.recharts-polar-grid_[stroke='#ccc']]:dark:stroke-white [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-black [&_.recharts-reference-line_[stroke='#ccc']]:dark:stroke-white [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-border [&_.recharts-surface]:outline-hidden",67 className,68 )}69// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from neobrutal-ui
All 100 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | neobrutal-ui | Components | Free | 1 dep | |
| Alertalert | neobrutal-ui | Components | Free | no deps | |
| Alert dialogalert-dialog | neobrutal-ui | Components | Free | 1 dep | |
| Avataravatar | neobrutal-ui | Components | Free | 1 dep | |
| Badgebadge | neobrutal-ui | Components | Free | no deps | |
| Breadcrumbbreadcrumb | neobrutal-ui | Components | Free | 1 dep | |
| Buttonbutton | neobrutal-ui | Components | Free | 1 dep | |
| Calendarcalendar | neobrutal-ui | Components | Free | 1 dep |
