shadcn-chart 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # shadcn-chart
2
+
3
+ [![npm version](https://img.shields.io/npm/v/shadcn-chart.svg)](https://www.npmjs.com/package/shadcn-chart)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ Beautiful, customizable chart components built with [shadcn/ui](https://ui.shadcn.com/) conventions and [Recharts](https://recharts.org/).
8
+
9
+ ## ✨ Features
10
+
11
+ - 📊 **5 Chart Types** - Area, Bar, Line, Pie, and Radial charts
12
+ - 🎨 **Multiple Variants** - Each chart has different display modes (stacked, gradient, interactive, etc.)
13
+ - 🌙 **Dark Mode Ready** - Built-in CSS variables for light/dark themes
14
+ - 📱 **Responsive** - Works on all screen sizes
15
+ - 🔧 **Highly Customizable** - Extensive props for fine-tuning
16
+ - 📦 **Tree-shakeable** - Only import what you need
17
+ - 💪 **TypeScript** - Full type definitions included
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install shadcn-chart
23
+ # or
24
+ yarn add shadcn-chart
25
+ # or
26
+ pnpm add shadcn-chart
27
+ ```
28
+
29
+ ### Peer Dependencies
30
+
31
+ ```bash
32
+ npm install react react-dom recharts lucide-react
33
+ ```
34
+
35
+ ## 🚀 Quick Start
36
+
37
+ ### 1. Import Styles
38
+
39
+ Add to your root layout or CSS entry point:
40
+
41
+ ```tsx
42
+ // Next.js: app/layout.tsx or pages/_app.tsx
43
+ // Vite: main.tsx
44
+ import 'shadcn-chart/styles';
45
+ ```
46
+
47
+ ### 2. Use Components
48
+
49
+ ```tsx
50
+ import { AreaChartComponent } from 'shadcn-chart';
51
+
52
+ const chartData = [
53
+ { month: "January", desktop: 186, mobile: 80 },
54
+ { month: "February", desktop: 305, mobile: 200 },
55
+ { month: "March", desktop: 237, mobile: 120 },
56
+ ];
57
+
58
+ const chartConfig = {
59
+ desktop: { label: "Desktop", color: "var(--chart-1)" },
60
+ mobile: { label: "Mobile", color: "var(--chart-2)" },
61
+ };
62
+
63
+ export default function MyChart() {
64
+ return (
65
+ <AreaChartComponent
66
+ title="Website Traffic"
67
+ description="Visitor statistics"
68
+ data={chartData}
69
+ chartConfig={chartConfig}
70
+ variant="gradient"
71
+ showLegend
72
+ />
73
+ );
74
+ }
75
+ ```
76
+
77
+ ## 📊 Components
78
+
79
+ ### AreaChartComponent
80
+
81
+ | Prop | Type | Default | Description |
82
+ |------|------|---------|-------------|
83
+ | `data` | `Array<Record<string, string \| number>>` | **required** | Chart data array |
84
+ | `chartConfig` | `ChartConfig` | **required** | Color and label configuration |
85
+ | `variant` | `'default' \| 'linear' \| 'step' \| 'stacked' \| 'stacked-expanded' \| 'gradient' \| 'legend' \| 'interactive'` | `'default'` | Display variant |
86
+ | `title` | `string` | - | Card title |
87
+ | `description` | `string` | - | Card description |
88
+ | `xAxisKey` | `string` | `'month'` | Data key for X-axis |
89
+ | `showGrid` | `boolean` | `true` | Show grid lines |
90
+ | `showTooltip` | `boolean` | `true` | Show tooltip on hover |
91
+ | `showLegend` | `boolean` | auto | Show chart legend |
92
+ | `showDots` | `boolean` | auto | Show data point dots |
93
+ | `useGradient` | `boolean` | auto | Use gradient fill |
94
+
95
+ ### BarChartComponent
96
+
97
+ | Prop | Type | Default | Description |
98
+ |------|------|---------|-------------|
99
+ | `data` | `Array<Record<string, string \| number>>` | **required** | Chart data array |
100
+ | `chartConfig` | `ChartConfig` | **required** | Color and label configuration |
101
+ | `variant` | `'default' \| 'horizontal' \| 'multiple' \| 'stacked' \| 'stacked-legend' \| 'label' \| 'negative' \| 'mixed' \| 'interactive'` | `'default'` | Display variant |
102
+ | `layout` | `'vertical' \| 'horizontal'` | auto | Bar orientation |
103
+ | `showLabels` | `boolean` | auto | Show value labels on bars |
104
+ | `barRadius` | `number \| [number, number, number, number]` | auto | Bar corner radius |
105
+
106
+ ### LineChartComponent
107
+
108
+ | Prop | Type | Default | Description |
109
+ |------|------|---------|-------------|
110
+ | `data` | `Array<Record<string, string \| number>>` | **required** | Chart data array |
111
+ | `chartConfig` | `ChartConfig` | **required** | Color and label configuration |
112
+ | `dot` | `boolean \| function` | `false` | Show/customize data points |
113
+ | `yAxisConfig` | `object` | - | Y-axis configuration |
114
+ | `toggleOptions` | `object` | - | Time period toggle buttons |
115
+
116
+ ### PieChartComponent
117
+
118
+ | Prop | Type | Default | Description |
119
+ |------|------|---------|-------------|
120
+ | `data` | `PieChartData[]` | **required** | Pie chart data with category, value, percentage |
121
+ | `chartConfig` | `ChartConfig` | **required** | Color and label configuration |
122
+ | `innerRadius` | `number` | `0` | Donut hole radius |
123
+ | `outerRadius` | `number` | `100` | Pie outer radius |
124
+ | `showActiveSection` | `boolean` | `false` | Animate active section on hover |
125
+ | `paddingAngle` | `number` | `0` | Gap between segments |
126
+
127
+ ### RadialChartShapeComponent
128
+
129
+ | Prop | Type | Default | Description |
130
+ |------|------|---------|-------------|
131
+ | `data` | `RadialChartData` | **required** | Single data object with percentage |
132
+ | `chartConfig` | `ChartConfig` | **required** | Color and label configuration |
133
+ | `centerLabel` | `string` | - | Label in center of chart |
134
+ | `innerRadius` | `number` | `80` | Inner radius |
135
+ | `outerRadius` | `number` | `130` | Outer radius |
136
+ | `animationDuration` | `number` | `2.5` | Animation duration in seconds |
137
+
138
+ ## 🎨 Theming
139
+
140
+ The package uses CSS variables for theming. Override these in your CSS:
141
+
142
+ ```css
143
+ :root {
144
+ --chart-1: oklch(0.646 0.222 41.116);
145
+ --chart-2: oklch(0.6 0.118 184.704);
146
+ --chart-3: oklch(0.398 0.07 227.392);
147
+ --chart-4: oklch(0.828 0.189 84.429);
148
+ --chart-5: oklch(0.769 0.188 70.08);
149
+ }
150
+
151
+ .dark {
152
+ --chart-1: oklch(0.488 0.243 264.376);
153
+ --chart-2: oklch(0.696 0.17 162.48);
154
+ --chart-3: oklch(0.769 0.188 70.08);
155
+ --chart-4: oklch(0.627 0.265 303.9);
156
+ --chart-5: oklch(0.645 0.246 16.439);
157
+ }
158
+ ```
159
+
160
+ ## ⚙️ Tailwind CSS Configuration
161
+
162
+ ### Tailwind v4
163
+
164
+ No extra configuration needed - just import the styles.
165
+
166
+ ### Tailwind v3
167
+
168
+ Add the package to your content paths:
169
+
170
+ ```js
171
+ // tailwind.config.js
172
+ module.exports = {
173
+ content: [
174
+ './src/**/*.{js,ts,jsx,tsx}',
175
+ './node_modules/shadcn-chart/dist/**/*.{js,mjs}',
176
+ ],
177
+ };
178
+ ```
179
+
180
+ ## 🌐 Framework Compatibility
181
+
182
+ | Framework | Status |
183
+ |-----------|--------|
184
+ | Next.js (App Router) | ✅ Supported |
185
+ | Next.js (Pages Router) | ✅ Supported |
186
+ | Vite | ✅ Supported |
187
+ | Create React App | ✅ Supported |
188
+ | Astro | ✅ Supported |
189
+ | Remix | ✅ Supported |
190
+ | TanStack Start | ✅ Supported |
191
+
192
+ ## 📄 License
193
+
194
+ MIT © [MnhTng](https://github.com/mnhtng)
195
+
196
+ ## 🤝 Contributing
197
+
198
+ Contributions are welcome! Please feel free to submit a Pull Request.
199
+
200
+ ## 📝 Changelog
201
+
202
+ See [GitHub Releases](https://github.com/mnhtng/shadcn-chart/releases) for changelog.
@@ -0,0 +1,288 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React$1 from 'react';
3
+ import React__default from 'react';
4
+ import * as RechartsPrimitive from 'recharts';
5
+ import { ClassValue } from 'clsx';
6
+
7
+ declare const THEMES: {
8
+ readonly light: "";
9
+ readonly dark: ".dark";
10
+ };
11
+ type ChartConfig = {
12
+ [k in string]: {
13
+ label?: React$1.ReactNode;
14
+ icon?: React$1.ComponentType;
15
+ } & ({
16
+ color?: string;
17
+ theme?: never;
18
+ } | {
19
+ color?: never;
20
+ theme: Record<keyof typeof THEMES, string>;
21
+ });
22
+ };
23
+ declare function ChartContainer({ id, className, children, config, ...props }: React$1.ComponentProps<"div"> & {
24
+ config: ChartConfig;
25
+ children: React$1.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
26
+ }): react_jsx_runtime.JSX.Element;
27
+ declare const ChartStyle: ({ id, config }: {
28
+ id: string;
29
+ config: ChartConfig;
30
+ }) => react_jsx_runtime.JSX.Element | null;
31
+ declare const ChartTooltip: typeof RechartsPrimitive.Tooltip;
32
+ declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }: React$1.ComponentProps<typeof RechartsPrimitive.Tooltip> & React$1.ComponentProps<"div"> & {
33
+ hideLabel?: boolean;
34
+ hideIndicator?: boolean;
35
+ indicator?: "line" | "dot" | "dashed";
36
+ nameKey?: string;
37
+ labelKey?: string;
38
+ }): react_jsx_runtime.JSX.Element | null;
39
+ declare const ChartLegend: typeof RechartsPrimitive.Legend;
40
+ declare function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: React$1.ComponentProps<"div"> & Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
41
+ hideIcon?: boolean;
42
+ nameKey?: string;
43
+ }): react_jsx_runtime.JSX.Element | null;
44
+
45
+ type AreaChartVariant = 'default' | 'linear' | 'step' | 'stacked' | 'stacked-expanded' | 'gradient' | 'legend' | 'interactive';
46
+ type AreaCurveType = 'monotone' | 'linear' | 'step' | 'stepBefore' | 'stepAfter' | 'natural' | 'basis';
47
+ interface AreaConfig {
48
+ dataKey: string;
49
+ fill?: string;
50
+ stroke?: string;
51
+ stackId?: string;
52
+ type?: AreaCurveType;
53
+ fillOpacity?: number;
54
+ }
55
+ interface AreaChartComponentProps {
56
+ title?: string;
57
+ description?: string;
58
+ data: Array<Record<string, string | number>>;
59
+ chartConfig: ChartConfig;
60
+ className?: string;
61
+ variant?: AreaChartVariant;
62
+ areas?: AreaConfig[];
63
+ xAxisKey?: string;
64
+ xAxisFormatter?: (value: string) => string;
65
+ yAxisConfig?: {
66
+ domain?: [number, number] | 'auto';
67
+ tickFormatter?: (value: number) => string;
68
+ hide?: boolean;
69
+ };
70
+ showGrid?: boolean;
71
+ showTooltip?: boolean;
72
+ showLegend?: boolean;
73
+ showDots?: boolean;
74
+ showActiveDot?: boolean;
75
+ useGradient?: boolean;
76
+ gradientOpacity?: {
77
+ start: number;
78
+ end: number;
79
+ };
80
+ margin?: {
81
+ top?: number;
82
+ right?: number;
83
+ bottom?: number;
84
+ left?: number;
85
+ };
86
+ footerContent?: {
87
+ mainText?: string;
88
+ subText?: string;
89
+ showTrending?: boolean;
90
+ trendingIcon?: React.ReactNode;
91
+ trendingColor?: string;
92
+ };
93
+ }
94
+ declare const AreaChartComponent: ({ title, description, data, chartConfig, className, variant, areas, xAxisKey, xAxisFormatter, yAxisConfig, showGrid, showTooltip, showLegend, showDots, showActiveDot, useGradient, gradientOpacity, margin, footerContent, }: AreaChartComponentProps) => react_jsx_runtime.JSX.Element;
95
+ declare const AreaChartExample: () => react_jsx_runtime.JSX.Element;
96
+
97
+ type BarChartVariant = 'default' | 'horizontal' | 'multiple' | 'stacked' | 'stacked-legend' | 'label' | 'negative' | 'mixed' | 'interactive';
98
+ interface BarConfig {
99
+ dataKey: string;
100
+ fill?: string;
101
+ radius?: number | [number, number, number, number];
102
+ stackId?: string;
103
+ name?: string;
104
+ }
105
+ interface BarChartComponentProps {
106
+ title?: string;
107
+ description?: string;
108
+ data: Array<Record<string, string | number>>;
109
+ chartConfig: ChartConfig;
110
+ className?: string;
111
+ variant?: BarChartVariant;
112
+ bars?: BarConfig[];
113
+ xAxisKey?: string;
114
+ xAxisFormatter?: (value: string) => string;
115
+ yAxisConfig?: {
116
+ dataKey?: string;
117
+ domain?: [number, number] | 'auto';
118
+ tickFormatter?: (value: number) => string;
119
+ hide?: boolean;
120
+ };
121
+ showGrid?: boolean;
122
+ showTooltip?: boolean;
123
+ showLegend?: boolean;
124
+ showLabels?: boolean;
125
+ labelPosition?: 'top' | 'center' | 'bottom' | 'inside' | 'insideTop' | 'insideBottom';
126
+ labelFormatter?: (value: number) => string;
127
+ tooltipNameKey?: string;
128
+ layout?: 'vertical' | 'horizontal';
129
+ margin?: {
130
+ top?: number;
131
+ right?: number;
132
+ bottom?: number;
133
+ left?: number;
134
+ };
135
+ barRadius?: number | [number, number, number, number];
136
+ barGap?: number;
137
+ barCategoryGap?: string | number;
138
+ positiveColor?: string;
139
+ negativeColor?: string;
140
+ footerContent?: {
141
+ mainText?: string;
142
+ subText?: string;
143
+ showTrending?: boolean;
144
+ trendingIcon?: React.ReactNode;
145
+ trendingColor?: string;
146
+ };
147
+ }
148
+ declare const BarChartComponent: ({ title, description, data, chartConfig, className, variant, bars, xAxisKey, xAxisFormatter, yAxisConfig, showGrid, showTooltip, showLegend, showLabels, labelPosition, labelFormatter, tooltipNameKey, layout, margin, barRadius, barGap, barCategoryGap, positiveColor, negativeColor, footerContent, }: BarChartComponentProps) => react_jsx_runtime.JSX.Element;
149
+ declare const BarChartExample: () => react_jsx_runtime.JSX.Element;
150
+
151
+ interface ToggleOption {
152
+ value: string;
153
+ label: string;
154
+ icon?: React__default.ReactNode;
155
+ }
156
+ interface LineChartComponentProps {
157
+ title?: string;
158
+ description?: string;
159
+ data: Array<Record<string, string | number>>;
160
+ chartConfig: ChartConfig;
161
+ xAxisKey?: string;
162
+ yAxisConfig?: {
163
+ domain?: [number, number] | "auto";
164
+ padding?: number;
165
+ tickCount?: number;
166
+ formatType?: 'auto' | 'full' | 'compact' | 'currency' | 'percentage';
167
+ customFormatter?: (value: number) => string;
168
+ tickFormatter?: (value: number) => string;
169
+ };
170
+ lines?: Array<{
171
+ dataKey: string;
172
+ stroke?: string;
173
+ strokeWidth?: number;
174
+ type?: "monotone" | "linear" | "step" | "stepBefore" | "stepAfter";
175
+ dot?: boolean;
176
+ }>;
177
+ dot?: boolean | ((props: any) => React__default.ReactElement);
178
+ margin?: {
179
+ top?: number;
180
+ right?: number;
181
+ bottom?: number;
182
+ left?: number;
183
+ };
184
+ footerContent?: {
185
+ mainText?: string;
186
+ subText?: string;
187
+ showTrending?: boolean;
188
+ trendingIcon?: React__default.ReactNode;
189
+ trendingColor?: string;
190
+ };
191
+ toggleOptions?: {
192
+ options: ToggleOption[];
193
+ currentValue: string;
194
+ onChange: (value: string) => void;
195
+ position?: "header-right" | "header-left";
196
+ };
197
+ className?: string;
198
+ }
199
+ declare function LineChartComponent({ title, description, data, chartConfig, xAxisKey, yAxisConfig, lines, dot, margin, footerContent, toggleOptions, className }: LineChartComponentProps): react_jsx_runtime.JSX.Element;
200
+ interface UserActivityChartProps {
201
+ className?: string;
202
+ }
203
+ declare const LineChartExample: ({ className }: UserActivityChartProps) => react_jsx_runtime.JSX.Element;
204
+
205
+ interface PieChartData {
206
+ category: string;
207
+ value: number;
208
+ percentage: number;
209
+ fill?: string;
210
+ [key: string]: unknown;
211
+ }
212
+ interface PieChartProps {
213
+ title?: string;
214
+ description?: string;
215
+ data: PieChartData[];
216
+ chartConfig: ChartConfig;
217
+ className?: string;
218
+ dataKey?: string;
219
+ nameKey?: string;
220
+ legendKey?: string;
221
+ innerRadius?: number;
222
+ outerRadius?: number;
223
+ cornerRadius?: number;
224
+ paddingAngle?: number;
225
+ strokeWidth?: number;
226
+ stroke?: string;
227
+ animationDuration?: number;
228
+ enableAnimation?: boolean;
229
+ showLegend?: boolean;
230
+ showTooltip?: boolean;
231
+ showActiveSection?: boolean;
232
+ footerContent?: {
233
+ mainText?: string;
234
+ subText?: string;
235
+ showTrending?: boolean;
236
+ trendingColor?: string;
237
+ trendingIcon?: React.ReactNode;
238
+ };
239
+ }
240
+ declare const PieChartComponent: ({ title, description, data, chartConfig, className, dataKey, nameKey, legendKey, innerRadius, outerRadius, strokeWidth, cornerRadius, paddingAngle, stroke, showLegend, showTooltip, showActiveSection, footerContent }: PieChartProps) => react_jsx_runtime.JSX.Element;
241
+ declare const PieChartExample: () => react_jsx_runtime.JSX.Element;
242
+
243
+ interface RadialChartData {
244
+ category: string;
245
+ value: number;
246
+ percentage: number;
247
+ fill?: string;
248
+ }
249
+ interface RadialChartProps {
250
+ title?: string;
251
+ description?: string;
252
+ data: RadialChartData;
253
+ chartConfig: ChartConfig;
254
+ centerLabel?: string;
255
+ footerContent?: {
256
+ mainText?: string;
257
+ subText?: string;
258
+ showTrending?: boolean;
259
+ trendingColor?: string;
260
+ trendingIcon?: React.ReactNode;
261
+ };
262
+ innerRadius?: number;
263
+ outerRadius?: number;
264
+ cornerRadius?: number;
265
+ startAngle?: number;
266
+ className?: string;
267
+ numberSize?: 'sm' | 'md' | 'lg' | 'xl';
268
+ labelSize?: 'xs' | 'sm' | 'md';
269
+ animationDuration?: number;
270
+ centerOffset?: {
271
+ x?: number;
272
+ y?: number;
273
+ };
274
+ }
275
+ declare const RadialChartShapeComponent: ({ title, description, data, centerLabel, footerContent, chartConfig, innerRadius, outerRadius, cornerRadius, startAngle, className, numberSize, labelSize, animationDuration, centerOffset }: RadialChartProps) => react_jsx_runtime.JSX.Element;
276
+ declare const RadialChartExample: () => react_jsx_runtime.JSX.Element;
277
+
278
+ declare function Card({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
279
+ declare function CardHeader({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
280
+ declare function CardTitle({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
281
+ declare function CardDescription({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
282
+ declare function CardAction({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
283
+ declare function CardContent({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
284
+ declare function CardFooter({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
285
+
286
+ declare function cn(...inputs: ClassValue[]): string;
287
+
288
+ export { AreaChartComponent, type AreaChartComponentProps, AreaChartExample, type AreaChartVariant, type AreaConfig, type AreaCurveType, BarChartComponent, type BarChartComponentProps, BarChartExample, type BarChartVariant, type BarConfig, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, LineChartComponent, LineChartExample, PieChartComponent, type PieChartData, PieChartExample, type PieChartProps, type RadialChartData, RadialChartExample, type RadialChartProps, RadialChartShapeComponent, cn };