Chart (Tailwind)
roi-ui/chart-tailwindFreeItem
Composable chart components for building any type of data visualization with Recharts primitives.
Install it
npx shadcn@latest add https://roiui.com/r/chart-tailwind.jsonSource
1"use client";23import {4 type ComponentProps,5 type ComponentType,6 type CSSProperties,7 createContext,8 type ReactNode,9 useContext,10 useId,11 useMemo,12} from "react";13import { Legend, ResponsiveContainer, Tooltip } from "recharts";14import { cn } from "@/lib/utils";1516const THEMES = { light: "", dark: ".dark" } as const;1718export type ChartConfig = {19 [k in string]: {20 label?: ReactNode;21 icon?: ComponentType;22 } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> });23};2425type ChartContextProps = {26 config: ChartConfig;27};2829const ChartContext = createContext<ChartContextProps | null>(null);3031function useChart() {32 const context = useContext(ChartContext);3334 if (!context) {35 throw new Error("useChart must be used within a <ChartContainer />");36 }3738 return context;39}4041function ChartContainer({42 id,43 className,44 children,45 config,46 ...props47}: ComponentProps<"div"> & {48 config: ChartConfig;49 children: ComponentProps<typeof ResponsiveContainer>["children"];50}) {51 const uniqueId = useId();52 const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;5354 return (55 <ChartContext.Provider value={{ config }}>56 <div57 {...props}58 className={cn("flex h-full w-full justify-center text-xs", className)}59 data-chart={chartId}60 data-slot="chart"61 >62 <ChartStyle config={config} id={chartId} />63 <ResponsiveContainer>{children}</ResponsiveContainer>64 <style global jsx>{`65 [data-chart="${chartId}"] .recharts-cartesian-axis-tick text {66 fill: var(--muted-foreground);67 }68 [data-chart="${chartId}"] .recharts-cartesian-grid line {69 stroke: oklch(from var(--border) l c h / 0.3);70 }71 [data-chart="${chartId}"] .recharts-curve.recharts-tooltip-cursor {72 stroke: var(--border);73 }74 [data-chart="${chartId}"] .recharts-polar-grid line {75 stroke: var(--border);76 }77 [data-chart="${chartId}"] .recharts-radial-bar-background-sector {78 fill: var(--muted);79 }80 [data-chart="${chartId}"] .recharts-rectangle.recharts-tooltip-cursor {81 fill: var(--muted);82 opacity: 0.3;83 }84 [data-chart="${chartId}"] .recharts-reference-line line {85 stroke: var(--border);86 }87 [data-chart="${chartId}"] .recharts-dot[stroke="#fff"] {88// … truncated
What it pulls in
npm packages
Files it writes
More from Roi UI
All 123 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | Roi UI | Other | Free | no deps · 2 files | |
| Accordion (Tailwind)accordion-tailwind | Roi UI | Other | Free | no deps | |
| AI Chatai-chat | Roi UI | Other | Free | no deps · 2 files | |
| AI Chat (Tailwind)ai-chat-tailwind | Roi UI | Other | Free | no deps | |
| Alertalert | Roi UI | Other | Free | 1 dep · 2 files | |
| Alert Dialogalert-dialog | Roi UI | Other | Free | no deps · 2 files | |
| Alert Dialog (Tailwind)alert-dialog-tailwind | Roi UI | Other | Free | no deps | |
| Alert (Tailwind)alert-tailwind | Roi UI | Other | Free | 1 dep |
