@trackunit/react-components 0.0.130 → 0.0.132
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/BaseInput/BaseInput.d.ts +4 -0
- package/components/FormGroup/FormGroup.d.ts +5 -1
- 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 +1 -0
- package/index.js +211 -28
- package/package.json +1 -1
|
@@ -45,6 +45,10 @@ export interface BaseInputProps extends FilteredInputProps, CommonProps {
|
|
|
45
45
|
* The Placeholder text for the input.
|
|
46
46
|
*/
|
|
47
47
|
placeholder?: string;
|
|
48
|
+
/**
|
|
49
|
+
* A flag to disable interaction with input for example if you want to use input as a child of higher component
|
|
50
|
+
*/
|
|
51
|
+
nonInteractive?: boolean;
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
54
|
* A base input component that can be used for text inputs, password inputs, etc.
|
|
@@ -22,6 +22,10 @@ export interface FormGroupProps extends CommonProps {
|
|
|
22
22
|
* If true the input is rendered in its invalid state.
|
|
23
23
|
*/
|
|
24
24
|
isInvalid?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* If true interactions are disabled
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
25
29
|
children?: React.ReactNode;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
@@ -31,4 +35,4 @@ export interface FormGroupProps extends CommonProps {
|
|
|
31
35
|
* @param {FormGroupProps} props - The props for the FormGroup component
|
|
32
36
|
* @returns {JSX.Element} FormGroup component
|
|
33
37
|
*/
|
|
34
|
-
export declare const FormGroup: ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, children, }: FormGroupProps) => JSX.Element;
|
|
38
|
+
export declare const FormGroup: ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, children, disabled, }: FormGroupProps) => JSX.Element;
|
|
@@ -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
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: {
|
|
@@ -400,7 +401,7 @@ const Icon$1 = ({
|
|
|
400
401
|
className: iconSizeClassName
|
|
401
402
|
})
|
|
402
403
|
}, {
|
|
403
|
-
children: jsx(Root$
|
|
404
|
+
children: jsx(Root$4, Object.assign({
|
|
404
405
|
"$color": color,
|
|
405
406
|
onClick: onClick,
|
|
406
407
|
"data-testid": dataTestId,
|
|
@@ -419,7 +420,7 @@ const Icon$1 = ({
|
|
|
419
420
|
const LoadingDot = tw.span`
|
|
420
421
|
tu-loading-dot
|
|
421
422
|
`;
|
|
422
|
-
const Root$
|
|
423
|
+
const Root$4 = tw.span`
|
|
423
424
|
tu-icon
|
|
424
425
|
${({
|
|
425
426
|
$color
|
|
@@ -581,7 +582,7 @@ const CustomIcon = tw(Icon$1)`
|
|
|
581
582
|
* @returns {JSX.Element} Text component
|
|
582
583
|
*/
|
|
583
584
|
|
|
584
|
-
const Text = ({
|
|
585
|
+
const Text$1 = ({
|
|
585
586
|
children,
|
|
586
587
|
type = "p",
|
|
587
588
|
size = "medium",
|
|
@@ -727,7 +728,7 @@ const Alert = ({
|
|
|
727
728
|
};
|
|
728
729
|
|
|
729
730
|
const body = inline ? jsxs("div", {
|
|
730
|
-
children: [title && jsx(Text, Object.assign({
|
|
731
|
+
children: [title && jsx(Text$1, Object.assign({
|
|
731
732
|
weight: "bold"
|
|
732
733
|
}, {
|
|
733
734
|
children: title !== null && title !== void 0 ? title : children
|
|
@@ -738,7 +739,7 @@ const Alert = ({
|
|
|
738
739
|
children: children
|
|
739
740
|
}))]
|
|
740
741
|
}) : jsxs(Fragment, {
|
|
741
|
-
children: [title && jsx(Text, Object.assign({
|
|
742
|
+
children: [title && jsx(Text$1, Object.assign({
|
|
742
743
|
weight: "bold"
|
|
743
744
|
}, {
|
|
744
745
|
children: title !== null && title !== void 0 ? title : children
|
|
@@ -856,7 +857,7 @@ const ContentDetails = tw.div`
|
|
|
856
857
|
const ContentBody = tw.div`
|
|
857
858
|
tu-alert__content-body
|
|
858
859
|
`;
|
|
859
|
-
const Description$2 = tw(Text)`
|
|
860
|
+
const Description$2 = tw(Text$1)`
|
|
860
861
|
${p => p.$hasTitle ? tws`tu-alert__description` : null}
|
|
861
862
|
`;
|
|
862
863
|
const RightAligned = tw.div`
|
|
@@ -967,9 +968,10 @@ const BaseInput = React.forwardRef((_a, ref) => {
|
|
|
967
968
|
addonBefore,
|
|
968
969
|
addonAfter,
|
|
969
970
|
actions,
|
|
970
|
-
fieldSize = "medium"
|
|
971
|
+
fieldSize = "medium",
|
|
972
|
+
nonInteractive = false
|
|
971
973
|
} = _a,
|
|
972
|
-
rest = __rest(_a, ["className", "isInvalid", "dataTestId", "prefix", "suffix", "addonBefore", "addonAfter", "actions", "fieldSize"]);
|
|
974
|
+
rest = __rest(_a, ["className", "isInvalid", "dataTestId", "prefix", "suffix", "addonBefore", "addonAfter", "actions", "fieldSize", "nonInteractive"]);
|
|
973
975
|
|
|
974
976
|
return jsxs(InputContainer$1, Object.assign({
|
|
975
977
|
"$fieldSize": fieldSize,
|
|
@@ -990,7 +992,9 @@ const BaseInput = React.forwardRef((_a, ref) => {
|
|
|
990
992
|
ref: ref,
|
|
991
993
|
"data-testid": dataTestId,
|
|
992
994
|
className: tws`tu-input__field`
|
|
993
|
-
}, rest
|
|
995
|
+
}, rest, {
|
|
996
|
+
readOnly: rest.readOnly || nonInteractive
|
|
997
|
+
})), suffix !== null && addonBefore !== suffix ? jsx(InputSuffix, Object.assign({
|
|
994
998
|
"data-testid": `${dataTestId}-suffix`
|
|
995
999
|
}, {
|
|
996
1000
|
children: suffix
|
|
@@ -1444,7 +1448,7 @@ const Chart = ({
|
|
|
1444
1448
|
children: showLoading ? jsxs(SpinnerContainer, {
|
|
1445
1449
|
children: [jsx(Spinner, {
|
|
1446
1450
|
centered: true
|
|
1447
|
-
}), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && jsx(Text, Object.assign({
|
|
1451
|
+
}), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && jsx(Text$1, Object.assign({
|
|
1448
1452
|
align: "center",
|
|
1449
1453
|
subtle: true
|
|
1450
1454
|
}, {
|
|
@@ -1492,7 +1496,7 @@ const Label$3 = ({
|
|
|
1492
1496
|
disabled,
|
|
1493
1497
|
isInvalid
|
|
1494
1498
|
}) => {
|
|
1495
|
-
return jsx(Root$
|
|
1499
|
+
return jsx(Root$3, Object.assign({
|
|
1496
1500
|
id: id || "",
|
|
1497
1501
|
htmlFor: htmlFor || "",
|
|
1498
1502
|
className: className,
|
|
@@ -1503,7 +1507,7 @@ const Label$3 = ({
|
|
|
1503
1507
|
children: children
|
|
1504
1508
|
}));
|
|
1505
1509
|
};
|
|
1506
|
-
const Root$
|
|
1510
|
+
const Root$3 = tw.label`
|
|
1507
1511
|
tu-label
|
|
1508
1512
|
${({
|
|
1509
1513
|
$disabled
|
|
@@ -1704,7 +1708,7 @@ const Collapse = ({
|
|
|
1704
1708
|
onClick: handleClick
|
|
1705
1709
|
}, {
|
|
1706
1710
|
children: jsxs(LabelContainer$2, {
|
|
1707
|
-
children: [jsx(Text, Object.assign({
|
|
1711
|
+
children: [jsx(Text$1, Object.assign({
|
|
1708
1712
|
weight: "bold"
|
|
1709
1713
|
}, {
|
|
1710
1714
|
children: label
|
|
@@ -2127,6 +2131,11 @@ const DateInput = forwardRef((_a, ref) => {
|
|
|
2127
2131
|
value: (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.toLocaleDateString()) || "",
|
|
2128
2132
|
onChange: () => {}
|
|
2129
2133
|
}, rest, {
|
|
2134
|
+
dataTestId: "dateInput",
|
|
2135
|
+
onFocus: () => {
|
|
2136
|
+
onShow();
|
|
2137
|
+
},
|
|
2138
|
+
nonInteractive: true,
|
|
2130
2139
|
suffix: jsx(Icon$1, {
|
|
2131
2140
|
dataTestId: "calendar",
|
|
2132
2141
|
name: "CalendarIcon",
|
|
@@ -2138,7 +2147,10 @@ const DateInput = forwardRef((_a, ref) => {
|
|
|
2138
2147
|
actions: selectedDay && jsx(RemoveValueContainer, {
|
|
2139
2148
|
children: jsx(Button, Object.assign({
|
|
2140
2149
|
intent: "tertiary",
|
|
2141
|
-
onClick:
|
|
2150
|
+
onClick: e => {
|
|
2151
|
+
e.preventDefault();
|
|
2152
|
+
setSelectedDay(undefined);
|
|
2153
|
+
}
|
|
2142
2154
|
}, {
|
|
2143
2155
|
children: jsx(Icon$1, {
|
|
2144
2156
|
name: "XIcon",
|
|
@@ -2156,14 +2168,16 @@ const DateInput = forwardRef((_a, ref) => {
|
|
|
2156
2168
|
(_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2157
2169
|
}
|
|
2158
2170
|
}, popoverProps, {
|
|
2159
|
-
children: jsx(PopoverList, {
|
|
2171
|
+
children: jsx(PopoverList, Object.assign({
|
|
2172
|
+
dataTestId: "datePickerPopover"
|
|
2173
|
+
}, {
|
|
2160
2174
|
children: jsx(DayPicker, {
|
|
2161
2175
|
onDaySelect: onChangeHandler,
|
|
2162
2176
|
disabledDays: disabledDays,
|
|
2163
2177
|
selectedDays: selectedDay,
|
|
2164
2178
|
language: navigator.language
|
|
2165
2179
|
})
|
|
2166
|
-
})
|
|
2180
|
+
}))
|
|
2167
2181
|
}))]
|
|
2168
2182
|
});
|
|
2169
2183
|
});
|
|
@@ -2220,7 +2234,7 @@ const PopoverListItem = ({
|
|
|
2220
2234
|
})) : content
|
|
2221
2235
|
}));
|
|
2222
2236
|
};
|
|
2223
|
-
const StyledText$2 = tw(Text)`
|
|
2237
|
+
const StyledText$2 = tw(Text$1)`
|
|
2224
2238
|
tu-popover-list-item__text
|
|
2225
2239
|
${p => p.$selected && tws`tu-popover-list-item__text--selected`}
|
|
2226
2240
|
`;
|
|
@@ -2267,7 +2281,7 @@ const Container$6 = tw.div`
|
|
|
2267
2281
|
tu-popover-title-container
|
|
2268
2282
|
${p => p.$divider && `tu-popover-title-container--divider`}
|
|
2269
2283
|
`;
|
|
2270
|
-
const StyledText$1 = tw(Text)`
|
|
2284
|
+
const StyledText$1 = tw(Text$1)`
|
|
2271
2285
|
tu-popover-title-text
|
|
2272
2286
|
`;
|
|
2273
2287
|
|
|
@@ -2323,7 +2337,7 @@ const Tooltip = ({
|
|
|
2323
2337
|
children: jsx(Content, Object.assign({
|
|
2324
2338
|
"$mode": mode
|
|
2325
2339
|
}, {
|
|
2326
|
-
children: jsx(Text, Object.assign({
|
|
2340
|
+
children: jsx(Text$1, Object.assign({
|
|
2327
2341
|
inverted: mode === "dark",
|
|
2328
2342
|
type: contentTextType
|
|
2329
2343
|
}, {
|
|
@@ -2399,11 +2413,13 @@ const FormGroup = ({
|
|
|
2399
2413
|
className,
|
|
2400
2414
|
dataTestId,
|
|
2401
2415
|
label,
|
|
2402
|
-
children
|
|
2416
|
+
children,
|
|
2417
|
+
disabled = false
|
|
2403
2418
|
}) => {
|
|
2404
2419
|
return jsxs(FormGroupRoot, Object.assign({
|
|
2405
2420
|
className: className,
|
|
2406
|
-
"data-testid": dataTestId
|
|
2421
|
+
"data-testid": dataTestId,
|
|
2422
|
+
"$disabled": disabled
|
|
2407
2423
|
}, {
|
|
2408
2424
|
children: [jsxs(ContainerBefore, {
|
|
2409
2425
|
children: [jsx(Label$3, Object.assign({
|
|
@@ -2432,6 +2448,11 @@ const FormGroup = ({
|
|
|
2432
2448
|
};
|
|
2433
2449
|
const FormGroupRoot = tw.label`
|
|
2434
2450
|
tu-form-group
|
|
2451
|
+
${({
|
|
2452
|
+
$disabled
|
|
2453
|
+
}) => {
|
|
2454
|
+
return $disabled ? "pointer-events-none " : null;
|
|
2455
|
+
}}
|
|
2435
2456
|
`;
|
|
2436
2457
|
const ContainerBefore = tw.div`
|
|
2437
2458
|
tu-form-group__container-before
|
|
@@ -2475,6 +2496,7 @@ const DateField = forwardRef((_a, ref) => {
|
|
|
2475
2496
|
isInvalid: renderAsInvalid,
|
|
2476
2497
|
helpText: errorMessage || helpText,
|
|
2477
2498
|
helpAddon: helpAddon,
|
|
2499
|
+
disabled: rest.disabled,
|
|
2478
2500
|
dataTestId: `${dataTestId}-FormGroup`
|
|
2479
2501
|
}, {
|
|
2480
2502
|
children: jsx(DateInput, Object.assign({
|
|
@@ -2721,7 +2743,7 @@ const LegendItem = ({
|
|
|
2721
2743
|
dataTestId
|
|
2722
2744
|
}) => {
|
|
2723
2745
|
const handleOnClick = onClick && !disabled ? () => onClick() : undefined;
|
|
2724
|
-
return jsxs(Root$
|
|
2746
|
+
return jsxs(Root$2, Object.assign({
|
|
2725
2747
|
"data-testid": dataTestId,
|
|
2726
2748
|
disabled: disabled,
|
|
2727
2749
|
className: className,
|
|
@@ -2737,7 +2759,7 @@ const LegendItem = ({
|
|
|
2737
2759
|
})]
|
|
2738
2760
|
}));
|
|
2739
2761
|
};
|
|
2740
|
-
const Root$
|
|
2762
|
+
const Root$2 = tw.div`
|
|
2741
2763
|
inline-flex
|
|
2742
2764
|
items-center
|
|
2743
2765
|
transition-all
|
|
@@ -3580,7 +3602,7 @@ const Container$1 = tw.label`
|
|
|
3580
3602
|
$isDisabled
|
|
3581
3603
|
}) => $isDisabled ? tws`tu-select--disabled` : null}
|
|
3582
3604
|
`;
|
|
3583
|
-
const InformativeText = tw(Text)`
|
|
3605
|
+
const InformativeText = tw(Text$1)`
|
|
3584
3606
|
tu-informative-text
|
|
3585
3607
|
${p => p.$hasError ? `tu-informative-text--error` : null}
|
|
3586
3608
|
`;
|
|
@@ -4543,11 +4565,11 @@ const TextLengthIndicator = ({
|
|
|
4543
4565
|
length,
|
|
4544
4566
|
maxLength
|
|
4545
4567
|
}) => {
|
|
4546
|
-
return jsxs(Root, {
|
|
4568
|
+
return jsxs(Root$1, {
|
|
4547
4569
|
children: [length, "/", maxLength]
|
|
4548
4570
|
});
|
|
4549
4571
|
};
|
|
4550
|
-
const Root = tw.span`
|
|
4572
|
+
const Root$1 = tw.span`
|
|
4551
4573
|
font-mono
|
|
4552
4574
|
`;
|
|
4553
4575
|
|
|
@@ -4654,7 +4676,8 @@ const TextField = React.forwardRef((_a, ref) => {
|
|
|
4654
4676
|
length: valueLength,
|
|
4655
4677
|
maxLength: maxLength
|
|
4656
4678
|
}),
|
|
4657
|
-
dataTestId: `${dataTestId}-FormGroup
|
|
4679
|
+
dataTestId: `${dataTestId}-FormGroup`,
|
|
4680
|
+
disabled: rest.readOnly
|
|
4658
4681
|
}, {
|
|
4659
4682
|
children: jsx(TextInput, Object.assign({
|
|
4660
4683
|
ref: ref,
|
|
@@ -4839,6 +4862,166 @@ ${({
|
|
|
4839
4862
|
}) => $disabled && tws`tu-toggle__description--disabled`}
|
|
4840
4863
|
`;
|
|
4841
4864
|
|
|
4865
|
+
/**
|
|
4866
|
+
* Helper function to get normalized score in range 0-1 used by the ValueBar
|
|
4867
|
+
*
|
|
4868
|
+
* @param {number} value - value for which score should be returned
|
|
4869
|
+
* @param {number} min - min range value
|
|
4870
|
+
* @param {number} max - max range value
|
|
4871
|
+
* @returns {number} normalized score
|
|
4872
|
+
*/
|
|
4873
|
+
|
|
4874
|
+
const getScore = (value, min, max) => {
|
|
4875
|
+
if (value <= min) {
|
|
4876
|
+
return 0.01; // always render at least some small fragment
|
|
4877
|
+
}
|
|
4878
|
+
|
|
4879
|
+
if (value >= max) {
|
|
4880
|
+
return 1;
|
|
4881
|
+
}
|
|
4882
|
+
|
|
4883
|
+
return (value - min) / (max - min);
|
|
4884
|
+
};
|
|
4885
|
+
/**
|
|
4886
|
+
* Helper function to get default color used by the ValueBar
|
|
4887
|
+
*
|
|
4888
|
+
* @param {number} score - score number for which color should be returned
|
|
4889
|
+
* @returns {string} color value
|
|
4890
|
+
*/
|
|
4891
|
+
|
|
4892
|
+
const getDefaultFillColor = score => {
|
|
4893
|
+
if (score < 0.3) {
|
|
4894
|
+
return getColorValue("--color-red-500");
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4897
|
+
if (score >= 0.6) {
|
|
4898
|
+
return getColorValue("--color-green-600");
|
|
4899
|
+
}
|
|
4900
|
+
|
|
4901
|
+
return getColorValue("--color-amber-300");
|
|
4902
|
+
};
|
|
4903
|
+
/**
|
|
4904
|
+
* Helper function to get normalized color
|
|
4905
|
+
*
|
|
4906
|
+
* @param {number} levelColor - color, ex --color-green-600
|
|
4907
|
+
* @returns {string} normalized color value
|
|
4908
|
+
*/
|
|
4909
|
+
|
|
4910
|
+
const getNormalizedLevelColor = levelColor => {
|
|
4911
|
+
if (levelColor.startsWith("--color")) {
|
|
4912
|
+
return getColorValue(levelColor);
|
|
4913
|
+
}
|
|
4914
|
+
|
|
4915
|
+
return levelColor;
|
|
4916
|
+
};
|
|
4917
|
+
/**
|
|
4918
|
+
* Helper function to get custom color used by the ValueBar
|
|
4919
|
+
*
|
|
4920
|
+
* @param {number} score - score number for which color should be returned
|
|
4921
|
+
* @param {LevelColors} levelColors - custom colors and levels definitions
|
|
4922
|
+
* @returns {string} color value
|
|
4923
|
+
*/
|
|
4924
|
+
|
|
4925
|
+
const getFillColor = (score, levelColors) => {
|
|
4926
|
+
var _a, _b;
|
|
4927
|
+
|
|
4928
|
+
if (levelColors.low && score < (levelColors.low.level || 0)) {
|
|
4929
|
+
return getNormalizedLevelColor(levelColors.low.color);
|
|
4930
|
+
}
|
|
4931
|
+
|
|
4932
|
+
if (levelColors.high && score >= (levelColors.high.level || 0)) {
|
|
4933
|
+
return getNormalizedLevelColor(levelColors.high.color);
|
|
4934
|
+
}
|
|
4935
|
+
|
|
4936
|
+
return getNormalizedLevelColor((_b = (_a = levelColors.medium) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : "--color-amber-300");
|
|
4937
|
+
};
|
|
4938
|
+
/**
|
|
4939
|
+
* Helper function to get color used by the ValueBar
|
|
4940
|
+
*
|
|
4941
|
+
* @param {number} value - value for which color should be returned
|
|
4942
|
+
* @param {number} min - min range value
|
|
4943
|
+
* @param {number} max - max range value
|
|
4944
|
+
* @param {LevelColors} levelColors - level colors used to coloring the bar
|
|
4945
|
+
* @returns {JSX.Element} ValueBar component
|
|
4946
|
+
*/
|
|
4947
|
+
|
|
4948
|
+
const getValueBarColorByValue = (value, min, max, levelColors) => {
|
|
4949
|
+
const score = getScore(value, min, max);
|
|
4950
|
+
return getFillColor(score, levelColors);
|
|
4951
|
+
};
|
|
4952
|
+
|
|
4953
|
+
/**
|
|
4954
|
+
* ValueBar component is used to display value on a colorful bar within provided range.
|
|
4955
|
+
*
|
|
4956
|
+
* @param {ValueBarProps} props - The props for the ValueBar component
|
|
4957
|
+
* @returns {JSX.Element} ValueBar component
|
|
4958
|
+
*/
|
|
4959
|
+
|
|
4960
|
+
const ValueBar = ({
|
|
4961
|
+
value,
|
|
4962
|
+
min = 0,
|
|
4963
|
+
max = 100,
|
|
4964
|
+
unit,
|
|
4965
|
+
size = "small",
|
|
4966
|
+
levelColors,
|
|
4967
|
+
valueColor,
|
|
4968
|
+
showValue,
|
|
4969
|
+
className,
|
|
4970
|
+
dataTestId
|
|
4971
|
+
}) => {
|
|
4972
|
+
const score = getScore(value, min, max);
|
|
4973
|
+
const barFillColor = levelColors ? getFillColor(score, levelColors) : getDefaultFillColor(score);
|
|
4974
|
+
const barWidth = showValue && size === "small" ? 90 : 100;
|
|
4975
|
+
return jsx(Root, Object.assign({
|
|
4976
|
+
className: className,
|
|
4977
|
+
"data-testid": dataTestId,
|
|
4978
|
+
"$size": size
|
|
4979
|
+
}, {
|
|
4980
|
+
children: jsxs("g", {
|
|
4981
|
+
children: [jsx(Background, {
|
|
4982
|
+
width: `${barWidth}%`,
|
|
4983
|
+
rx: "5"
|
|
4984
|
+
}), jsx(Bar, {
|
|
4985
|
+
width: `${score * barWidth}%`,
|
|
4986
|
+
fill: barFillColor,
|
|
4987
|
+
rx: "5"
|
|
4988
|
+
}), showValue && size === "large" && jsxs(Text, Object.assign({
|
|
4989
|
+
"$size": size,
|
|
4990
|
+
x: "12",
|
|
4991
|
+
y: "23",
|
|
4992
|
+
fill: valueColor !== null && valueColor !== void 0 ? valueColor : "white"
|
|
4993
|
+
}, {
|
|
4994
|
+
children: [Number(value.toFixed(1)), unit || ""]
|
|
4995
|
+
})), showValue && size === "small" && jsxs(Text, Object.assign({
|
|
4996
|
+
"$size": size,
|
|
4997
|
+
x: `${barWidth + 2}%`,
|
|
4998
|
+
y: "11",
|
|
4999
|
+
fill: valueColor !== null && valueColor !== void 0 ? valueColor : getColorValue("--color-neutral-400")
|
|
5000
|
+
}, {
|
|
5001
|
+
children: [Number(value.toFixed(1)), unit || ""]
|
|
5002
|
+
}))]
|
|
5003
|
+
})
|
|
5004
|
+
}));
|
|
5005
|
+
};
|
|
5006
|
+
const Root = tw.svg`
|
|
5007
|
+
tu-value-bar
|
|
5008
|
+
${({
|
|
5009
|
+
$size
|
|
5010
|
+
}) => $size === "small" ? tws`tu-value-bar--small` : tws`tu-value-bar--large`}
|
|
5011
|
+
`;
|
|
5012
|
+
const Text = tw.text`
|
|
5013
|
+
tu-value-bar__text
|
|
5014
|
+
${({
|
|
5015
|
+
$size
|
|
5016
|
+
}) => $size === "small" ? tws`tu-value-bar__text--small` : tws`tu-value-bar__text--large`}
|
|
5017
|
+
`;
|
|
5018
|
+
const Background = tw.rect`
|
|
5019
|
+
tu-value-bar__background
|
|
5020
|
+
`;
|
|
5021
|
+
const Bar = tw.rect`
|
|
5022
|
+
tu-value-bar__bar
|
|
5023
|
+
`;
|
|
5024
|
+
|
|
4842
5025
|
/**
|
|
4843
5026
|
* The useDebounce hook works like useState, but adds a delay where previous values will be ignored.
|
|
4844
5027
|
*
|
|
@@ -5202,4 +5385,4 @@ const Layout = tw.div`
|
|
|
5202
5385
|
tu-layout-TwoColumnLayout
|
|
5203
5386
|
`;
|
|
5204
5387
|
|
|
5205
|
-
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, 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 };
|
|
5388
|
+
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 };
|