@trackunit/react-components 0.1.44 → 0.1.46
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.js +9 -23
- package/package.json +1 -1
- package/src/components/Badge/Badge.d.ts +2 -1
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import EChart from 'echarts-for-react';
|
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import { useMeasure, useCopyToClipboard } from 'react-use';
|
|
9
9
|
import { format, formatDistance } from 'date-fns';
|
|
10
|
-
import { useFloating, offset, flip,
|
|
10
|
+
import { useFloating, offset, flip, size, shift, autoUpdate, useInteractions, useClick, useHover, useRole, useDismiss, FloatingPortal, FloatingFocusManager } from '@floating-ui/react';
|
|
11
11
|
import { Link, UNSAFE_NavigationContext } from 'react-router-dom';
|
|
12
12
|
import { DayPicker as DayPicker$1 } from 'react-day-picker';
|
|
13
13
|
import { enGB, enUS, da, de, cs, nl, fr, fi, hu, it, nb, pl, pt, ru, ro, es, sv, ja, th } from 'date-fns/locale';
|
|
@@ -488,7 +488,7 @@ const IconContainer$1 = tw.div `
|
|
|
488
488
|
* @returns {JSX.Element} Badge component
|
|
489
489
|
*/
|
|
490
490
|
const Badge = (_a) => {
|
|
491
|
-
var { color = "
|
|
491
|
+
var { color = "primary", subtle = false, className, count, max, hideZero = false, dataTestId } = _a; __rest(_a, ["color", "subtle", "className", "count", "max", "hideZero", "dataTestId"]);
|
|
492
492
|
if (hideZero && count === 0) {
|
|
493
493
|
return null;
|
|
494
494
|
}
|
|
@@ -498,20 +498,7 @@ const Badge = (_a) => {
|
|
|
498
498
|
const getBadgeModifierClass = () => ({ $color, $subtle }) => {
|
|
499
499
|
const colorClasses = {
|
|
500
500
|
primary: $subtle ? tws `tu-badge--primary-subtle` : tws `tu-badge--primary`,
|
|
501
|
-
secondary: $subtle ? tws `tu-badge--secondary-subtle` : tws `tu-badge--secondary`,
|
|
502
|
-
accent: $subtle ? tws `tu-badge--accent-subtle` : tws `tu-badge--accent`,
|
|
503
|
-
success: $subtle ? tws `tu-badge--success-subtle` : tws `tu-badge--success`,
|
|
504
501
|
danger: $subtle ? tws `tu-badge--danger-subtle` : tws `tu-badge--danger`,
|
|
505
|
-
warning: $subtle ? tws `tu-badge--warning-subtle` : tws `tu-badge--warning`,
|
|
506
|
-
info: $subtle ? tws `tu-badge--info-subtle` : tws `tu-badge--info`,
|
|
507
|
-
neutral: $subtle ? tws `tu-badge--neutral-subtle` : tws `tu-badge--neutral`,
|
|
508
|
-
good: $subtle ? tws `tu-badge--good-subtle` : tws `tu-badge--good`,
|
|
509
|
-
low: $subtle ? tws `tu-badge--low-subtle` : tws `tu-badge--low`,
|
|
510
|
-
critical: $subtle ? tws `tu-badge--critical-subtle` : tws `tu-badge--critical`,
|
|
511
|
-
working: $subtle ? tws `tu-badge--working-subtle` : tws `tu-badge--working`,
|
|
512
|
-
idle: $subtle ? tws `tu-badge--idle-subtle` : tws `tu-badge--idle`,
|
|
513
|
-
stopped: $subtle ? tws `tu-badge--stopped-subtle` : tws `tu-badge--stopped`,
|
|
514
|
-
unknown: $subtle ? tws `tu-badge--unknown-subtle` : tws `tu-badge--unknown`,
|
|
515
502
|
};
|
|
516
503
|
return colorClasses[$color];
|
|
517
504
|
};
|
|
@@ -958,9 +945,7 @@ const Popover = ({ children, render, placement, activation = { click: true, hove
|
|
|
958
945
|
middleware: [
|
|
959
946
|
offset(8),
|
|
960
947
|
flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
|
|
961
|
-
shift(),
|
|
962
948
|
size({
|
|
963
|
-
padding: 8,
|
|
964
949
|
apply({ availableWidth, availableHeight, elements }) {
|
|
965
950
|
Object.assign(elements.floating.style, {
|
|
966
951
|
maxWidth: `${availableWidth}px`,
|
|
@@ -968,6 +953,7 @@ const Popover = ({ children, render, placement, activation = { click: true, hove
|
|
|
968
953
|
});
|
|
969
954
|
},
|
|
970
955
|
}),
|
|
956
|
+
shift(),
|
|
971
957
|
],
|
|
972
958
|
placement,
|
|
973
959
|
whileElementsMounted: autoUpdate,
|
|
@@ -1142,8 +1128,8 @@ const HelpAddon = tw.span `
|
|
|
1142
1128
|
*/
|
|
1143
1129
|
const DateField = forwardRef((_a, ref) => {
|
|
1144
1130
|
var { label, tip, helpText, errorMessage, helpAddon, isInvalid, className, defaultValue, dataTestId } = _a, rest = __rest(_a, ["label", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "className", "defaultValue", "dataTestId"]);
|
|
1145
|
-
const renderAsInvalid = isInvalid
|
|
1146
|
-
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(DateInput, Object.assign({ ref: ref, defaultValue: defaultValue, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1131
|
+
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1132
|
+
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, disabled: rest.disabled, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(DateInput, Object.assign({ ref: ref, defaultValue: defaultValue, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1147
1133
|
});
|
|
1148
1134
|
|
|
1149
1135
|
const localeLookup = {
|
|
@@ -1595,8 +1581,8 @@ const NumberInput = forwardRef((props, ref) => (jsx(BaseInput, Object.assign({ r
|
|
|
1595
1581
|
*/
|
|
1596
1582
|
const NumberField = forwardRef((_a, ref) => {
|
|
1597
1583
|
var { label, tip, helpText, errorMessage, helpAddon, isInvalid, maxLength, className, value, dataTestId } = _a, rest = __rest(_a, ["label", "tip", "helpText", "errorMessage", "helpAddon", "isInvalid", "maxLength", "className", "value", "dataTestId"]);
|
|
1598
|
-
const renderAsInvalid = isInvalid
|
|
1599
|
-
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(NumberInput, Object.assign({ ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1584
|
+
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1585
|
+
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsx(NumberInput, Object.assign({ ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, dataTestId: dataTestId })) })));
|
|
1600
1586
|
});
|
|
1601
1587
|
|
|
1602
1588
|
/**
|
|
@@ -2644,14 +2630,14 @@ const TextAreaField = React.forwardRef((_a, ref) => {
|
|
|
2644
2630
|
const TextField = React.forwardRef((_a, ref) => {
|
|
2645
2631
|
var { label, tip, helpText, helpAddon, errorMessage, isInvalid, maxLength, onChange, className, value, dataTestId } = _a, rest = __rest(_a, ["label", "tip", "helpText", "helpAddon", "errorMessage", "isInvalid", "maxLength", "onChange", "className", "value", "dataTestId"]);
|
|
2646
2632
|
const [valueLength, setValueLength] = React.useState(value ? `${value}`.length : 0);
|
|
2647
|
-
const renderAsInvalid = isInvalid
|
|
2633
|
+
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2648
2634
|
const handleChange = React.useCallback((event) => {
|
|
2649
2635
|
setValueLength(event.target.value.length);
|
|
2650
2636
|
if (onChange) {
|
|
2651
2637
|
onChange(event);
|
|
2652
2638
|
}
|
|
2653
2639
|
}, [onChange]);
|
|
2654
|
-
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon ||
|
|
2640
|
+
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon ||
|
|
2655
2641
|
(maxLength !== null && maxLength !== undefined && (jsx(TextLengthIndicator, { length: valueLength, maxLength: maxLength }))), dataTestId: dataTestId && `${dataTestId}-FormGroup`, disabled: rest.readOnly }, { children: jsx(TextInput, Object.assign({ ref: ref, maxLength: maxLength, value: value, isInvalid: renderAsInvalid }, rest, { className: className, onChange: handleChange, dataTestId: dataTestId })) })));
|
|
2656
2642
|
});
|
|
2657
2643
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ThemeColors } from "@trackunit/ui-design-tokens";
|
|
3
3
|
import { CommonProps } from "../../common/CommonProps";
|
|
4
|
+
type BadgeColors = Extract<ThemeColors, "primary" | "danger">;
|
|
4
5
|
interface BaseBadgeProps extends CommonProps {
|
|
5
6
|
/**
|
|
6
7
|
* The color of the badge.
|
|
7
8
|
*/
|
|
8
|
-
color?:
|
|
9
|
+
color?: BadgeColors;
|
|
9
10
|
/**
|
|
10
11
|
* Specifies whether the badge is subtle or not.
|
|
11
12
|
* Subtle badges have a light background color wither a darker text color.
|