@taiv/ui 2.1.0 → 2.1.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CardProps } from '../../../Layout/Card/Card';
|
|
3
3
|
import { primitives } from '../../../../constants/colors';
|
|
4
|
-
import { formats } from '../../../../constants/data';
|
|
4
|
+
import { formats, truncation } from '../../../../constants/data';
|
|
5
5
|
export interface StatsCardProps extends Omit<CardProps, 'children'> {
|
|
6
6
|
value: number;
|
|
7
7
|
title: string;
|
|
@@ -12,6 +12,7 @@ export interface StatsCardProps extends Omit<CardProps, 'children'> {
|
|
|
12
12
|
iconColor?: keyof typeof primitives;
|
|
13
13
|
tooltip?: React.ReactNode;
|
|
14
14
|
increaseDescription?: string;
|
|
15
|
+
truncateAt?: keyof typeof truncation;
|
|
15
16
|
}
|
|
16
|
-
export declare const StatsCard: ({ value, format, isDelta, title, description, increaseDescription, icon: Icon, iconColor, tooltip, ...cardProps }: StatsCardProps) => React.JSX.Element;
|
|
17
|
+
export declare const StatsCard: ({ value, format, isDelta, title, description, increaseDescription, icon: Icon, iconColor, tooltip, truncateAt, ...cardProps }: StatsCardProps) => React.JSX.Element;
|
|
17
18
|
//# sourceMappingURL=StatsCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatsCard.d.ts","sourceRoot":"","sources":["../../../../../src/components/Data/Cards/StatsCard/StatsCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAQ,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAO5D,OAAO,EAAE,UAAU,EAAoB,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"StatsCard.d.ts","sourceRoot":"","sources":["../../../../../src/components/Data/Cards/StatsCard/StatsCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAQ,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAO5D,OAAO,EAAE,UAAU,EAAoB,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGjE,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,OAAO,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,OAAO,UAAU,CAAC;IACpC,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,OAAO,UAAU,CAAC;CACtC;AAED,eAAO,MAAM,SAAS,GAAI,+HAA4J,cAAc,sBAmEnM,CAAC"}
|
|
@@ -7,9 +7,9 @@ import { Group } from '../../../Layout/Group/Group';
|
|
|
7
7
|
import { Stack } from '../../../Layout/Stack/Stack';
|
|
8
8
|
import { IconBadge } from '../../../Misc/IconBadge/IconBadge';
|
|
9
9
|
import { success, neutral } from '../../../../constants/colors';
|
|
10
|
-
import { formats } from '../../../../constants/data';
|
|
10
|
+
import { formats, truncation } from '../../../../constants/data';
|
|
11
11
|
import { spacing } from '../../../../constants/spacing';
|
|
12
|
-
export const StatsCard = ({ value, format = 'decimal', isDelta = false, title, description, increaseDescription, icon: Icon, iconColor = 'blue', tooltip, ...cardProps }) => {
|
|
12
|
+
export const StatsCard = ({ value, format = 'decimal', isDelta = false, title, description, increaseDescription, icon: Icon, iconColor = 'blue', tooltip, truncateAt, ...cardProps }) => {
|
|
13
13
|
const getDelta = () => {
|
|
14
14
|
const currentDirection = isDelta ? (value > 0 ? 'positive' : value < 0 ? 'negative' : null) : null;
|
|
15
15
|
return {
|
|
@@ -21,10 +21,17 @@ export const StatsCard = ({ value, format = 'decimal', isDelta = false, title, d
|
|
|
21
21
|
const delta = getDelta();
|
|
22
22
|
const formatValue = () => {
|
|
23
23
|
const config = formats[format];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
let formattedNumber;
|
|
25
|
+
if (truncateAt && value >= truncation[truncateAt].threshold) {
|
|
26
|
+
const truncConfig = truncation[truncateAt];
|
|
27
|
+
formattedNumber = `${(value / truncConfig.threshold).toFixed(1)}${truncConfig.suffix}`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
formattedNumber = value.toLocaleString('en-US', {
|
|
31
|
+
minimumFractionDigits: config.decimalPlaces,
|
|
32
|
+
maximumFractionDigits: config.decimalPlaces,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
28
35
|
let result = formattedNumber;
|
|
29
36
|
if (delta.direction === 'positive') {
|
|
30
37
|
result = `+${result}`;
|
package/package.json
CHANGED