@trackunit/react-components 0.5.39 → 0.5.40
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 +35 -12
- package/index.esm.js +35 -12
- package/package.json +1 -1
- package/src/components/KPICard/KPICard.d.ts +31 -11
- package/src/components/KPICard/KPICard.variants.d.ts +6 -2
package/index.cjs.js
CHANGED
|
@@ -3731,7 +3731,7 @@ const cvaKPICardContainer = cssClassVarianceUtilities.cvaMerge(["inline-flex"],
|
|
|
3731
3731
|
isClickable: false,
|
|
3732
3732
|
},
|
|
3733
3733
|
});
|
|
3734
|
-
const cvaKPICard = cssClassVarianceUtilities.cvaMerge(["w-full", "bg-white", "
|
|
3734
|
+
const cvaKPICard = cssClassVarianceUtilities.cvaMerge(["w-full", "bg-white", "px-4", "py-2", "flex", "flex-row", "items-center", "gap-1"], {
|
|
3735
3735
|
variants: {
|
|
3736
3736
|
isClickable: {
|
|
3737
3737
|
true: ["hover:bg-slate-50", "component-card-border"],
|
|
@@ -3741,38 +3741,61 @@ const cvaKPICard = cssClassVarianceUtilities.cvaMerge(["w-full", "bg-white", "pl
|
|
|
3741
3741
|
true: ["bg-primary-50", "border-primary-600"],
|
|
3742
3742
|
false: [],
|
|
3743
3743
|
},
|
|
3744
|
+
variant: {
|
|
3745
|
+
small: ["px-3"],
|
|
3746
|
+
default: ["min-w-40"],
|
|
3747
|
+
},
|
|
3744
3748
|
},
|
|
3745
3749
|
defaultVariants: {
|
|
3746
3750
|
isClickable: false,
|
|
3747
3751
|
isActive: false,
|
|
3752
|
+
variant: "default",
|
|
3753
|
+
},
|
|
3754
|
+
});
|
|
3755
|
+
const cvaKPICardTrendPercentage = cssClassVarianceUtilities.cvaMerge([""], {
|
|
3756
|
+
variants: {
|
|
3757
|
+
color: {
|
|
3758
|
+
success: ["text-success-500"],
|
|
3759
|
+
danger: ["text-danger-500"],
|
|
3760
|
+
neutral: ["text-neutral-500"],
|
|
3761
|
+
},
|
|
3762
|
+
},
|
|
3763
|
+
defaultVariants: {
|
|
3764
|
+
color: "success",
|
|
3748
3765
|
},
|
|
3749
3766
|
});
|
|
3750
|
-
const
|
|
3767
|
+
const cvaKPICardValueContainer = cssClassVarianceUtilities.cvaMerge([], {
|
|
3751
3768
|
variants: {
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
warning: "bg-yellow-500",
|
|
3756
|
-
danger: "bg-red-500",
|
|
3769
|
+
isDefaultAndHasTrendValue: {
|
|
3770
|
+
true: [],
|
|
3771
|
+
false: ["flex", "flex-row", "items-center", "gap-1"],
|
|
3757
3772
|
},
|
|
3758
3773
|
},
|
|
3759
3774
|
defaultVariants: {
|
|
3760
|
-
|
|
3775
|
+
isDefaultAndHasTrendValue: true,
|
|
3761
3776
|
},
|
|
3762
3777
|
});
|
|
3763
3778
|
|
|
3764
|
-
const LoadingContent = () => (jsxRuntime.
|
|
3779
|
+
const LoadingContent = () => (jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-3", "data-testid": "kpi-card-loading-content", children: jsxRuntime.jsx("div", { className: "w-full", children: jsxRuntime.jsx(SkeletonLines, { height: [18, 20], lines: 2, margin: "3px 0", width: [50, 100] }) }) }));
|
|
3765
3780
|
/**
|
|
3766
3781
|
* The KPICard component is used to display KPIs.
|
|
3767
3782
|
*
|
|
3768
3783
|
* @param {KPICardProps} props - The props for the KPICard component
|
|
3769
3784
|
* @returns {JSX.Element} KPICard component
|
|
3770
3785
|
*/
|
|
3771
|
-
const KPICard = ({ asChild = false, title, value, loading, unit,
|
|
3786
|
+
const KPICard = ({ asChild = false, title, value, loading, unit, className, dataTestId, tooltipLabel, isActive, variant = "default", trend, onClick, ...rest }) => {
|
|
3772
3787
|
const Comp = asChild ? reactSlot.Slot : "div";
|
|
3773
|
-
const
|
|
3774
|
-
|
|
3788
|
+
const isSmallVariant = variant === "small";
|
|
3789
|
+
const TrendIndicator = () => {
|
|
3790
|
+
var _a, _b;
|
|
3791
|
+
if (!trend) {
|
|
3792
|
+
return null;
|
|
3793
|
+
}
|
|
3794
|
+
return (jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-1", "data-testid": "trend-indicator", children: [!isSmallVariant && trend.value ? (jsxRuntime.jsxs(Text, { dataTestId: "trend-value", size: "small", weight: "normal", children: [trend.value, " ", unit] })) : null, ((_a = trend.variant) === null || _a === void 0 ? void 0 : _a.icon) ? jsxRuntime.jsx(Icon, { color: trend.variant.color, name: trend.variant.icon, size: "small" }) : null, trend.percentage ? (jsxRuntime.jsxs(Text, { className: cvaKPICardTrendPercentage({ color: (_b = trend.variant) === null || _b === void 0 ? void 0 : _b.color }), size: "small", weight: "bold", children: [trend.percentage, "%"] })) : null] }));
|
|
3775
3795
|
};
|
|
3796
|
+
const CardContent = () => (jsxRuntime.jsx(Card, { className: cvaKPICard({ isClickable: Boolean((onClick || asChild) && !loading), isActive, variant }), children: loading ? (jsxRuntime.jsx(LoadingContent, {})) : (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(Text, { dataTestId: `${dataTestId}-title`, size: isSmallVariant ? "small" : "medium", subtle: true, weight: isSmallVariant ? "normal" : "bold", children: title }), jsxRuntime.jsx(Text, { className: isSmallVariant ? "mt-0.5" : "", dataTestId: `${dataTestId}-value`, size: isSmallVariant ? "small" : "large", type: "div", weight: isSmallVariant ? "bold" : "thick", children: jsxRuntime.jsxs("div", { className: cvaKPICardValueContainer({
|
|
3797
|
+
isDefaultAndHasTrendValue: Boolean((trend === null || trend === void 0 ? void 0 : trend.value) && !isSmallVariant),
|
|
3798
|
+
}), children: [jsxRuntime.jsxs("span", { children: [value, " ", unit] }), jsxRuntime.jsx(TrendIndicator, {})] }) })] })) }));
|
|
3776
3799
|
return (jsxRuntime.jsxs(Comp, { className: cvaKPICardContainer({ className, isClickable: Boolean(asChild || onClick) }), "data-testid": `${dataTestId}-comp`, onClick: onClick, ...rest, children: [tooltipLabel ? (jsxRuntime.jsx(Tooltip, { className: "w-full", label: tooltipLabel, placement: "bottom", children: jsxRuntime.jsx(CardContent, {}) })) : (jsxRuntime.jsx(CardContent, {})), !loading && jsxRuntime.jsx(reactSlot.Slottable, { children: rest.children })] }));
|
|
3777
3800
|
};
|
|
3778
3801
|
|
package/index.esm.js
CHANGED
|
@@ -3711,7 +3711,7 @@ const cvaKPICardContainer = cvaMerge(["inline-flex"], {
|
|
|
3711
3711
|
isClickable: false,
|
|
3712
3712
|
},
|
|
3713
3713
|
});
|
|
3714
|
-
const cvaKPICard = cvaMerge(["w-full", "bg-white", "
|
|
3714
|
+
const cvaKPICard = cvaMerge(["w-full", "bg-white", "px-4", "py-2", "flex", "flex-row", "items-center", "gap-1"], {
|
|
3715
3715
|
variants: {
|
|
3716
3716
|
isClickable: {
|
|
3717
3717
|
true: ["hover:bg-slate-50", "component-card-border"],
|
|
@@ -3721,38 +3721,61 @@ const cvaKPICard = cvaMerge(["w-full", "bg-white", "pl-6", "pr-8", "py-4", "flex
|
|
|
3721
3721
|
true: ["bg-primary-50", "border-primary-600"],
|
|
3722
3722
|
false: [],
|
|
3723
3723
|
},
|
|
3724
|
+
variant: {
|
|
3725
|
+
small: ["px-3"],
|
|
3726
|
+
default: ["min-w-40"],
|
|
3727
|
+
},
|
|
3724
3728
|
},
|
|
3725
3729
|
defaultVariants: {
|
|
3726
3730
|
isClickable: false,
|
|
3727
3731
|
isActive: false,
|
|
3732
|
+
variant: "default",
|
|
3733
|
+
},
|
|
3734
|
+
});
|
|
3735
|
+
const cvaKPICardTrendPercentage = cvaMerge([""], {
|
|
3736
|
+
variants: {
|
|
3737
|
+
color: {
|
|
3738
|
+
success: ["text-success-500"],
|
|
3739
|
+
danger: ["text-danger-500"],
|
|
3740
|
+
neutral: ["text-neutral-500"],
|
|
3741
|
+
},
|
|
3742
|
+
},
|
|
3743
|
+
defaultVariants: {
|
|
3744
|
+
color: "success",
|
|
3728
3745
|
},
|
|
3729
3746
|
});
|
|
3730
|
-
const
|
|
3747
|
+
const cvaKPICardValueContainer = cvaMerge([], {
|
|
3731
3748
|
variants: {
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
warning: "bg-yellow-500",
|
|
3736
|
-
danger: "bg-red-500",
|
|
3749
|
+
isDefaultAndHasTrendValue: {
|
|
3750
|
+
true: [],
|
|
3751
|
+
false: ["flex", "flex-row", "items-center", "gap-1"],
|
|
3737
3752
|
},
|
|
3738
3753
|
},
|
|
3739
3754
|
defaultVariants: {
|
|
3740
|
-
|
|
3755
|
+
isDefaultAndHasTrendValue: true,
|
|
3741
3756
|
},
|
|
3742
3757
|
});
|
|
3743
3758
|
|
|
3744
|
-
const LoadingContent = () => (
|
|
3759
|
+
const LoadingContent = () => (jsx("div", { className: "flex flex-row items-center gap-3", "data-testid": "kpi-card-loading-content", children: jsx("div", { className: "w-full", children: jsx(SkeletonLines, { height: [18, 20], lines: 2, margin: "3px 0", width: [50, 100] }) }) }));
|
|
3745
3760
|
/**
|
|
3746
3761
|
* The KPICard component is used to display KPIs.
|
|
3747
3762
|
*
|
|
3748
3763
|
* @param {KPICardProps} props - The props for the KPICard component
|
|
3749
3764
|
* @returns {JSX.Element} KPICard component
|
|
3750
3765
|
*/
|
|
3751
|
-
const KPICard = ({ asChild = false, title, value, loading, unit,
|
|
3766
|
+
const KPICard = ({ asChild = false, title, value, loading, unit, className, dataTestId, tooltipLabel, isActive, variant = "default", trend, onClick, ...rest }) => {
|
|
3752
3767
|
const Comp = asChild ? Slot : "div";
|
|
3753
|
-
const
|
|
3754
|
-
|
|
3768
|
+
const isSmallVariant = variant === "small";
|
|
3769
|
+
const TrendIndicator = () => {
|
|
3770
|
+
var _a, _b;
|
|
3771
|
+
if (!trend) {
|
|
3772
|
+
return null;
|
|
3773
|
+
}
|
|
3774
|
+
return (jsxs("div", { className: "flex flex-row items-center gap-1", "data-testid": "trend-indicator", children: [!isSmallVariant && trend.value ? (jsxs(Text, { dataTestId: "trend-value", size: "small", weight: "normal", children: [trend.value, " ", unit] })) : null, ((_a = trend.variant) === null || _a === void 0 ? void 0 : _a.icon) ? jsx(Icon, { color: trend.variant.color, name: trend.variant.icon, size: "small" }) : null, trend.percentage ? (jsxs(Text, { className: cvaKPICardTrendPercentage({ color: (_b = trend.variant) === null || _b === void 0 ? void 0 : _b.color }), size: "small", weight: "bold", children: [trend.percentage, "%"] })) : null] }));
|
|
3755
3775
|
};
|
|
3776
|
+
const CardContent = () => (jsx(Card, { className: cvaKPICard({ isClickable: Boolean((onClick || asChild) && !loading), isActive, variant }), children: loading ? (jsx(LoadingContent, {})) : (jsxs("div", { children: [jsx(Text, { dataTestId: `${dataTestId}-title`, size: isSmallVariant ? "small" : "medium", subtle: true, weight: isSmallVariant ? "normal" : "bold", children: title }), jsx(Text, { className: isSmallVariant ? "mt-0.5" : "", dataTestId: `${dataTestId}-value`, size: isSmallVariant ? "small" : "large", type: "div", weight: isSmallVariant ? "bold" : "thick", children: jsxs("div", { className: cvaKPICardValueContainer({
|
|
3777
|
+
isDefaultAndHasTrendValue: Boolean((trend === null || trend === void 0 ? void 0 : trend.value) && !isSmallVariant),
|
|
3778
|
+
}), children: [jsxs("span", { children: [value, " ", unit] }), jsx(TrendIndicator, {})] }) })] })) }));
|
|
3756
3779
|
return (jsxs(Comp, { className: cvaKPICardContainer({ className, isClickable: Boolean(asChild || onClick) }), "data-testid": `${dataTestId}-comp`, onClick: onClick, ...rest, children: [tooltipLabel ? (jsx(Tooltip, { className: "w-full", label: tooltipLabel, placement: "bottom", children: jsx(CardContent, {}) })) : (jsx(CardContent, {})), !loading && jsx(Slottable, { children: rest.children })] }));
|
|
3757
3780
|
};
|
|
3758
3781
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { IntentColors } from "@trackunit/ui-design-tokens";
|
|
2
|
-
import { IconName } from "@trackunit/ui-icons";
|
|
3
1
|
import { ReactNode } from "react";
|
|
4
2
|
import { CommonProps } from "../../common";
|
|
5
3
|
export interface KPICardProps extends CommonProps {
|
|
@@ -19,14 +17,6 @@ export interface KPICardProps extends CommonProps {
|
|
|
19
17
|
* Whether or not to show the loading state
|
|
20
18
|
*/
|
|
21
19
|
loading?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* The icon to be displayed in the prefix
|
|
24
|
-
*/
|
|
25
|
-
iconName?: IconName;
|
|
26
|
-
/**
|
|
27
|
-
* The icon to be displayed in the prefix
|
|
28
|
-
*/
|
|
29
|
-
iconBackgroundColor?: IntentColors;
|
|
30
20
|
/**
|
|
31
21
|
* Use asChild to render the KPICard as another component
|
|
32
22
|
*/
|
|
@@ -49,6 +39,36 @@ export interface KPICardProps extends CommonProps {
|
|
|
49
39
|
* Is the kpi card active
|
|
50
40
|
*/
|
|
51
41
|
isActive?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The size of the KPI Card
|
|
44
|
+
*/
|
|
45
|
+
variant?: "small" | "default";
|
|
46
|
+
/**
|
|
47
|
+
* The trend of the KPI Card
|
|
48
|
+
*/
|
|
49
|
+
trend?: {
|
|
50
|
+
/**
|
|
51
|
+
* The value of the trend
|
|
52
|
+
*/
|
|
53
|
+
value?: number | string;
|
|
54
|
+
/**
|
|
55
|
+
* The percentage of the trend
|
|
56
|
+
*/
|
|
57
|
+
percentage?: number | string;
|
|
58
|
+
/**
|
|
59
|
+
* The variant of the trend
|
|
60
|
+
*/
|
|
61
|
+
variant?: {
|
|
62
|
+
/**
|
|
63
|
+
* The icon of the trend
|
|
64
|
+
*/
|
|
65
|
+
icon?: "ArrowUp" | "ArrowDown" | "ArrowTrendingUp" | "ArrowTrendingDown";
|
|
66
|
+
/**
|
|
67
|
+
* The color of the trend
|
|
68
|
+
*/
|
|
69
|
+
color?: "success" | "danger" | "neutral";
|
|
70
|
+
};
|
|
71
|
+
};
|
|
52
72
|
/**
|
|
53
73
|
* On kpi card click handler
|
|
54
74
|
*/
|
|
@@ -60,4 +80,4 @@ export interface KPICardProps extends CommonProps {
|
|
|
60
80
|
* @param {KPICardProps} props - The props for the KPICard component
|
|
61
81
|
* @returns {JSX.Element} KPICard component
|
|
62
82
|
*/
|
|
63
|
-
export declare const KPICard: ({ asChild, title, value, loading, unit,
|
|
83
|
+
export declare const KPICard: ({ asChild, title, value, loading, unit, className, dataTestId, tooltipLabel, isActive, variant, trend, onClick, ...rest }: KPICardProps) => JSX.Element;
|
|
@@ -4,7 +4,11 @@ export declare const cvaKPICardContainer: (props?: ({
|
|
|
4
4
|
export declare const cvaKPICard: (props?: ({
|
|
5
5
|
isClickable?: boolean | null | undefined;
|
|
6
6
|
isActive?: boolean | null | undefined;
|
|
7
|
+
variant?: "default" | "small" | null | undefined;
|
|
7
8
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
8
|
-
export declare const
|
|
9
|
-
|
|
9
|
+
export declare const cvaKPICardTrendPercentage: (props?: ({
|
|
10
|
+
color?: "success" | "danger" | "neutral" | null | undefined;
|
|
11
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
12
|
+
export declare const cvaKPICardValueContainer: (props?: ({
|
|
13
|
+
isDefaultAndHasTrendValue?: boolean | null | undefined;
|
|
10
14
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|