@nucleux/chart 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nucleux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @nucleux/chart
2
+
3
+ Composable chart primitives — Nucleux agentic UI for React.
4
+
5
+ Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @nucleux/chart @nucleux/tokens
11
+ ```
12
+
13
+ `react` / `react-dom` are peer dependencies.
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { Chart } from "@nucleux/chart";
19
+ ```
20
+
21
+ Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
22
+ and the Tailwind preset from `@nucleux/tokens/preset`.
23
+
24
+ ## License
25
+
26
+ MIT © Nucleux
package/dist/index.cjs ADDED
@@ -0,0 +1,120 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var React = require('react');
5
+ var recharts = require('recharts');
6
+ var utils = require('@nucleux/utils');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
28
+
29
+ // src/index.tsx
30
+ var ChartTooltip = recharts.Tooltip;
31
+ var ChartLegend = recharts.Legend;
32
+ var ChartContainer = React__namespace.forwardRef(
33
+ ({ config, className, children, style, ...props }, ref) => {
34
+ const colorVars = React__namespace.useMemo(() => {
35
+ const vars = {};
36
+ for (const [key, cfg] of Object.entries(config)) {
37
+ if (cfg.color) vars[`--color-${key}`] = cfg.color;
38
+ }
39
+ return vars;
40
+ }, [config]);
41
+ return /* @__PURE__ */ jsxRuntime.jsx(
42
+ "div",
43
+ {
44
+ ref,
45
+ "data-chart": "",
46
+ className: utils.cn(
47
+ "flex aspect-video justify-center text-xs [&_.recharts-cartesian-grid_line]:stroke-border/50 [&_.recharts-text]:fill-muted-foreground",
48
+ className
49
+ ),
50
+ style: { ...colorVars, ...style },
51
+ ...props,
52
+ children: /* @__PURE__ */ jsxRuntime.jsx(recharts.ResponsiveContainer, { width: "100%", height: "100%", children })
53
+ }
54
+ );
55
+ }
56
+ );
57
+ ChartContainer.displayName = "ChartContainer";
58
+ var ChartTooltipContent = React__namespace.forwardRef(
59
+ ({ active, payload, label, config }, ref) => {
60
+ if (!active || !payload?.length) return null;
61
+ return /* @__PURE__ */ jsxRuntime.jsxs(
62
+ "div",
63
+ {
64
+ ref,
65
+ className: "min-w-32 rounded-lg border border-border bg-background px-3 py-2 text-sm shadow-md",
66
+ children: [
67
+ label != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-1 font-medium text-foreground", children: label }),
68
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-1", children: payload.map((item, i) => {
69
+ const key = String(item.dataKey ?? item.name ?? i);
70
+ const name = config?.[key]?.label ?? item.name ?? key;
71
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3", children: [
72
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5 text-muted-foreground", children: [
73
+ /* @__PURE__ */ jsxRuntime.jsx(
74
+ "span",
75
+ {
76
+ "aria-hidden": true,
77
+ className: "h-2 w-2 rounded-[2px]",
78
+ style: { background: item.color ?? `var(--color-${key})` }
79
+ }
80
+ ),
81
+ name
82
+ ] }),
83
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium tabular-nums text-foreground", children: item.value })
84
+ ] }, i);
85
+ }) })
86
+ ]
87
+ }
88
+ );
89
+ }
90
+ );
91
+ ChartTooltipContent.displayName = "ChartTooltipContent";
92
+ var ChartLegendContent = React__namespace.forwardRef(
93
+ ({ payload, config }, ref) => {
94
+ if (!payload?.length) return null;
95
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: "flex flex-wrap items-center justify-center gap-4 pt-3", children: payload.map((item, i) => {
96
+ const key = String(item.dataKey ?? item.value ?? i);
97
+ const name = config?.[key]?.label ?? item.value ?? key;
98
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
99
+ /* @__PURE__ */ jsxRuntime.jsx(
100
+ "span",
101
+ {
102
+ "aria-hidden": true,
103
+ className: "h-2 w-2 rounded-[2px]",
104
+ style: { background: item.color ?? `var(--color-${key})` }
105
+ }
106
+ ),
107
+ name
108
+ ] }, i);
109
+ }) });
110
+ }
111
+ );
112
+ ChartLegendContent.displayName = "ChartLegendContent";
113
+
114
+ exports.ChartContainer = ChartContainer;
115
+ exports.ChartLegend = ChartLegend;
116
+ exports.ChartLegendContent = ChartLegendContent;
117
+ exports.ChartTooltip = ChartTooltip;
118
+ exports.ChartTooltipContent = ChartTooltipContent;
119
+ //# sourceMappingURL=index.cjs.map
120
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["Tooltip","Legend","React","jsx","cn","ResponsiveContainer","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,IAAM,YAAA,GAAeA;AAErB,IAAM,WAAA,GAAcC;AAYpB,IAAM,cAAA,GAAuBC,gBAAA,CAAA,UAAA;AAAA,EAClC,CAAC,EAAE,MAAA,EAAQ,SAAA,EAAW,UAAU,KAAA,EAAO,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AACzD,IAAA,MAAM,SAAA,GAAkBA,yBAAQ,MAAM;AACpC,MAAA,MAAM,OAA+B,EAAC;AACtC,MAAA,KAAA,MAAW,CAAC,GAAA,EAAK,GAAG,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AAC/C,QAAA,IAAI,IAAI,KAAA,EAAO,IAAA,CAAK,WAAW,GAAG,CAAA,CAAE,IAAI,GAAA,CAAI,KAAA;AAAA,MAC9C;AACA,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AAEX,IAAA,uBACEC,cAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,YAAA,EAAW,EAAA;AAAA,QACX,SAAA,EAAWC,QAAA;AAAA,UACT,sIAAA;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A,SAC3D;AAAA,QACC;AAAA,OAAA,EAAA,EANQ,CAOX,CAAA;AAAA,IAEJ,CAAC,CAAA,EACH,CAAA;AAAA,EAEJ;AACF;AACA,kBAAA,CAAmB,WAAA,GAAc,oBAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { Legend, ResponsiveContainer, Tooltip } from \"recharts\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface ChartSeriesConfig {\n label?: React.ReactNode;\n /** CSS color; exposed to children as `var(--color-<key>)`. */\n color?: string;\n}\nexport type ChartConfig = Record<string, ChartSeriesConfig>;\n\n/** Re-exported recharts Tooltip — pair with {@link ChartTooltipContent}. */\nexport const ChartTooltip = Tooltip;\n/** Re-exported recharts Legend — pair with {@link ChartLegendContent}. */\nexport const ChartLegend = Legend;\n\nexport interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {\n config: ChartConfig;\n /** A single recharts chart element (BarChart, LineChart, …). */\n children: React.ReactElement;\n}\n\n/**\n * Wraps a recharts chart in a responsive, token-aware container. Each config key\n * becomes a `--color-<key>` CSS variable for series `fill`/`stroke`.\n */\nexport const ChartContainer = React.forwardRef<HTMLDivElement, ChartContainerProps>(\n ({ config, className, children, style, ...props }, ref) => {\n const colorVars = React.useMemo(() => {\n const vars: Record<string, string> = {};\n for (const [key, cfg] of Object.entries(config)) {\n if (cfg.color) vars[`--color-${key}`] = cfg.color;\n }\n return vars;\n }, [config]);\n\n return (\n <div\n ref={ref}\n data-chart=\"\"\n className={cn(\n \"flex aspect-video justify-center text-xs [&_.recharts-cartesian-grid_line]:stroke-border/50 [&_.recharts-text]:fill-muted-foreground\",\n className,\n )}\n style={{ ...colorVars, ...style }}\n {...props}\n >\n <ResponsiveContainer width=\"100%\" height=\"100%\">\n {children}\n </ResponsiveContainer>\n </div>\n );\n },\n);\nChartContainer.displayName = \"ChartContainer\";\n\ninterface TooltipPayloadItem {\n name?: string | number;\n value?: string | number;\n color?: string;\n dataKey?: string | number;\n}\n\nexport interface ChartTooltipContentProps {\n active?: boolean;\n payload?: TooltipPayloadItem[];\n label?: React.ReactNode;\n config?: ChartConfig;\n}\n\n/** A tokenized tooltip body for recharts. Pass to `<ChartTooltip content={…} />`. */\nexport const ChartTooltipContent = React.forwardRef<HTMLDivElement, ChartTooltipContentProps>(\n ({ active, payload, label, config }, ref) => {\n if (!active || !payload?.length) return null;\n return (\n <div\n ref={ref}\n className=\"min-w-32 rounded-lg border border-border bg-background px-3 py-2 text-sm shadow-md\"\n >\n {label != null && <div className=\"mb-1 font-medium text-foreground\">{label}</div>}\n <div className=\"flex flex-col gap-1\">\n {payload.map((item, i) => {\n const key = String(item.dataKey ?? item.name ?? i);\n const name = config?.[key]?.label ?? item.name ?? key;\n return (\n <div key={i} className=\"flex items-center justify-between gap-3\">\n <span className=\"flex items-center gap-1.5 text-muted-foreground\">\n <span\n aria-hidden\n className=\"h-2 w-2 rounded-[2px]\"\n style={{ background: item.color ?? `var(--color-${key})` }}\n />\n {name}\n </span>\n <span className=\"font-medium tabular-nums text-foreground\">{item.value}</span>\n </div>\n );\n })}\n </div>\n </div>\n );\n },\n);\nChartTooltipContent.displayName = \"ChartTooltipContent\";\n\ninterface LegendPayloadItem {\n value?: string | number;\n color?: string;\n dataKey?: string | number;\n}\n\nexport interface ChartLegendContentProps {\n payload?: LegendPayloadItem[];\n config?: ChartConfig;\n}\n\n/** A tokenized legend for recharts. Pass to `<ChartLegend content={…} />`. */\nexport const ChartLegendContent = React.forwardRef<HTMLDivElement, ChartLegendContentProps>(\n ({ payload, config }, ref) => {\n if (!payload?.length) return null;\n return (\n <div ref={ref} className=\"flex flex-wrap items-center justify-center gap-4 pt-3\">\n {payload.map((item, i) => {\n const key = String(item.dataKey ?? item.value ?? i);\n const name = config?.[key]?.label ?? item.value ?? key;\n return (\n <span key={i} className=\"flex items-center gap-1.5 text-xs text-muted-foreground\">\n <span\n aria-hidden\n className=\"h-2 w-2 rounded-[2px]\"\n style={{ background: item.color ?? `var(--color-${key})` }}\n />\n {name}\n </span>\n );\n })}\n </div>\n );\n },\n);\nChartLegendContent.displayName = \"ChartLegendContent\";\n"]}
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import { Legend, Tooltip } from 'recharts';
3
+
4
+ interface ChartSeriesConfig {
5
+ label?: React.ReactNode;
6
+ /** CSS color; exposed to children as `var(--color-<key>)`. */
7
+ color?: string;
8
+ }
9
+ type ChartConfig = Record<string, ChartSeriesConfig>;
10
+ /** Re-exported recharts Tooltip — pair with {@link ChartTooltipContent}. */
11
+ declare const ChartTooltip: typeof Tooltip;
12
+ /** Re-exported recharts Legend — pair with {@link ChartLegendContent}. */
13
+ declare const ChartLegend: typeof Legend;
14
+ interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {
15
+ config: ChartConfig;
16
+ /** A single recharts chart element (BarChart, LineChart, …). */
17
+ children: React.ReactElement;
18
+ }
19
+ /**
20
+ * Wraps a recharts chart in a responsive, token-aware container. Each config key
21
+ * becomes a `--color-<key>` CSS variable for series `fill`/`stroke`.
22
+ */
23
+ declare const ChartContainer: React.ForwardRefExoticComponent<ChartContainerProps & React.RefAttributes<HTMLDivElement>>;
24
+ interface TooltipPayloadItem {
25
+ name?: string | number;
26
+ value?: string | number;
27
+ color?: string;
28
+ dataKey?: string | number;
29
+ }
30
+ interface ChartTooltipContentProps {
31
+ active?: boolean;
32
+ payload?: TooltipPayloadItem[];
33
+ label?: React.ReactNode;
34
+ config?: ChartConfig;
35
+ }
36
+ /** A tokenized tooltip body for recharts. Pass to `<ChartTooltip content={…} />`. */
37
+ declare const ChartTooltipContent: React.ForwardRefExoticComponent<ChartTooltipContentProps & React.RefAttributes<HTMLDivElement>>;
38
+ interface LegendPayloadItem {
39
+ value?: string | number;
40
+ color?: string;
41
+ dataKey?: string | number;
42
+ }
43
+ interface ChartLegendContentProps {
44
+ payload?: LegendPayloadItem[];
45
+ config?: ChartConfig;
46
+ }
47
+ /** A tokenized legend for recharts. Pass to `<ChartLegend content={…} />`. */
48
+ declare const ChartLegendContent: React.ForwardRefExoticComponent<ChartLegendContentProps & React.RefAttributes<HTMLDivElement>>;
49
+
50
+ export { type ChartConfig, ChartContainer, type ChartContainerProps, ChartLegend, ChartLegendContent, type ChartLegendContentProps, type ChartSeriesConfig, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps };
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import { Legend, Tooltip } from 'recharts';
3
+
4
+ interface ChartSeriesConfig {
5
+ label?: React.ReactNode;
6
+ /** CSS color; exposed to children as `var(--color-<key>)`. */
7
+ color?: string;
8
+ }
9
+ type ChartConfig = Record<string, ChartSeriesConfig>;
10
+ /** Re-exported recharts Tooltip — pair with {@link ChartTooltipContent}. */
11
+ declare const ChartTooltip: typeof Tooltip;
12
+ /** Re-exported recharts Legend — pair with {@link ChartLegendContent}. */
13
+ declare const ChartLegend: typeof Legend;
14
+ interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {
15
+ config: ChartConfig;
16
+ /** A single recharts chart element (BarChart, LineChart, …). */
17
+ children: React.ReactElement;
18
+ }
19
+ /**
20
+ * Wraps a recharts chart in a responsive, token-aware container. Each config key
21
+ * becomes a `--color-<key>` CSS variable for series `fill`/`stroke`.
22
+ */
23
+ declare const ChartContainer: React.ForwardRefExoticComponent<ChartContainerProps & React.RefAttributes<HTMLDivElement>>;
24
+ interface TooltipPayloadItem {
25
+ name?: string | number;
26
+ value?: string | number;
27
+ color?: string;
28
+ dataKey?: string | number;
29
+ }
30
+ interface ChartTooltipContentProps {
31
+ active?: boolean;
32
+ payload?: TooltipPayloadItem[];
33
+ label?: React.ReactNode;
34
+ config?: ChartConfig;
35
+ }
36
+ /** A tokenized tooltip body for recharts. Pass to `<ChartTooltip content={…} />`. */
37
+ declare const ChartTooltipContent: React.ForwardRefExoticComponent<ChartTooltipContentProps & React.RefAttributes<HTMLDivElement>>;
38
+ interface LegendPayloadItem {
39
+ value?: string | number;
40
+ color?: string;
41
+ dataKey?: string | number;
42
+ }
43
+ interface ChartLegendContentProps {
44
+ payload?: LegendPayloadItem[];
45
+ config?: ChartConfig;
46
+ }
47
+ /** A tokenized legend for recharts. Pass to `<ChartLegend content={…} />`. */
48
+ declare const ChartLegendContent: React.ForwardRefExoticComponent<ChartLegendContentProps & React.RefAttributes<HTMLDivElement>>;
49
+
50
+ export { type ChartConfig, ChartContainer, type ChartContainerProps, ChartLegend, ChartLegendContent, type ChartLegendContentProps, type ChartSeriesConfig, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps };
package/dist/index.js ADDED
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { ResponsiveContainer, Legend, Tooltip } from 'recharts';
4
+ import { cn } from '@nucleux/utils';
5
+ import { jsx, jsxs } from 'react/jsx-runtime';
6
+
7
+ // src/index.tsx
8
+ var ChartTooltip = Tooltip;
9
+ var ChartLegend = Legend;
10
+ var ChartContainer = React.forwardRef(
11
+ ({ config, className, children, style, ...props }, ref) => {
12
+ const colorVars = React.useMemo(() => {
13
+ const vars = {};
14
+ for (const [key, cfg] of Object.entries(config)) {
15
+ if (cfg.color) vars[`--color-${key}`] = cfg.color;
16
+ }
17
+ return vars;
18
+ }, [config]);
19
+ return /* @__PURE__ */ jsx(
20
+ "div",
21
+ {
22
+ ref,
23
+ "data-chart": "",
24
+ className: cn(
25
+ "flex aspect-video justify-center text-xs [&_.recharts-cartesian-grid_line]:stroke-border/50 [&_.recharts-text]:fill-muted-foreground",
26
+ className
27
+ ),
28
+ style: { ...colorVars, ...style },
29
+ ...props,
30
+ children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children })
31
+ }
32
+ );
33
+ }
34
+ );
35
+ ChartContainer.displayName = "ChartContainer";
36
+ var ChartTooltipContent = React.forwardRef(
37
+ ({ active, payload, label, config }, ref) => {
38
+ if (!active || !payload?.length) return null;
39
+ return /* @__PURE__ */ jsxs(
40
+ "div",
41
+ {
42
+ ref,
43
+ className: "min-w-32 rounded-lg border border-border bg-background px-3 py-2 text-sm shadow-md",
44
+ children: [
45
+ label != null && /* @__PURE__ */ jsx("div", { className: "mb-1 font-medium text-foreground", children: label }),
46
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-1", children: payload.map((item, i) => {
47
+ const key = String(item.dataKey ?? item.name ?? i);
48
+ const name = config?.[key]?.label ?? item.name ?? key;
49
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
50
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5 text-muted-foreground", children: [
51
+ /* @__PURE__ */ jsx(
52
+ "span",
53
+ {
54
+ "aria-hidden": true,
55
+ className: "h-2 w-2 rounded-[2px]",
56
+ style: { background: item.color ?? `var(--color-${key})` }
57
+ }
58
+ ),
59
+ name
60
+ ] }),
61
+ /* @__PURE__ */ jsx("span", { className: "font-medium tabular-nums text-foreground", children: item.value })
62
+ ] }, i);
63
+ }) })
64
+ ]
65
+ }
66
+ );
67
+ }
68
+ );
69
+ ChartTooltipContent.displayName = "ChartTooltipContent";
70
+ var ChartLegendContent = React.forwardRef(
71
+ ({ payload, config }, ref) => {
72
+ if (!payload?.length) return null;
73
+ return /* @__PURE__ */ jsx("div", { ref, className: "flex flex-wrap items-center justify-center gap-4 pt-3", children: payload.map((item, i) => {
74
+ const key = String(item.dataKey ?? item.value ?? i);
75
+ const name = config?.[key]?.label ?? item.value ?? key;
76
+ return /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
77
+ /* @__PURE__ */ jsx(
78
+ "span",
79
+ {
80
+ "aria-hidden": true,
81
+ className: "h-2 w-2 rounded-[2px]",
82
+ style: { background: item.color ?? `var(--color-${key})` }
83
+ }
84
+ ),
85
+ name
86
+ ] }, i);
87
+ }) });
88
+ }
89
+ );
90
+ ChartLegendContent.displayName = "ChartLegendContent";
91
+
92
+ export { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent };
93
+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Ac,qBAAA;AAc3B,IAAM,kBAAA,GAA2B,KAAA,CAAA,UAAA;AAAA,EACtC,CAAC,EAAE,OAAA,EAAS,MAAA,IAAU,GAAA,KAAQ;AAC5B,IAAA,IAAI,CAAC,OAAA,EAAS,MAAA,EAAQ,OAAO,IAAA;AAC7B,IAAA,uBACE,GAAA,CAAC,SAAI,GAAA,EAAU,SAAA,EAAU,yDACtB,QAAA,EAAA,OAAA,CAAQ,GAAA,CAAI,CAAC,IAAA,EAAM,CAAA,KAAM;AACxB,MAAA,MAAM,MAAM,MAAA,CAAO,IAAA,CAAK,OAAA,IAAW,IAAA,CAAK,SAAS,CAAC,CAAA;AAClD,MAAA,MAAM,OAAO,MAAA,GAAS,GAAG,CAAA,EAAG,KAAA,IAAS,KAAK,KAAA,IAAS,GAAA;AACnD,MAAA,uBACE,IAAA,CAAC,MAAA,EAAA,EAAa,SAAA,EAAU,yDAAA,EACtB,QAAA,EAAA;AAAA,wBAAA,GAAA;AAAA,UAAC,MAAA;AAAA,UAAA;AAAA,YACC,aAAA,EAAW,IAAA;AAAA,YACX,SAAA,EAAU,uBAAA;AAAA,YACV,OAAO,EAAE,UAAA,EAAY,KAAK,KAAA,IAAS,CAAA,YAAA,EAAe,GAAG,CAAA,CAAA,CAAA;AAAI;AAAA,SAC3D;AAAA,QACC;AAAA,OAAA,EAAA,EANQ,CAOX,CAAA;AAAA,IAEJ,CAAC,CAAA,EACH,CAAA;AAAA,EAEJ;AACF;AACA,kBAAA,CAAmB,WAAA,GAAc,oBAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { Legend, ResponsiveContainer, Tooltip } from \"recharts\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface ChartSeriesConfig {\n label?: React.ReactNode;\n /** CSS color; exposed to children as `var(--color-<key>)`. */\n color?: string;\n}\nexport type ChartConfig = Record<string, ChartSeriesConfig>;\n\n/** Re-exported recharts Tooltip — pair with {@link ChartTooltipContent}. */\nexport const ChartTooltip = Tooltip;\n/** Re-exported recharts Legend — pair with {@link ChartLegendContent}. */\nexport const ChartLegend = Legend;\n\nexport interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {\n config: ChartConfig;\n /** A single recharts chart element (BarChart, LineChart, …). */\n children: React.ReactElement;\n}\n\n/**\n * Wraps a recharts chart in a responsive, token-aware container. Each config key\n * becomes a `--color-<key>` CSS variable for series `fill`/`stroke`.\n */\nexport const ChartContainer = React.forwardRef<HTMLDivElement, ChartContainerProps>(\n ({ config, className, children, style, ...props }, ref) => {\n const colorVars = React.useMemo(() => {\n const vars: Record<string, string> = {};\n for (const [key, cfg] of Object.entries(config)) {\n if (cfg.color) vars[`--color-${key}`] = cfg.color;\n }\n return vars;\n }, [config]);\n\n return (\n <div\n ref={ref}\n data-chart=\"\"\n className={cn(\n \"flex aspect-video justify-center text-xs [&_.recharts-cartesian-grid_line]:stroke-border/50 [&_.recharts-text]:fill-muted-foreground\",\n className,\n )}\n style={{ ...colorVars, ...style }}\n {...props}\n >\n <ResponsiveContainer width=\"100%\" height=\"100%\">\n {children}\n </ResponsiveContainer>\n </div>\n );\n },\n);\nChartContainer.displayName = \"ChartContainer\";\n\ninterface TooltipPayloadItem {\n name?: string | number;\n value?: string | number;\n color?: string;\n dataKey?: string | number;\n}\n\nexport interface ChartTooltipContentProps {\n active?: boolean;\n payload?: TooltipPayloadItem[];\n label?: React.ReactNode;\n config?: ChartConfig;\n}\n\n/** A tokenized tooltip body for recharts. Pass to `<ChartTooltip content={…} />`. */\nexport const ChartTooltipContent = React.forwardRef<HTMLDivElement, ChartTooltipContentProps>(\n ({ active, payload, label, config }, ref) => {\n if (!active || !payload?.length) return null;\n return (\n <div\n ref={ref}\n className=\"min-w-32 rounded-lg border border-border bg-background px-3 py-2 text-sm shadow-md\"\n >\n {label != null && <div className=\"mb-1 font-medium text-foreground\">{label}</div>}\n <div className=\"flex flex-col gap-1\">\n {payload.map((item, i) => {\n const key = String(item.dataKey ?? item.name ?? i);\n const name = config?.[key]?.label ?? item.name ?? key;\n return (\n <div key={i} className=\"flex items-center justify-between gap-3\">\n <span className=\"flex items-center gap-1.5 text-muted-foreground\">\n <span\n aria-hidden\n className=\"h-2 w-2 rounded-[2px]\"\n style={{ background: item.color ?? `var(--color-${key})` }}\n />\n {name}\n </span>\n <span className=\"font-medium tabular-nums text-foreground\">{item.value}</span>\n </div>\n );\n })}\n </div>\n </div>\n );\n },\n);\nChartTooltipContent.displayName = \"ChartTooltipContent\";\n\ninterface LegendPayloadItem {\n value?: string | number;\n color?: string;\n dataKey?: string | number;\n}\n\nexport interface ChartLegendContentProps {\n payload?: LegendPayloadItem[];\n config?: ChartConfig;\n}\n\n/** A tokenized legend for recharts. Pass to `<ChartLegend content={…} />`. */\nexport const ChartLegendContent = React.forwardRef<HTMLDivElement, ChartLegendContentProps>(\n ({ payload, config }, ref) => {\n if (!payload?.length) return null;\n return (\n <div ref={ref} className=\"flex flex-wrap items-center justify-center gap-4 pt-3\">\n {payload.map((item, i) => {\n const key = String(item.dataKey ?? item.value ?? i);\n const name = config?.[key]?.label ?? item.value ?? key;\n return (\n <span key={i} className=\"flex items-center gap-1.5 text-xs text-muted-foreground\">\n <span\n aria-hidden\n className=\"h-2 w-2 rounded-[2px]\"\n style={{ background: item.color ?? `var(--color-${key})` }}\n />\n {name}\n </span>\n );\n })}\n </div>\n );\n },\n);\nChartLegendContent.displayName = \"ChartLegendContent\";\n"]}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@nucleux/chart",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "description": "Composable chart primitives — Nucleux agentic UI for React.",
7
+ "keywords": [
8
+ "nucleux",
9
+ "react",
10
+ "ui",
11
+ "components",
12
+ "agentic",
13
+ "ai",
14
+ "tailwind",
15
+ "chart"
16
+ ],
17
+ "main": "./dist/index.cjs",
18
+ "module": "./dist/index.js",
19
+ "types": "./dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md"
30
+ ],
31
+ "peerDependencies": {
32
+ "react": ">=18",
33
+ "react-dom": ">=18"
34
+ },
35
+ "dependencies": {
36
+ "recharts": "^2.15.0",
37
+ "@nucleux/utils": "0.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "tsup": "^8.3.5",
41
+ "typescript": "^5.7.2",
42
+ "@types/react": "^18.3.18",
43
+ "react": "^18.3.1",
44
+ "lucide-react": "^0.469.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "license": "MIT",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
53
+ "directory": "packages/chart"
54
+ },
55
+ "homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
56
+ "scripts": {
57
+ "build": "tsup"
58
+ }
59
+ }