@trackunit/react-chart-components 0.0.18 → 0.0.19

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 CHANGED
@@ -7,6 +7,7 @@ var reactComponents = require('@trackunit/react-components');
7
7
  var tailwindStyledComponents = require('@trackunit/tailwind-styled-components');
8
8
  var EChart = require('echarts-for-react');
9
9
  var React = require('react');
10
+ var uiDesignTokens = require('@trackunit/ui-design-tokens');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
@@ -87,6 +88,81 @@ const ChartContainer = tailwindStyledComponents.tw.div `
87
88
  tu-chart-container
88
89
  `;
89
90
 
91
+ /**
92
+
93
+ A donut chart component to display a KPI value and its total in a circular chart.
94
+ *
95
+ @param {string} countColor - The color to be used for the value portion in the chart.
96
+ @param {string} totalCountColor - The color to be used for the total portion in the chart.
97
+ @param {number} count - The count of the KPI to be displayed.
98
+ @param {number} totalCount - The total count of the KPI to be displayed.
99
+ @returns {JSX.Element} - A donut chart displaying the KPI count and total count.
100
+ */
101
+ const KPIDonutChart = ({ dataTestId, loading, countColor, totalCountColor, count, totalCount = count, }) => {
102
+ return (jsxRuntime.jsx(Chart, { dataTestId: dataTestId, showLoading: loading, style: { height: "36px", width: "36px" }, options: {
103
+ color: [countColor || uiDesignTokens.DEFAULT_CHART_COLORS[0], totalCountColor || uiDesignTokens.DEFAULT_CHART_COLORS[22]],
104
+ xAxis: [
105
+ {
106
+ type: "category",
107
+ },
108
+ ],
109
+ yAxis: [
110
+ {
111
+ type: "value",
112
+ },
113
+ ],
114
+ series: [
115
+ {
116
+ labelLine: {
117
+ show: false,
118
+ },
119
+ emphasis: false,
120
+ type: "pie",
121
+ data: [
122
+ {
123
+ key: "Value",
124
+ value: count,
125
+ },
126
+ {
127
+ key: "Total",
128
+ value: totalCount - count,
129
+ },
130
+ ],
131
+ radius: ["40%", "70%"],
132
+ center: ["50%", "50%"],
133
+ },
134
+ ],
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} 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 {JSX.Element} Kpi component
151
+ */
152
+ const Kpi = ({ className, dataTestId, showChart = false, count, description, totalCount, countColor, totalCountColor, suffix, inline = false, loading = false, }) => {
153
+ return (jsxRuntime.jsxs(Root$1, Object.assign({ className: className, "data-testid": dataTestId }, { children: [showChart && (jsxRuntime.jsx(KPIDonutChart, { dataTestId: dataTestId && dataTestId + "-donut-chart", loading: loading, count: count, totalCount: totalCount, countColor: countColor, totalCountColor: totalCountColor })), loading ? (jsxRuntime.jsxs(Container, Object.assign({ "data-testid": dataTestId && `${dataTestId}-skeleton-lines`, "$inline": inline }, { children: [jsxRuntime.jsx(reactComponents.SkeletonLines, { lines: 1, width: 20 }), jsxRuntime.jsx(reactComponents.SkeletonLines, { lines: 1, width: 50 })] }))) : (jsxRuntime.jsxs(Container, Object.assign({ "$showChart": showChart, "data-testid": dataTestId && `${dataTestId}-container`, "$inline": inline }, { children: [jsxRuntime.jsxs(CountContainer, { children: [jsxRuntime.jsx(Count, { children: count }), suffix && jsxRuntime.jsx(Suffix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-suffix` }, { children: suffix }))] }), jsxRuntime.jsx(Description, { children: description })] })))] })));
154
+ };
155
+ const Root$1 = tailwindStyledComponents.tw.div `tu-kpi`;
156
+ const CountContainer = tailwindStyledComponents.tw.span `tu-kpi__count-container`;
157
+ const Description = tailwindStyledComponents.tw.span `tu-kpi__description`;
158
+ const Count = tailwindStyledComponents.tw.span `tu-kpi__count`;
159
+ const Suffix = tailwindStyledComponents.tw.span `tu-kpi__suffix`;
160
+ const Container = tailwindStyledComponents.tw.div `
161
+ tu-kpi__container
162
+ ${p => p.$inline && `tu-kpi__container--inline`}
163
+ ${p => !p.$showChart && `tu-kpi__container--without-chart`}
164
+ `;
165
+
90
166
  /**
91
167
  * The LegendItem component is used to show form legends.
92
168
  *
@@ -185,5 +261,6 @@ const ChartRoot = tailwindStyledComponents.tw.div `
185
261
  `;
186
262
 
187
263
  exports.Chart = Chart;
264
+ exports.Kpi = Kpi;
188
265
  exports.LegendItem = LegendItem;
189
266
  exports.PieChart = PieChart;
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { Spinner, Text } from '@trackunit/react-components';
2
+ import { Spinner, Text, SkeletonLines } from '@trackunit/react-components';
3
3
  import { tw, tws } from '@trackunit/tailwind-styled-components';
4
4
  import EChart from 'echarts-for-react';
5
5
  import * as React from 'react';
6
+ import { DEFAULT_CHART_COLORS } from '@trackunit/ui-design-tokens';
6
7
 
7
8
  /**
8
9
  * The Chart component is a wrapper component for ECharts.
@@ -60,6 +61,81 @@ const ChartContainer = tw.div `
60
61
  tu-chart-container
61
62
  `;
62
63
 
64
+ /**
65
+
66
+ A donut chart component to display a KPI value and its total in a circular chart.
67
+ *
68
+ @param {string} countColor - The color to be used for the value portion in the chart.
69
+ @param {string} totalCountColor - The color to be used for the total portion in the chart.
70
+ @param {number} count - The count of the KPI to be displayed.
71
+ @param {number} totalCount - The total count of the KPI to be displayed.
72
+ @returns {JSX.Element} - A donut chart displaying the KPI count and total count.
73
+ */
74
+ const KPIDonutChart = ({ dataTestId, loading, countColor, totalCountColor, count, totalCount = count, }) => {
75
+ return (jsx(Chart, { dataTestId: dataTestId, showLoading: loading, style: { height: "36px", width: "36px" }, options: {
76
+ color: [countColor || DEFAULT_CHART_COLORS[0], totalCountColor || DEFAULT_CHART_COLORS[22]],
77
+ xAxis: [
78
+ {
79
+ type: "category",
80
+ },
81
+ ],
82
+ yAxis: [
83
+ {
84
+ type: "value",
85
+ },
86
+ ],
87
+ series: [
88
+ {
89
+ labelLine: {
90
+ show: false,
91
+ },
92
+ emphasis: false,
93
+ type: "pie",
94
+ data: [
95
+ {
96
+ key: "Value",
97
+ value: count,
98
+ },
99
+ {
100
+ key: "Total",
101
+ value: totalCount - count,
102
+ },
103
+ ],
104
+ radius: ["40%", "70%"],
105
+ center: ["50%", "50%"],
106
+ },
107
+ ],
108
+ } }));
109
+ };
110
+
111
+ /**
112
+ * - A KPI component to display a value and its description.
113
+ * - It can also display a donut chart to show the value and its total.
114
+ * - The donut chart is displayed when the showChart prop is set to true.
115
+ *
116
+ * @param {boolean} showChart - Boolean to control the visibility of the chart.
117
+ * @param {number} count - Value of the Kpi.
118
+ * @param {number} totalCount - Total value of the Kpi.
119
+ * @param {string} description - Description of the Kpi.
120
+ * @param {string[]} colors - Colors of the Kpi.
121
+ * @param {boolean} loading - Whether the value is loading or not.
122
+ * @param {boolean} inline - Boolean to control whether the KPI is displayed inline or not.
123
+ * @returns {JSX.Element} Kpi component
124
+ */
125
+ const Kpi = ({ className, dataTestId, showChart = false, count, description, totalCount, countColor, totalCountColor, suffix, inline = false, loading = false, }) => {
126
+ return (jsxs(Root$1, Object.assign({ className: className, "data-testid": dataTestId }, { children: [showChart && (jsx(KPIDonutChart, { dataTestId: dataTestId && dataTestId + "-donut-chart", loading: loading, count: count, totalCount: totalCount, countColor: countColor, totalCountColor: totalCountColor })), loading ? (jsxs(Container, Object.assign({ "data-testid": dataTestId && `${dataTestId}-skeleton-lines`, "$inline": inline }, { children: [jsx(SkeletonLines, { lines: 1, width: 20 }), jsx(SkeletonLines, { lines: 1, width: 50 })] }))) : (jsxs(Container, Object.assign({ "$showChart": showChart, "data-testid": dataTestId && `${dataTestId}-container`, "$inline": inline }, { children: [jsxs(CountContainer, { children: [jsx(Count, { children: count }), suffix && jsx(Suffix, Object.assign({ "data-testid": dataTestId && `${dataTestId}-suffix` }, { children: suffix }))] }), jsx(Description, { children: description })] })))] })));
127
+ };
128
+ const Root$1 = tw.div `tu-kpi`;
129
+ const CountContainer = tw.span `tu-kpi__count-container`;
130
+ const Description = tw.span `tu-kpi__description`;
131
+ const Count = tw.span `tu-kpi__count`;
132
+ const Suffix = tw.span `tu-kpi__suffix`;
133
+ const Container = tw.div `
134
+ tu-kpi__container
135
+ ${p => p.$inline && `tu-kpi__container--inline`}
136
+ ${p => !p.$showChart && `tu-kpi__container--without-chart`}
137
+ `;
138
+
63
139
  /**
64
140
  * The LegendItem component is used to show form legends.
65
141
  *
@@ -157,4 +233,4 @@ const ChartRoot = tw.div `
157
233
  h-full
158
234
  `;
159
235
 
160
- export { Chart, LegendItem, PieChart };
236
+ export { Chart, Kpi, LegendItem, PieChart };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@trackunit/react-chart-components",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
7
- "@trackunit/react-components": "0.1.77",
8
- "@trackunit/ui-design-tokens": "0.0.64",
7
+ "@trackunit/react-components": "0.1.78",
8
+ "@trackunit/ui-design-tokens": "0.0.65",
9
9
  "@trackunit/tailwind-styled-components": "0.0.55",
10
10
  "echarts": "5.4.0",
11
11
  "echarts-for-react": "3.0.2",
@@ -0,0 +1,49 @@
1
+ /// <reference types="react" />
2
+ interface DonutChartProps {
3
+ /**
4
+ * The color to be used for the count portion in the chart.
5
+ */
6
+ countColor?: string;
7
+ /**
8
+ * The color to be used for the total count portion in the chart.
9
+ */
10
+ totalCountColor?: string;
11
+ /**
12
+ * The count to be displayed in the KPI.
13
+ *
14
+ * @example
15
+ * <Kpi count={29000} />
16
+ */
17
+ count: number;
18
+ /**
19
+ * Total count of the Kpi.
20
+ * This is useful when you want to display a donut chart.
21
+ * The donut chart will be divided into two parts, the count and the total count.
22
+ *
23
+ * @example
24
+ * <Kpi totalCount={29000} />
25
+ */
26
+ totalCount?: number;
27
+ /**
28
+ * Whether the value is loading or not.
29
+ *
30
+ * @default false
31
+ */
32
+ loading?: boolean;
33
+ /**
34
+ * The data-testid attribute to be used for testing.
35
+ */
36
+ dataTestId?: string;
37
+ }
38
+ /**
39
+
40
+ A donut chart component to display a KPI value and its total in a circular chart.
41
+ *
42
+ @param {string} countColor - The color to be used for the value portion in the chart.
43
+ @param {string} totalCountColor - The color to be used for the total portion in the chart.
44
+ @param {number} count - The count of the KPI to be displayed.
45
+ @param {number} totalCount - The total count of the KPI to be displayed.
46
+ @returns {JSX.Element} - A donut chart displaying the KPI count and total count.
47
+ */
48
+ export declare const KPIDonutChart: ({ dataTestId, loading, countColor, totalCountColor, count, totalCount, }: DonutChartProps) => JSX.Element;
49
+ export {};
@@ -0,0 +1,74 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps } from "@trackunit/react-components";
3
+ export interface KpiProps extends CommonProps {
4
+ /**
5
+ * The count to be displayed in the KPI.
6
+ *
7
+ * @example
8
+ * <Kpi count={29000} />
9
+ */
10
+ count: number;
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} 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 {JSX.Element} Kpi component
73
+ */
74
+ export declare const Kpi: ({ className, dataTestId, showChart, count, description, totalCount, countColor, totalCountColor, suffix, inline, loading, }: KpiProps) => JSX.Element;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { ComponentMeta, Story } from "@storybook/react";
3
+ import { KpiProps } from "./Kpi";
4
+ import "./Kpi.css";
5
+ declare const _default: ComponentMeta<({ className, dataTestId, showChart, count, description, totalCount, countColor, totalCountColor, suffix, inline, loading, }: KpiProps) => JSX.Element>;
6
+ export default _default;
7
+ export declare const Default: Story<KpiProps>;
8
+ export declare const HiddenVariantSingleValue: () => JSX.Element;
9
+ export declare const HiddenVariantInline: () => JSX.Element;
10
+ export declare const HiddenVariantChart: () => JSX.Element;
11
+ export declare const Usage: () => JSX.Element;
12
+ export declare const Variants: () => JSX.Element;
@@ -0,0 +1 @@
1
+ export * from "./Kpi";
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./Chart";
2
+ export * from "./KPI";
2
3
  export * from "./LegendItem";
3
4
  export * from "./PieChart";