@trackunit/react-components 0.1.44 → 0.1.45
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 +7 -20
- package/package.json +1 -1
- package/src/components/Badge/Badge.d.ts +2 -1
package/index.js
CHANGED
|
@@ -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
|
};
|
|
@@ -1142,8 +1129,8 @@ const HelpAddon = tw.span `
|
|
|
1142
1129
|
*/
|
|
1143
1130
|
const DateField = forwardRef((_a, ref) => {
|
|
1144
1131
|
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 })) })));
|
|
1132
|
+
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1133
|
+
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
1134
|
});
|
|
1148
1135
|
|
|
1149
1136
|
const localeLookup = {
|
|
@@ -1595,8 +1582,8 @@ const NumberInput = forwardRef((props, ref) => (jsx(BaseInput, Object.assign({ r
|
|
|
1595
1582
|
*/
|
|
1596
1583
|
const NumberField = forwardRef((_a, ref) => {
|
|
1597
1584
|
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 })) })));
|
|
1585
|
+
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
1586
|
+
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
1587
|
});
|
|
1601
1588
|
|
|
1602
1589
|
/**
|
|
@@ -2644,14 +2631,14 @@ const TextAreaField = React.forwardRef((_a, ref) => {
|
|
|
2644
2631
|
const TextField = React.forwardRef((_a, ref) => {
|
|
2645
2632
|
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
2633
|
const [valueLength, setValueLength] = React.useState(value ? `${value}`.length : 0);
|
|
2647
|
-
const renderAsInvalid = isInvalid
|
|
2634
|
+
const renderAsInvalid = isInvalid === undefined ? Boolean(errorMessage) : isInvalid;
|
|
2648
2635
|
const handleChange = React.useCallback((event) => {
|
|
2649
2636
|
setValueLength(event.target.value.length);
|
|
2650
2637
|
if (onChange) {
|
|
2651
2638
|
onChange(event);
|
|
2652
2639
|
}
|
|
2653
2640
|
}, [onChange]);
|
|
2654
|
-
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon ||
|
|
2641
|
+
return (jsx(FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: (renderAsInvalid && errorMessage) || helpText, helpAddon: helpAddon ||
|
|
2655
2642
|
(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
2643
|
});
|
|
2657
2644
|
|
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.
|