framepexls-ui-lib 0.3.24 → 0.3.25

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.
@@ -11,7 +11,7 @@ type CheckboxProps = Omit<React__default.InputHTMLAttributes<HTMLInputElement>,
11
11
  className?: string;
12
12
  inputClassName?: string;
13
13
  };
14
- declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<React__default.InputHTMLAttributes<HTMLInputElement>, "size" | "type"> & {
14
+ declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<React__default.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
15
15
  label?: React__default.ReactNode;
16
16
  description?: React__default.ReactNode;
17
17
  error?: boolean;
@@ -11,7 +11,7 @@ type CheckboxProps = Omit<React__default.InputHTMLAttributes<HTMLInputElement>,
11
11
  className?: string;
12
12
  inputClassName?: string;
13
13
  };
14
- declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<React__default.InputHTMLAttributes<HTMLInputElement>, "size" | "type"> & {
14
+ declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<React__default.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
15
15
  label?: React__default.ReactNode;
16
16
  description?: React__default.ReactNode;
17
17
  error?: boolean;
@@ -55,6 +55,12 @@ function RechartsDonutCard({
55
55
  valueFormatter
56
56
  }) {
57
57
  const safeData = Array.isArray(data) ? data : [];
58
+ const totalValue = safeData.reduce((acc, item) => {
59
+ var _a;
60
+ const raw = Number((_a = item == null ? void 0 : item[valueKey]) != null ? _a : 0);
61
+ return acc + (Number.isFinite(raw) ? raw : 0);
62
+ }, 0);
63
+ const formattedTotal = typeof totalValue === "number" ? valueFormatter ? valueFormatter(totalValue) : totalValue.toLocaleString("es-MX", { maximumFractionDigits: 2 }) : "";
58
64
  const renderTooltip = (props) => {
59
65
  var _a, _b;
60
66
  const { active, payload } = props || {};
@@ -78,7 +84,7 @@ function RechartsDonutCard({
78
84
  ] });
79
85
  };
80
86
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ChartCard.default, { title, subtitle, children: !safeData.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex h-[220px] items-center justify-center text-xs text-slate-500 dark:text-slate-400", children: "Sin datos para los filtros seleccionados." }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex h-[240px] w-full items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_recharts.PieChart, { width: 260, height: 220, children: [
81
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
87
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
82
88
  import_recharts.Pie,
83
89
  {
84
90
  data: safeData,
@@ -87,13 +93,25 @@ function RechartsDonutCard({
87
93
  innerRadius: 50,
88
94
  outerRadius: 80,
89
95
  paddingAngle: 2,
90
- children: safeData.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
91
- import_recharts.Cell,
92
- {
93
- fill: colors[index % colors.length]
94
- },
95
- `slice-${index}`
96
- ))
96
+ labelLine: false,
97
+ label: ({ percent }) => percent && percent > 0.05 ? `${(percent * 100).toFixed(0)}%` : "",
98
+ children: [
99
+ safeData.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
100
+ import_recharts.Cell,
101
+ {
102
+ fill: colors[index % colors.length]
103
+ },
104
+ `slice-${index}`
105
+ )),
106
+ formattedTotal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ import_recharts.Label,
108
+ {
109
+ position: "center",
110
+ value: formattedTotal,
111
+ style: { fontSize: 12, fontWeight: 600 }
112
+ }
113
+ )
114
+ ]
97
115
  }
98
116
  ),
99
117
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.Tooltip, { content: renderTooltip })
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import ChartCard from "./ChartCard";
4
- import { PieChart, Pie, Cell, Tooltip } from "recharts";
4
+ import { PieChart, Pie, Cell, Tooltip, Label } from "recharts";
5
5
  const DEFAULT_COLORS = [
6
6
  "#0ea5e9",
7
7
  "#6366f1",
@@ -22,6 +22,12 @@ function RechartsDonutCard({
22
22
  valueFormatter
23
23
  }) {
24
24
  const safeData = Array.isArray(data) ? data : [];
25
+ const totalValue = safeData.reduce((acc, item) => {
26
+ var _a;
27
+ const raw = Number((_a = item == null ? void 0 : item[valueKey]) != null ? _a : 0);
28
+ return acc + (Number.isFinite(raw) ? raw : 0);
29
+ }, 0);
30
+ const formattedTotal = typeof totalValue === "number" ? valueFormatter ? valueFormatter(totalValue) : totalValue.toLocaleString("es-MX", { maximumFractionDigits: 2 }) : "";
25
31
  const renderTooltip = (props) => {
26
32
  var _a, _b;
27
33
  const { active, payload } = props || {};
@@ -45,7 +51,7 @@ function RechartsDonutCard({
45
51
  ] });
46
52
  };
47
53
  return /* @__PURE__ */ jsx(ChartCard, { title, subtitle, children: !safeData.length ? /* @__PURE__ */ jsx("div", { className: "flex h-[220px] items-center justify-center text-xs text-slate-500 dark:text-slate-400", children: "Sin datos para los filtros seleccionados." }) : /* @__PURE__ */ jsx("div", { className: "flex h-[240px] w-full items-center justify-center", children: /* @__PURE__ */ jsxs(PieChart, { width: 260, height: 220, children: [
48
- /* @__PURE__ */ jsx(
54
+ /* @__PURE__ */ jsxs(
49
55
  Pie,
50
56
  {
51
57
  data: safeData,
@@ -54,13 +60,25 @@ function RechartsDonutCard({
54
60
  innerRadius: 50,
55
61
  outerRadius: 80,
56
62
  paddingAngle: 2,
57
- children: safeData.map((entry, index) => /* @__PURE__ */ jsx(
58
- Cell,
59
- {
60
- fill: colors[index % colors.length]
61
- },
62
- `slice-${index}`
63
- ))
63
+ labelLine: false,
64
+ label: ({ percent }) => percent && percent > 0.05 ? `${(percent * 100).toFixed(0)}%` : "",
65
+ children: [
66
+ safeData.map((entry, index) => /* @__PURE__ */ jsx(
67
+ Cell,
68
+ {
69
+ fill: colors[index % colors.length]
70
+ },
71
+ `slice-${index}`
72
+ )),
73
+ formattedTotal && /* @__PURE__ */ jsx(
74
+ Label,
75
+ {
76
+ position: "center",
77
+ value: formattedTotal,
78
+ style: { fontSize: 12, fontWeight: 600 }
79
+ }
80
+ )
81
+ ]
64
82
  }
65
83
  ),
66
84
  /* @__PURE__ */ jsx(Tooltip, { content: renderTooltip })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framepexls-ui-lib",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Componentes UI de Framepexls para React/Next.",