@trackunit/react-components 0.0.129 → 0.0.131
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/components/ActionButton/ActionButton.d.ts +25 -0
- package/components/ActionButton/index.d.ts +1 -0
- package/components/ValueBar/ValueBar.d.ts +44 -0
- package/components/ValueBar/ValueBarHelper.d.ts +42 -0
- package/components/ValueBar/ValueBarTypes.d.ts +9 -0
- package/components/ValueBar/index.d.ts +3 -0
- package/components/index.d.ts +2 -0
- package/index.css +20 -3
- package/index.js +252 -20
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { CommonProps } from "../../common";
|
|
3
|
+
declare type ActionType = "PHONE_NUMBER" | "WEB_ADDRESS" | "EMAIL";
|
|
4
|
+
interface ActionButtonProps extends CommonProps {
|
|
5
|
+
/**
|
|
6
|
+
* The type of action performed when clicking the button.
|
|
7
|
+
*/
|
|
8
|
+
type: ActionType;
|
|
9
|
+
/**
|
|
10
|
+
* The value to be passed into the button.
|
|
11
|
+
*/
|
|
12
|
+
value?: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* The onClick event.
|
|
15
|
+
*/
|
|
16
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The ActionButton component is a wrapper over IconButton to perform an action when the onClick event is triggered.
|
|
20
|
+
*
|
|
21
|
+
* @param {ActionButtonProps} props - The props for the ActionButton component
|
|
22
|
+
* @returns {JSX.Element} ActionButton component
|
|
23
|
+
*/
|
|
24
|
+
export declare const ActionButton: ({ type, value }: ActionButtonProps) => JSX.Element;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ActionButton";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LevelColors } from "./ValueBarTypes";
|
|
3
|
+
import { CommonProps } from "../../common";
|
|
4
|
+
export interface ValueBarProps extends CommonProps {
|
|
5
|
+
/**
|
|
6
|
+
* Value to display.
|
|
7
|
+
*/
|
|
8
|
+
value: number;
|
|
9
|
+
/**
|
|
10
|
+
* Minimum value visible on the bar.
|
|
11
|
+
*/
|
|
12
|
+
min?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum value visible on the bar.
|
|
15
|
+
*/
|
|
16
|
+
max?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Value unit. Visible only together with value if showValue parameter is set to true.
|
|
19
|
+
*/
|
|
20
|
+
unit?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Size of the tooltip
|
|
23
|
+
*/
|
|
24
|
+
size?: "small" | "large";
|
|
25
|
+
/**
|
|
26
|
+
* Custom level colors. If this param is not provided then default values are used.
|
|
27
|
+
*/
|
|
28
|
+
levelColors?: LevelColors;
|
|
29
|
+
/**
|
|
30
|
+
* Custom value color. If this param is not provided then default value is used.
|
|
31
|
+
*/
|
|
32
|
+
valueColor?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Show value with unit (if provided) on the bar in large version or after the bar in the small version.
|
|
35
|
+
*/
|
|
36
|
+
showValue?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* ValueBar component is used to display value on a colorful bar within provided range.
|
|
40
|
+
*
|
|
41
|
+
* @param {ValueBarProps} props - The props for the ValueBar component
|
|
42
|
+
* @returns {JSX.Element} ValueBar component
|
|
43
|
+
*/
|
|
44
|
+
export declare const ValueBar: ({ value, min, max, unit, size, levelColors, valueColor, showValue, className, dataTestId }: ValueBarProps) => JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LevelColors } from "./ValueBarTypes";
|
|
2
|
+
/**
|
|
3
|
+
* Helper function to get normalized score in range 0-1 used by the ValueBar
|
|
4
|
+
*
|
|
5
|
+
* @param {number} value - value for which score should be returned
|
|
6
|
+
* @param {number} min - min range value
|
|
7
|
+
* @param {number} max - max range value
|
|
8
|
+
* @returns {number} normalized score
|
|
9
|
+
*/
|
|
10
|
+
export declare const getScore: (value: number, min: number, max: number) => number;
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to get default color used by the ValueBar
|
|
13
|
+
*
|
|
14
|
+
* @param {number} score - score number for which color should be returned
|
|
15
|
+
* @returns {string} color value
|
|
16
|
+
*/
|
|
17
|
+
export declare const getDefaultFillColor: (score: number) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Helper function to get normalized color
|
|
20
|
+
*
|
|
21
|
+
* @param {number} levelColor - color, ex --color-green-600
|
|
22
|
+
* @returns {string} normalized color value
|
|
23
|
+
*/
|
|
24
|
+
export declare const getNormalizedLevelColor: (levelColor: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to get custom color used by the ValueBar
|
|
27
|
+
*
|
|
28
|
+
* @param {number} score - score number for which color should be returned
|
|
29
|
+
* @param {LevelColors} levelColors - custom colors and levels definitions
|
|
30
|
+
* @returns {string} color value
|
|
31
|
+
*/
|
|
32
|
+
export declare const getFillColor: (score: number, levelColors: LevelColors) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Helper function to get color used by the ValueBar
|
|
35
|
+
*
|
|
36
|
+
* @param {number} value - value for which color should be returned
|
|
37
|
+
* @param {number} min - min range value
|
|
38
|
+
* @param {number} max - max range value
|
|
39
|
+
* @param {LevelColors} levelColors - level colors used to coloring the bar
|
|
40
|
+
* @returns {JSX.Element} ValueBar component
|
|
41
|
+
*/
|
|
42
|
+
export declare const getValueBarColorByValue: (value: number, min: number, max: number, levelColors: LevelColors) => string;
|
package/components/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./ActionButton";
|
|
1
2
|
export * from "./Alert";
|
|
2
3
|
export * from "./Badge";
|
|
3
4
|
export * from "./BaseInput";
|
|
@@ -38,3 +39,4 @@ export * from "./Timeline/Timeline";
|
|
|
38
39
|
export * from "./Tip";
|
|
39
40
|
export * from "./Toggle";
|
|
40
41
|
export * from "./Tooltip";
|
|
42
|
+
export * from "./ValueBar";
|
package/index.css
CHANGED
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
rounded-lg
|
|
17
17
|
cursor-pointer
|
|
18
18
|
flex-none
|
|
19
|
-
|
|
20
|
-
px-3
|
|
19
|
+
p-2.5
|
|
21
20
|
h-min
|
|
22
21
|
drop-shadow
|
|
23
22
|
focus:ring
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
&--small {
|
|
49
|
-
@apply
|
|
48
|
+
@apply p-2;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
&--large {
|
|
@@ -161,6 +160,24 @@
|
|
|
161
160
|
hover:bg-slate-600/10
|
|
162
161
|
disabled:hover:bg-transparent;
|
|
163
162
|
}
|
|
163
|
+
|
|
164
|
+
&__container {
|
|
165
|
+
@apply w-5
|
|
166
|
+
h-5
|
|
167
|
+
flex
|
|
168
|
+
justify-center
|
|
169
|
+
items-center
|
|
170
|
+
box-border;
|
|
171
|
+
|
|
172
|
+
&--small {
|
|
173
|
+
@apply w-4
|
|
174
|
+
h-4
|
|
175
|
+
flex
|
|
176
|
+
justify-center
|
|
177
|
+
items-center
|
|
178
|
+
box-border;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
164
181
|
}
|
|
165
182
|
|
|
166
183
|
/* CSS related to the LAbel component */
|
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import ReactAsyncCreatableSelect from 'react-select/async-creatable';
|
|
|
19
19
|
import ReactCreatableSelect from 'react-select/creatable';
|
|
20
20
|
import ReactAsyncSelect from 'react-select/async';
|
|
21
21
|
import { format, formatDistance } from 'date-fns';
|
|
22
|
+
import { getColorValue } from '@trackunit/ui-design-tokens';
|
|
22
23
|
|
|
23
24
|
const docs = {
|
|
24
25
|
source: {
|
|
@@ -287,12 +288,20 @@ const IconButton = React.forwardRef((_a, ref) => {
|
|
|
287
288
|
disabled: disabled || loading,
|
|
288
289
|
ref: ref
|
|
289
290
|
}, rest, {
|
|
290
|
-
children:
|
|
291
|
+
children: jsx(IconContainer$2, {
|
|
292
|
+
children: loading ? jsx(Spinner, {
|
|
293
|
+
size: size
|
|
294
|
+
}) : icon
|
|
295
|
+
})
|
|
291
296
|
}));
|
|
292
297
|
});
|
|
293
298
|
const StyledButton = tw(Button)`
|
|
294
299
|
${p => p.$circular ? tws`tu-button--rounded` : null}
|
|
295
300
|
`;
|
|
301
|
+
const IconContainer$2 = tw.div`
|
|
302
|
+
tu-button__container
|
|
303
|
+
${p => p.$size === "small" ? tws`tu-button__container--small` : null}
|
|
304
|
+
`;
|
|
296
305
|
|
|
297
306
|
/**
|
|
298
307
|
* ? A collection of all the types and tokens related to the named colors in the default theme.
|
|
@@ -392,7 +401,7 @@ const Icon$1 = ({
|
|
|
392
401
|
className: iconSizeClassName
|
|
393
402
|
})
|
|
394
403
|
}, {
|
|
395
|
-
children: jsx(Root$
|
|
404
|
+
children: jsx(Root$4, Object.assign({
|
|
396
405
|
"$color": color,
|
|
397
406
|
onClick: onClick,
|
|
398
407
|
"data-testid": dataTestId,
|
|
@@ -411,7 +420,7 @@ const Icon$1 = ({
|
|
|
411
420
|
const LoadingDot = tw.span`
|
|
412
421
|
tu-loading-dot
|
|
413
422
|
`;
|
|
414
|
-
const Root$
|
|
423
|
+
const Root$4 = tw.span`
|
|
415
424
|
tu-icon
|
|
416
425
|
${({
|
|
417
426
|
$color
|
|
@@ -465,6 +474,69 @@ const Root$3 = tw.span`
|
|
|
465
474
|
}}
|
|
466
475
|
`;
|
|
467
476
|
|
|
477
|
+
/**
|
|
478
|
+
* The ActionButton component is a wrapper over IconButton to perform an action when the onClick event is triggered.
|
|
479
|
+
*
|
|
480
|
+
* @param {ActionButtonProps} props - The props for the ActionButton component
|
|
481
|
+
* @returns {JSX.Element} ActionButton component
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
const ActionButton = ({
|
|
485
|
+
type,
|
|
486
|
+
value
|
|
487
|
+
}) => {
|
|
488
|
+
const getIconName = () => {
|
|
489
|
+
switch (type) {
|
|
490
|
+
case "PHONE_NUMBER":
|
|
491
|
+
return "PhoneOutgoingIcon";
|
|
492
|
+
|
|
493
|
+
case "WEB_ADDRESS":
|
|
494
|
+
return "ExternalLinkIcon";
|
|
495
|
+
|
|
496
|
+
case "EMAIL":
|
|
497
|
+
default:
|
|
498
|
+
return "MailIcon";
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
const ButtonAction = () => {
|
|
503
|
+
switch (type) {
|
|
504
|
+
case "EMAIL":
|
|
505
|
+
return window.open(`mailto:${value}`);
|
|
506
|
+
|
|
507
|
+
case "WEB_ADDRESS":
|
|
508
|
+
if (value) {
|
|
509
|
+
return window.open(value, "_blank", "noopener,noreferrer");
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return null;
|
|
513
|
+
|
|
514
|
+
case "PHONE_NUMBER":
|
|
515
|
+
default:
|
|
516
|
+
return window.open(`tel:${value}`);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
return jsx(ActionContainer, {
|
|
521
|
+
children: jsx(StyledIconButton, {
|
|
522
|
+
dataTestId: "testIconButtonId",
|
|
523
|
+
size: "small",
|
|
524
|
+
intent: "tertiary",
|
|
525
|
+
icon: jsx(Icon$1, {
|
|
526
|
+
size: "small",
|
|
527
|
+
name: getIconName()
|
|
528
|
+
}),
|
|
529
|
+
onClick: ButtonAction
|
|
530
|
+
})
|
|
531
|
+
});
|
|
532
|
+
};
|
|
533
|
+
const ActionContainer = tw.div`
|
|
534
|
+
tu-action-container
|
|
535
|
+
`;
|
|
536
|
+
const StyledIconButton = tw(IconButton)`
|
|
537
|
+
tu-action-button
|
|
538
|
+
`;
|
|
539
|
+
|
|
468
540
|
/**
|
|
469
541
|
* The StarButton component is used for favorite actions or similar.
|
|
470
542
|
*
|
|
@@ -510,7 +582,7 @@ const CustomIcon = tw(Icon$1)`
|
|
|
510
582
|
* @returns {JSX.Element} Text component
|
|
511
583
|
*/
|
|
512
584
|
|
|
513
|
-
const Text = ({
|
|
585
|
+
const Text$1 = ({
|
|
514
586
|
children,
|
|
515
587
|
type = "p",
|
|
516
588
|
size = "medium",
|
|
@@ -656,7 +728,7 @@ const Alert = ({
|
|
|
656
728
|
};
|
|
657
729
|
|
|
658
730
|
const body = inline ? jsxs("div", {
|
|
659
|
-
children: [title && jsx(Text, Object.assign({
|
|
731
|
+
children: [title && jsx(Text$1, Object.assign({
|
|
660
732
|
weight: "bold"
|
|
661
733
|
}, {
|
|
662
734
|
children: title !== null && title !== void 0 ? title : children
|
|
@@ -667,7 +739,7 @@ const Alert = ({
|
|
|
667
739
|
children: children
|
|
668
740
|
}))]
|
|
669
741
|
}) : jsxs(Fragment, {
|
|
670
|
-
children: [title && jsx(Text, Object.assign({
|
|
742
|
+
children: [title && jsx(Text$1, Object.assign({
|
|
671
743
|
weight: "bold"
|
|
672
744
|
}, {
|
|
673
745
|
children: title !== null && title !== void 0 ? title : children
|
|
@@ -785,7 +857,7 @@ const ContentDetails = tw.div`
|
|
|
785
857
|
const ContentBody = tw.div`
|
|
786
858
|
tu-alert__content-body
|
|
787
859
|
`;
|
|
788
|
-
const Description$2 = tw(Text)`
|
|
860
|
+
const Description$2 = tw(Text$1)`
|
|
789
861
|
${p => p.$hasTitle ? tws`tu-alert__description` : null}
|
|
790
862
|
`;
|
|
791
863
|
const RightAligned = tw.div`
|
|
@@ -1373,7 +1445,7 @@ const Chart = ({
|
|
|
1373
1445
|
children: showLoading ? jsxs(SpinnerContainer, {
|
|
1374
1446
|
children: [jsx(Spinner, {
|
|
1375
1447
|
centered: true
|
|
1376
|
-
}), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && jsx(Text, Object.assign({
|
|
1448
|
+
}), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && jsx(Text$1, Object.assign({
|
|
1377
1449
|
align: "center",
|
|
1378
1450
|
subtle: true
|
|
1379
1451
|
}, {
|
|
@@ -1421,7 +1493,7 @@ const Label$3 = ({
|
|
|
1421
1493
|
disabled,
|
|
1422
1494
|
isInvalid
|
|
1423
1495
|
}) => {
|
|
1424
|
-
return jsx(Root$
|
|
1496
|
+
return jsx(Root$3, Object.assign({
|
|
1425
1497
|
id: id || "",
|
|
1426
1498
|
htmlFor: htmlFor || "",
|
|
1427
1499
|
className: className,
|
|
@@ -1432,7 +1504,7 @@ const Label$3 = ({
|
|
|
1432
1504
|
children: children
|
|
1433
1505
|
}));
|
|
1434
1506
|
};
|
|
1435
|
-
const Root$
|
|
1507
|
+
const Root$3 = tw.label`
|
|
1436
1508
|
tu-label
|
|
1437
1509
|
${({
|
|
1438
1510
|
$disabled
|
|
@@ -1633,7 +1705,7 @@ const Collapse = ({
|
|
|
1633
1705
|
onClick: handleClick
|
|
1634
1706
|
}, {
|
|
1635
1707
|
children: jsxs(LabelContainer$2, {
|
|
1636
|
-
children: [jsx(Text, Object.assign({
|
|
1708
|
+
children: [jsx(Text$1, Object.assign({
|
|
1637
1709
|
weight: "bold"
|
|
1638
1710
|
}, {
|
|
1639
1711
|
children: label
|
|
@@ -2149,7 +2221,7 @@ const PopoverListItem = ({
|
|
|
2149
2221
|
})) : content
|
|
2150
2222
|
}));
|
|
2151
2223
|
};
|
|
2152
|
-
const StyledText$2 = tw(Text)`
|
|
2224
|
+
const StyledText$2 = tw(Text$1)`
|
|
2153
2225
|
tu-popover-list-item__text
|
|
2154
2226
|
${p => p.$selected && tws`tu-popover-list-item__text--selected`}
|
|
2155
2227
|
`;
|
|
@@ -2196,7 +2268,7 @@ const Container$6 = tw.div`
|
|
|
2196
2268
|
tu-popover-title-container
|
|
2197
2269
|
${p => p.$divider && `tu-popover-title-container--divider`}
|
|
2198
2270
|
`;
|
|
2199
|
-
const StyledText$1 = tw(Text)`
|
|
2271
|
+
const StyledText$1 = tw(Text$1)`
|
|
2200
2272
|
tu-popover-title-text
|
|
2201
2273
|
`;
|
|
2202
2274
|
|
|
@@ -2252,7 +2324,7 @@ const Tooltip = ({
|
|
|
2252
2324
|
children: jsx(Content, Object.assign({
|
|
2253
2325
|
"$mode": mode
|
|
2254
2326
|
}, {
|
|
2255
|
-
children: jsx(Text, Object.assign({
|
|
2327
|
+
children: jsx(Text$1, Object.assign({
|
|
2256
2328
|
inverted: mode === "dark",
|
|
2257
2329
|
type: contentTextType
|
|
2258
2330
|
}, {
|
|
@@ -2650,7 +2722,7 @@ const LegendItem = ({
|
|
|
2650
2722
|
dataTestId
|
|
2651
2723
|
}) => {
|
|
2652
2724
|
const handleOnClick = onClick && !disabled ? () => onClick() : undefined;
|
|
2653
|
-
return jsxs(Root$
|
|
2725
|
+
return jsxs(Root$2, Object.assign({
|
|
2654
2726
|
"data-testid": dataTestId,
|
|
2655
2727
|
disabled: disabled,
|
|
2656
2728
|
className: className,
|
|
@@ -2666,7 +2738,7 @@ const LegendItem = ({
|
|
|
2666
2738
|
})]
|
|
2667
2739
|
}));
|
|
2668
2740
|
};
|
|
2669
|
-
const Root$
|
|
2741
|
+
const Root$2 = tw.div`
|
|
2670
2742
|
inline-flex
|
|
2671
2743
|
items-center
|
|
2672
2744
|
transition-all
|
|
@@ -3509,7 +3581,7 @@ const Container$1 = tw.label`
|
|
|
3509
3581
|
$isDisabled
|
|
3510
3582
|
}) => $isDisabled ? tws`tu-select--disabled` : null}
|
|
3511
3583
|
`;
|
|
3512
|
-
const InformativeText = tw(Text)`
|
|
3584
|
+
const InformativeText = tw(Text$1)`
|
|
3513
3585
|
tu-informative-text
|
|
3514
3586
|
${p => p.$hasError ? `tu-informative-text--error` : null}
|
|
3515
3587
|
`;
|
|
@@ -4472,11 +4544,11 @@ const TextLengthIndicator = ({
|
|
|
4472
4544
|
length,
|
|
4473
4545
|
maxLength
|
|
4474
4546
|
}) => {
|
|
4475
|
-
return jsxs(Root, {
|
|
4547
|
+
return jsxs(Root$1, {
|
|
4476
4548
|
children: [length, "/", maxLength]
|
|
4477
4549
|
});
|
|
4478
4550
|
};
|
|
4479
|
-
const Root = tw.span`
|
|
4551
|
+
const Root$1 = tw.span`
|
|
4480
4552
|
font-mono
|
|
4481
4553
|
`;
|
|
4482
4554
|
|
|
@@ -4768,6 +4840,166 @@ ${({
|
|
|
4768
4840
|
}) => $disabled && tws`tu-toggle__description--disabled`}
|
|
4769
4841
|
`;
|
|
4770
4842
|
|
|
4843
|
+
/**
|
|
4844
|
+
* Helper function to get normalized score in range 0-1 used by the ValueBar
|
|
4845
|
+
*
|
|
4846
|
+
* @param {number} value - value for which score should be returned
|
|
4847
|
+
* @param {number} min - min range value
|
|
4848
|
+
* @param {number} max - max range value
|
|
4849
|
+
* @returns {number} normalized score
|
|
4850
|
+
*/
|
|
4851
|
+
|
|
4852
|
+
const getScore = (value, min, max) => {
|
|
4853
|
+
if (value <= min) {
|
|
4854
|
+
return 0.01; // always render at least some small fragment
|
|
4855
|
+
}
|
|
4856
|
+
|
|
4857
|
+
if (value >= max) {
|
|
4858
|
+
return 1;
|
|
4859
|
+
}
|
|
4860
|
+
|
|
4861
|
+
return (value - min) / (max - min);
|
|
4862
|
+
};
|
|
4863
|
+
/**
|
|
4864
|
+
* Helper function to get default color used by the ValueBar
|
|
4865
|
+
*
|
|
4866
|
+
* @param {number} score - score number for which color should be returned
|
|
4867
|
+
* @returns {string} color value
|
|
4868
|
+
*/
|
|
4869
|
+
|
|
4870
|
+
const getDefaultFillColor = score => {
|
|
4871
|
+
if (score < 0.3) {
|
|
4872
|
+
return getColorValue("--color-red-500");
|
|
4873
|
+
}
|
|
4874
|
+
|
|
4875
|
+
if (score >= 0.6) {
|
|
4876
|
+
return getColorValue("--color-green-600");
|
|
4877
|
+
}
|
|
4878
|
+
|
|
4879
|
+
return getColorValue("--color-amber-300");
|
|
4880
|
+
};
|
|
4881
|
+
/**
|
|
4882
|
+
* Helper function to get normalized color
|
|
4883
|
+
*
|
|
4884
|
+
* @param {number} levelColor - color, ex --color-green-600
|
|
4885
|
+
* @returns {string} normalized color value
|
|
4886
|
+
*/
|
|
4887
|
+
|
|
4888
|
+
const getNormalizedLevelColor = levelColor => {
|
|
4889
|
+
if (levelColor.startsWith("--color")) {
|
|
4890
|
+
return getColorValue(levelColor);
|
|
4891
|
+
}
|
|
4892
|
+
|
|
4893
|
+
return levelColor;
|
|
4894
|
+
};
|
|
4895
|
+
/**
|
|
4896
|
+
* Helper function to get custom color used by the ValueBar
|
|
4897
|
+
*
|
|
4898
|
+
* @param {number} score - score number for which color should be returned
|
|
4899
|
+
* @param {LevelColors} levelColors - custom colors and levels definitions
|
|
4900
|
+
* @returns {string} color value
|
|
4901
|
+
*/
|
|
4902
|
+
|
|
4903
|
+
const getFillColor = (score, levelColors) => {
|
|
4904
|
+
var _a, _b;
|
|
4905
|
+
|
|
4906
|
+
if (levelColors.low && score < (levelColors.low.level || 0)) {
|
|
4907
|
+
return getNormalizedLevelColor(levelColors.low.color);
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
if (levelColors.high && score >= (levelColors.high.level || 0)) {
|
|
4911
|
+
return getNormalizedLevelColor(levelColors.high.color);
|
|
4912
|
+
}
|
|
4913
|
+
|
|
4914
|
+
return getNormalizedLevelColor((_b = (_a = levelColors.medium) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : "--color-amber-300");
|
|
4915
|
+
};
|
|
4916
|
+
/**
|
|
4917
|
+
* Helper function to get color used by the ValueBar
|
|
4918
|
+
*
|
|
4919
|
+
* @param {number} value - value for which color should be returned
|
|
4920
|
+
* @param {number} min - min range value
|
|
4921
|
+
* @param {number} max - max range value
|
|
4922
|
+
* @param {LevelColors} levelColors - level colors used to coloring the bar
|
|
4923
|
+
* @returns {JSX.Element} ValueBar component
|
|
4924
|
+
*/
|
|
4925
|
+
|
|
4926
|
+
const getValueBarColorByValue = (value, min, max, levelColors) => {
|
|
4927
|
+
const score = getScore(value, min, max);
|
|
4928
|
+
return getFillColor(score, levelColors);
|
|
4929
|
+
};
|
|
4930
|
+
|
|
4931
|
+
/**
|
|
4932
|
+
* ValueBar component is used to display value on a colorful bar within provided range.
|
|
4933
|
+
*
|
|
4934
|
+
* @param {ValueBarProps} props - The props for the ValueBar component
|
|
4935
|
+
* @returns {JSX.Element} ValueBar component
|
|
4936
|
+
*/
|
|
4937
|
+
|
|
4938
|
+
const ValueBar = ({
|
|
4939
|
+
value,
|
|
4940
|
+
min = 0,
|
|
4941
|
+
max = 100,
|
|
4942
|
+
unit,
|
|
4943
|
+
size = "small",
|
|
4944
|
+
levelColors,
|
|
4945
|
+
valueColor,
|
|
4946
|
+
showValue,
|
|
4947
|
+
className,
|
|
4948
|
+
dataTestId
|
|
4949
|
+
}) => {
|
|
4950
|
+
const score = getScore(value, min, max);
|
|
4951
|
+
const barFillColor = levelColors ? getFillColor(score, levelColors) : getDefaultFillColor(score);
|
|
4952
|
+
const barWidth = showValue && size === "small" ? 90 : 100;
|
|
4953
|
+
return jsx(Root, Object.assign({
|
|
4954
|
+
className: className,
|
|
4955
|
+
"data-testid": dataTestId,
|
|
4956
|
+
"$size": size
|
|
4957
|
+
}, {
|
|
4958
|
+
children: jsxs("g", {
|
|
4959
|
+
children: [jsx(Background, {
|
|
4960
|
+
width: `${barWidth}%`,
|
|
4961
|
+
rx: "5"
|
|
4962
|
+
}), jsx(Bar, {
|
|
4963
|
+
width: `${score * barWidth}%`,
|
|
4964
|
+
fill: barFillColor,
|
|
4965
|
+
rx: "5"
|
|
4966
|
+
}), showValue && size === "large" && jsxs(Text, Object.assign({
|
|
4967
|
+
"$size": size,
|
|
4968
|
+
x: "12",
|
|
4969
|
+
y: "23",
|
|
4970
|
+
fill: valueColor !== null && valueColor !== void 0 ? valueColor : "white"
|
|
4971
|
+
}, {
|
|
4972
|
+
children: [Number(value.toFixed(1)), unit || ""]
|
|
4973
|
+
})), showValue && size === "small" && jsxs(Text, Object.assign({
|
|
4974
|
+
"$size": size,
|
|
4975
|
+
x: `${barWidth + 2}%`,
|
|
4976
|
+
y: "11",
|
|
4977
|
+
fill: valueColor !== null && valueColor !== void 0 ? valueColor : getColorValue("--color-neutral-400")
|
|
4978
|
+
}, {
|
|
4979
|
+
children: [Number(value.toFixed(1)), unit || ""]
|
|
4980
|
+
}))]
|
|
4981
|
+
})
|
|
4982
|
+
}));
|
|
4983
|
+
};
|
|
4984
|
+
const Root = tw.svg`
|
|
4985
|
+
tu-value-bar
|
|
4986
|
+
${({
|
|
4987
|
+
$size
|
|
4988
|
+
}) => $size === "small" ? tws`tu-value-bar--small` : tws`tu-value-bar--large`}
|
|
4989
|
+
`;
|
|
4990
|
+
const Text = tw.text`
|
|
4991
|
+
tu-value-bar__text
|
|
4992
|
+
${({
|
|
4993
|
+
$size
|
|
4994
|
+
}) => $size === "small" ? tws`tu-value-bar__text--small` : tws`tu-value-bar__text--large`}
|
|
4995
|
+
`;
|
|
4996
|
+
const Background = tw.rect`
|
|
4997
|
+
tu-value-bar__background
|
|
4998
|
+
`;
|
|
4999
|
+
const Bar = tw.rect`
|
|
5000
|
+
tu-value-bar__bar
|
|
5001
|
+
`;
|
|
5002
|
+
|
|
4771
5003
|
/**
|
|
4772
5004
|
* The useDebounce hook works like useState, but adds a delay where previous values will be ignored.
|
|
4773
5005
|
*
|
|
@@ -5131,4 +5363,4 @@ const Layout = tw.div`
|
|
|
5131
5363
|
tu-layout-TwoColumnLayout
|
|
5132
5364
|
`;
|
|
5133
5365
|
|
|
5134
|
-
export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$3 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MultiSelectMenuItem, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, getOrderedOptions, intentColors, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
|
|
5366
|
+
export { ActionButton, Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$3 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MultiSelectMenuItem, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text$1 as Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, ValueBar, activityColors, colors, criticalityColors, docs, generalColors, getOrderedOptions, getValueBarColorByValue, intentColors, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
|