@trackunit/react-chart-components 1.3.41 → 1.3.43

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/index.cjs.js CHANGED
@@ -5,7 +5,6 @@ var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities
5
5
  var reactComponents = require('@trackunit/react-components');
6
6
  var EChart = require('echarts-for-react');
7
7
  var react = require('react');
8
- var uiDesignTokens = require('@trackunit/ui-design-tokens');
9
8
 
10
9
  /**
11
10
  * The Chart component is a wrapper component for ECharts.
@@ -66,93 +65,6 @@ const Chart = ({ options, unsafeOptions, showLoading, className, style, onChartR
66
65
  const cvaChartContainer = cssClassVarianceUtilities.cvaMerge(["grid", "gap-1", "grid-rows-1", "grid-cols-1", "h-full", "w-full", "items-center"]);
67
66
  const cvaChartSpinnerContainer = cssClassVarianceUtilities.cvaMerge(["grid", "place-items-center", "overflow-y-auto"]);
68
67
 
69
- /**
70
-
71
- A donut chart component to display a KPI value and its total in a circular chart.
72
- *
73
- @param {string} countColor - The color to be used for the value portion in the chart.
74
- @param {string} totalCountColor - The color to be used for the total portion in the chart.
75
- @param {number} count - The count of the KPI to be displayed.
76
- @param {number} totalCount - The total count of the KPI to be displayed.
77
- @returns {ReactElement} - A donut chart displaying the KPI count and total count.
78
- */
79
- const KPIDonutChart = ({ dataTestId, loading, countColor, totalCountColor, count, totalCount = count, }) => {
80
- return (jsxRuntime.jsx(Chart, { dataTestId: dataTestId, options: {
81
- color: [countColor || uiDesignTokens.DEFAULT_CHART_COLORS[0], totalCountColor || uiDesignTokens.DEFAULT_CHART_COLORS[22]],
82
- xAxis: [
83
- {
84
- type: "category",
85
- },
86
- ],
87
- yAxis: [
88
- {
89
- type: "value",
90
- },
91
- ],
92
- series: [
93
- {
94
- labelLine: {
95
- show: false,
96
- },
97
- emphasis: { disabled: true },
98
- type: "pie",
99
- data: [
100
- {
101
- name: "Value",
102
- value: count,
103
- },
104
- {
105
- name: "Total",
106
- value: totalCount - count,
107
- },
108
- ],
109
- radius: ["40%", "70%"],
110
- center: ["50%", "50%"],
111
- },
112
- ],
113
- }, showLoading: loading, style: { height: "36px", width: "36px" } }));
114
- };
115
-
116
- const cvaKpi = cssClassVarianceUtilities.cvaMerge(["flex", "flex-row", "gap-1", "leading-none", "items-center"]);
117
- const cvaKpiCountContainer = cssClassVarianceUtilities.cvaMerge(["flex", "gap-1", "items-baseline"]);
118
- const cvaKpiDescription = cssClassVarianceUtilities.cvaMerge(["font-normal", "text-base"]);
119
- const cvaKpiCount = cssClassVarianceUtilities.cvaMerge(["font-semibold", "text-xl"]);
120
- const cvaKpiSuffix = cssClassVarianceUtilities.cvaMerge(["font-normal", "text-base"]);
121
- const cvaKpiContainer = cssClassVarianceUtilities.cvaMerge(["flex", "flex-col", "items-baseline"], {
122
- variants: {
123
- inline: {
124
- false: "",
125
- true: ["flex-row", "gap-1", "justify-start"],
126
- },
127
- showChart: {
128
- false: "",
129
- true: ["gap-0 ", "items-center"],
130
- },
131
- },
132
- defaultVariants: {
133
- inline: false,
134
- showChart: false,
135
- },
136
- });
137
-
138
- /**
139
- * - A KPI component to display a value and its description.
140
- * - It can also display a donut chart to show the value and its total.
141
- * - The donut chart is displayed when the showChart prop is set to true.
142
- *
143
- * @param {boolean} showChart - Boolean to control the visibility of the chart.
144
- * @param {number|string|null} count - Value of the Kpi.
145
- * @param {number} totalCount - Total value of the Kpi.
146
- * @param {string} description - Description of the Kpi.
147
- * @param {string[]} colors - Colors of the Kpi.
148
- * @param {boolean} loading - Whether the value is loading or not.
149
- * @param {boolean} inline - Boolean to control whether the KPI is displayed inline or not.
150
- * @returns {ReactElement} Kpi component
151
- */
152
- const Kpi = ({ className, dataTestId, showChart = false, count, description, totalCount, countColor, totalCountColor, suffix, inline = false, loading = false, }) => {
153
- return (jsxRuntime.jsxs("div", { className: cvaKpi({ className }), "data-testid": dataTestId, children: [showChart ? (jsxRuntime.jsx(KPIDonutChart, { count: Number(count), countColor: countColor, dataTestId: dataTestId ? dataTestId + "-donut-chart" : undefined, loading: loading, totalCount: totalCount, totalCountColor: totalCountColor })) : null, loading ? (jsxRuntime.jsxs("div", { className: cvaKpiContainer({ inline }), "data-testid": dataTestId ? `${dataTestId}-skeleton-lines` : null, children: [jsxRuntime.jsx(reactComponents.SkeletonLines, { lines: 1, width: 20 }), jsxRuntime.jsx(reactComponents.SkeletonLines, { lines: 1, width: 50 })] })) : (jsxRuntime.jsxs("div", { className: cvaKpiContainer({ inline, showChart }), "data-testid": dataTestId ? `${dataTestId}-container` : null, children: [jsxRuntime.jsxs("span", { className: cvaKpiCountContainer(), children: [jsxRuntime.jsx("span", { className: cvaKpiCount(), children: count ?? "-" }), suffix ? (jsxRuntime.jsx("span", { className: cvaKpiSuffix(), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null] }), jsxRuntime.jsx("span", { className: cvaKpiDescription(), children: description })] }))] }));
154
- };
155
-
156
68
  const cvaLegendItem = cssClassVarianceUtilities.cvaMerge([
157
69
  "inline-flex",
158
70
  "items-center",
@@ -276,6 +188,5 @@ const cvaChartRoot = cssClassVarianceUtilities.cvaMerge([
276
188
  ]);
277
189
 
278
190
  exports.Chart = Chart;
279
- exports.Kpi = Kpi;
280
191
  exports.LegendItem = LegendItem;
281
192
  exports.PieChart = PieChart;
package/index.esm.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
3
- import { Spinner, Text, SkeletonLines, useHover } from '@trackunit/react-components';
3
+ import { Spinner, Text, useHover } from '@trackunit/react-components';
4
4
  import EChart from 'echarts-for-react';
5
5
  import { useRef, useMemo, useEffect } from 'react';
6
- import { DEFAULT_CHART_COLORS } from '@trackunit/ui-design-tokens';
7
6
 
8
7
  /**
9
8
  * The Chart component is a wrapper component for ECharts.
@@ -64,93 +63,6 @@ const Chart = ({ options, unsafeOptions, showLoading, className, style, onChartR
64
63
  const cvaChartContainer = cvaMerge(["grid", "gap-1", "grid-rows-1", "grid-cols-1", "h-full", "w-full", "items-center"]);
65
64
  const cvaChartSpinnerContainer = cvaMerge(["grid", "place-items-center", "overflow-y-auto"]);
66
65
 
67
- /**
68
-
69
- A donut chart component to display a KPI value and its total in a circular chart.
70
- *
71
- @param {string} countColor - The color to be used for the value portion in the chart.
72
- @param {string} totalCountColor - The color to be used for the total portion in the chart.
73
- @param {number} count - The count of the KPI to be displayed.
74
- @param {number} totalCount - The total count of the KPI to be displayed.
75
- @returns {ReactElement} - A donut chart displaying the KPI count and total count.
76
- */
77
- const KPIDonutChart = ({ dataTestId, loading, countColor, totalCountColor, count, totalCount = count, }) => {
78
- return (jsx(Chart, { dataTestId: dataTestId, options: {
79
- color: [countColor || DEFAULT_CHART_COLORS[0], totalCountColor || DEFAULT_CHART_COLORS[22]],
80
- xAxis: [
81
- {
82
- type: "category",
83
- },
84
- ],
85
- yAxis: [
86
- {
87
- type: "value",
88
- },
89
- ],
90
- series: [
91
- {
92
- labelLine: {
93
- show: false,
94
- },
95
- emphasis: { disabled: true },
96
- type: "pie",
97
- data: [
98
- {
99
- name: "Value",
100
- value: count,
101
- },
102
- {
103
- name: "Total",
104
- value: totalCount - count,
105
- },
106
- ],
107
- radius: ["40%", "70%"],
108
- center: ["50%", "50%"],
109
- },
110
- ],
111
- }, showLoading: loading, style: { height: "36px", width: "36px" } }));
112
- };
113
-
114
- const cvaKpi = cvaMerge(["flex", "flex-row", "gap-1", "leading-none", "items-center"]);
115
- const cvaKpiCountContainer = cvaMerge(["flex", "gap-1", "items-baseline"]);
116
- const cvaKpiDescription = cvaMerge(["font-normal", "text-base"]);
117
- const cvaKpiCount = cvaMerge(["font-semibold", "text-xl"]);
118
- const cvaKpiSuffix = cvaMerge(["font-normal", "text-base"]);
119
- const cvaKpiContainer = cvaMerge(["flex", "flex-col", "items-baseline"], {
120
- variants: {
121
- inline: {
122
- false: "",
123
- true: ["flex-row", "gap-1", "justify-start"],
124
- },
125
- showChart: {
126
- false: "",
127
- true: ["gap-0 ", "items-center"],
128
- },
129
- },
130
- defaultVariants: {
131
- inline: false,
132
- showChart: false,
133
- },
134
- });
135
-
136
- /**
137
- * - A KPI component to display a value and its description.
138
- * - It can also display a donut chart to show the value and its total.
139
- * - The donut chart is displayed when the showChart prop is set to true.
140
- *
141
- * @param {boolean} showChart - Boolean to control the visibility of the chart.
142
- * @param {number|string|null} count - Value of the Kpi.
143
- * @param {number} totalCount - Total value of the Kpi.
144
- * @param {string} description - Description of the Kpi.
145
- * @param {string[]} colors - Colors of the Kpi.
146
- * @param {boolean} loading - Whether the value is loading or not.
147
- * @param {boolean} inline - Boolean to control whether the KPI is displayed inline or not.
148
- * @returns {ReactElement} Kpi component
149
- */
150
- const Kpi = ({ className, dataTestId, showChart = false, count, description, totalCount, countColor, totalCountColor, suffix, inline = false, loading = false, }) => {
151
- return (jsxs("div", { className: cvaKpi({ className }), "data-testid": dataTestId, children: [showChart ? (jsx(KPIDonutChart, { count: Number(count), countColor: countColor, dataTestId: dataTestId ? dataTestId + "-donut-chart" : undefined, loading: loading, totalCount: totalCount, totalCountColor: totalCountColor })) : null, loading ? (jsxs("div", { className: cvaKpiContainer({ inline }), "data-testid": dataTestId ? `${dataTestId}-skeleton-lines` : null, children: [jsx(SkeletonLines, { lines: 1, width: 20 }), jsx(SkeletonLines, { lines: 1, width: 50 })] })) : (jsxs("div", { className: cvaKpiContainer({ inline, showChart }), "data-testid": dataTestId ? `${dataTestId}-container` : null, children: [jsxs("span", { className: cvaKpiCountContainer(), children: [jsx("span", { className: cvaKpiCount(), children: count ?? "-" }), suffix ? (jsx("span", { className: cvaKpiSuffix(), "data-testid": dataTestId ? `${dataTestId}-suffix` : null, children: suffix })) : null] }), jsx("span", { className: cvaKpiDescription(), children: description })] }))] }));
152
- };
153
-
154
66
  const cvaLegendItem = cvaMerge([
155
67
  "inline-flex",
156
68
  "items-center",
@@ -273,4 +185,4 @@ const cvaChartRoot = cvaMerge([
273
185
  "h-full",
274
186
  ]);
275
187
 
276
- export { Chart, Kpi, LegendItem, PieChart };
188
+ export { Chart, LegendItem, PieChart };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-chart-components",
3
- "version": "1.3.41",
3
+ "version": "1.3.43",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -10,9 +10,8 @@
10
10
  "echarts": "5.6.0",
11
11
  "echarts-for-react": "^3.0.2",
12
12
  "react": "19.0.0",
13
- "@trackunit/css-class-variance-utilities": "1.3.37",
14
- "@trackunit/react-components": "1.4.41",
15
- "@trackunit/ui-design-tokens": "1.3.37"
13
+ "@trackunit/css-class-variance-utilities": "1.3.39",
14
+ "@trackunit/react-components": "1.4.43"
16
15
  },
17
16
  "module": "./index.esm.js",
18
17
  "main": "./index.cjs.js",
package/src/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./Chart";
2
- export * from "./KPI";
3
2
  export * from "./LegendItem";
4
3
  export * from "./PieChart";
@@ -1,48 +0,0 @@
1
- interface DonutChartProps {
2
- /**
3
- * The color to be used for the count portion in the chart.
4
- */
5
- countColor?: string;
6
- /**
7
- * The color to be used for the total count portion in the chart.
8
- */
9
- totalCountColor?: string;
10
- /**
11
- * The count to be displayed in the KPI.
12
- *
13
- * @example
14
- * <Kpi count={29000} />
15
- */
16
- count: number;
17
- /**
18
- * Total count of the Kpi.
19
- * This is useful when you want to display a donut chart.
20
- * The donut chart will be divided into two parts, the count and the total count.
21
- *
22
- * @example
23
- * <Kpi totalCount={29000} />
24
- */
25
- totalCount?: number;
26
- /**
27
- * Whether the value is loading or not.
28
- *
29
- * @default false
30
- */
31
- loading?: boolean;
32
- /**
33
- * The data-testid attribute to be used for testing.
34
- */
35
- dataTestId?: string;
36
- }
37
- /**
38
-
39
- A donut chart component to display a KPI value and its total in a circular chart.
40
- *
41
- @param {string} countColor - The color to be used for the value portion in the chart.
42
- @param {string} totalCountColor - The color to be used for the total portion in the chart.
43
- @param {number} count - The count of the KPI to be displayed.
44
- @param {number} totalCount - The total count of the KPI to be displayed.
45
- @returns {ReactElement} - A donut chart displaying the KPI count and total count.
46
- */
47
- export declare const KPIDonutChart: ({ dataTestId, loading, countColor, totalCountColor, count, totalCount, }: DonutChartProps) => import("react/jsx-runtime").JSX.Element;
48
- export {};
package/src/KPI/Kpi.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import { CommonProps } from "@trackunit/react-components";
2
- export interface KpiProps extends CommonProps {
3
- /**
4
- * The count to be displayed in the KPI.
5
- *
6
- * @example
7
- * <Kpi count={29000} />
8
- * <Kpi count="29,000" />
9
- */
10
- count: number | string | null;
11
- /**
12
- * Total count of the Kpi.
13
- * This is useful when you want to display a donut chart.
14
- * The donut chart will be divided into two parts, the count and the total count.
15
- *
16
- * @example
17
- * <Kpi count={15000} totalCount={29000} />
18
- */
19
- totalCount?: number;
20
- /**
21
- * Description of the Kpi.
22
- *
23
- * @example <Kpi description="Total Assets" />
24
- */
25
- description?: string;
26
- /**
27
- * Boolean to control the visibility of the chart.
28
- */
29
- showChart?: boolean;
30
- /**
31
- * A suffix that gets added to the end of the count.
32
- * This is useful when you want to display a percentage, unit, etc.
33
- *
34
- * @example <Kpi value={50} suffix="%" /> will display 50%.
35
- * <Kpi value={50} suffix="units" /> will display 50 units.
36
- */
37
- suffix?: string;
38
- /**
39
- * The color to be used for the count portion in the chart.
40
- */
41
- countColor?: string;
42
- /**
43
- * The color to be used for the total count portion in the chart.
44
- */
45
- totalCountColor?: string;
46
- /**
47
- * Boolean to control whether the KPI is displayed inline or not.
48
- *
49
- * @default false
50
- */
51
- inline?: boolean;
52
- /**
53
- * Whether the value is loading or not.
54
- * When set to true, a skeleton will be displayed.
55
- *
56
- * @default false
57
- */
58
- loading?: boolean;
59
- }
60
- /**
61
- * - A KPI component to display a value and its description.
62
- * - It can also display a donut chart to show the value and its total.
63
- * - The donut chart is displayed when the showChart prop is set to true.
64
- *
65
- * @param {boolean} showChart - Boolean to control the visibility of the chart.
66
- * @param {number|string|null} count - Value of the Kpi.
67
- * @param {number} totalCount - Total value of the Kpi.
68
- * @param {string} description - Description of the Kpi.
69
- * @param {string[]} colors - Colors of the Kpi.
70
- * @param {boolean} loading - Whether the value is loading or not.
71
- * @param {boolean} inline - Boolean to control whether the KPI is displayed inline or not.
72
- * @returns {ReactElement} Kpi component
73
- */
74
- export declare const Kpi: ({ className, dataTestId, showChart, count, description, totalCount, countColor, totalCountColor, suffix, inline, loading, }: KpiProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,9 +0,0 @@
1
- export declare const cvaKpi: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
2
- export declare const cvaKpiCountContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
3
- export declare const cvaKpiDescription: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
4
- export declare const cvaKpiCount: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
5
- export declare const cvaKpiSuffix: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
6
- export declare const cvaKpiContainer: (props?: ({
7
- inline?: boolean | null | undefined;
8
- showChart?: boolean | null | undefined;
9
- } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
@@ -1 +0,0 @@
1
- export * from "./Kpi";