BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/optics/chart

Chart

optics/chart
FreeComponent

Beautiful charts built with Recharts.

See it running

Open the demo on optics

optics.agusmayol.com.ar/components/chart
Open
This registry sends X-Frame-Options, so its page cannot be embedded here. The link is the same page the frame would have shown.

Install it

npx shadcn@latest add https://optics.agusmayol.com.ar/r/chart.json

Source

registry/optics/chart.jsxoptics.agusmayol.com.ar/r/chart.json · first 6 KB
1"use client";
2import * as React from "react";
3import * as RechartsPrimitive from "recharts";
4
5import { cn } from "@/lib/utils";
6
7// Format: { THEME_NAME: CSS_SELECTOR }
8const THEMES = {
9 light: "",
10 dark: ".dark",
11};
12
13const ChartContext = React.createContext(null);
14
15function useChart() {
16 const context = React.useContext(ChartContext);
17
18 if (!context) {
19 throw new Error("useChart must be used within a <ChartContainer />");
20 }
21
22 return context;
23}
24
25function ChartContainer({
26 id = undefined,
27 className = "",
28 children = null,
29 config = {},
30 ...props
31}) {
32 const uniqueId = React.useId();
33 const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
34
35 return (
36 <ChartContext.Provider value={{ config }}>
37 <div
38 data-slot="chart"
39 data-chart={chartId}
40 className={cn(
41 "[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
42 className,
43 )}
44 {...props}
45 >
46 <ChartStyle id={chartId} config={config} />
47 <RechartsPrimitive.ResponsiveContainer>
48 {children}
49 </RechartsPrimitive.ResponsiveContainer>
50 </div>
51 </ChartContext.Provider>
52 );
53}
54
55const ChartStyle = ({ id = "", config = {} }) => {
56 const colorConfig = Object.entries(config).filter(
57 ([, config]) => config.theme || config.color,
58 );
59
60 if (!colorConfig.length) {
61 return null;
62 }
63
64 return (
65 <style
66 dangerouslySetInnerHTML={{
67 __html: Object.entries(THEMES)
68 .map(
69 ([theme, prefix]) => `
70${prefix} [data-chart=${id}] {
71${colorConfig
72 .map(([key, itemConfig]) => {
73 const color = itemConfig.theme?.[theme] || itemConfig.color;
74 return color ? ` --color-${key}: ${color};` : null;
75 })
76 .join("\n")}
77}
78`,
79 )
80 .join("\n"),
81 }}
82 />
83 );
84};
85
86const ChartTooltip = RechartsPrimitive.Tooltip;
87
88function ChartTooltipContent({
89 active = false,
90 payload = [],
91 className = "",
92 indicator = "dot",
93 hideLabel = false,
94 hideIndicator = false,
95// … truncated

What it pulls in

npm packages

  • recharts
  • clsx
  • tailwind-merge

Other registry items

  • https://optics.agusmayol.com.ar/r/utils.json

Files it writes

  • registry/optics/chart.jsx

Facts

Registry
optics
Type
registry:component
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-04
Last confirmed
today

Go to the source

Docs on optics optics.agusmayol.com.ar AgusMayol/optics on GitHub Raw registry item This item as JSON

More from optics

All 79 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AccordionaccordionopticsComponentsFree5 deps
AlertalertopticsComponentsFree4 deps
Alert Dialogalert-dialogopticsComponentsFree4 deps
Aspect Ratioaspect-ratioopticsComponentsFree2 deps
Auto Heightauto-heightopticsComponentsFree3 deps
AvataravataropticsComponentsFree3 deps
BadgebadgeopticsComponentsFree4 deps
BreadcrumbbreadcrumbopticsComponentsFree4 deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex