@trackunit/react-components 0.1.383 → 0.1.385
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.cjs.js +6 -20
- package/index.esm.js +7 -21
- package/package.json +1 -1
- package/src/common/AriaProps.d.ts +5 -0
- package/src/common/CommonProps.d.ts +4 -2
- package/src/common/Density.d.ts +1 -0
- package/src/common/Size.d.ts +1 -0
- package/src/common/index.d.ts +3 -0
- package/src/components/Card/CardBody.d.ts +1 -1
- package/src/components/Card/CardFooter.d.ts +1 -1
- package/src/components/Card/CardHeader.d.ts +1 -1
- package/src/components/Icon/Icon.d.ts +10 -15
- package/src/components/Menu/MenuItem/MenuItem.d.ts +1 -2
- package/src/components/Spinner/Spinner.d.ts +1 -1
- package/src/components/Tag/Tag.d.ts +1 -1
- package/src/components/Text/Text.d.ts +1 -1
- package/src/components/ValueBar/ValueBar.d.ts +1 -2
- package/src/components/Widget/WidgetBody.d.ts +1 -1
- package/src/components/buttons/shared/ButtonProps.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -11,9 +11,9 @@ var IconSpriteMini = require('@trackunit/ui-icons/icons-sprite-mini.svg');
|
|
|
11
11
|
var IconSpriteOutline = require('@trackunit/ui-icons/icons-sprite-outline.svg');
|
|
12
12
|
var IconSpriteSolid = require('@trackunit/ui-icons/icons-sprite-solid.svg');
|
|
13
13
|
var stringTs = require('string-ts');
|
|
14
|
+
var uuid = require('uuid');
|
|
14
15
|
var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
|
|
15
16
|
var reactSlot = require('@radix-ui/react-slot');
|
|
16
|
-
var uuid = require('uuid');
|
|
17
17
|
var isEqual = require('lodash/isEqual');
|
|
18
18
|
var reactUse = require('react-use');
|
|
19
19
|
var reactRouter = require('@tanstack/react-router');
|
|
@@ -170,22 +170,7 @@ const isSafari = () => {
|
|
|
170
170
|
const ua = navigator.userAgent.toLowerCase();
|
|
171
171
|
return ua.includes("safari") && !ua.includes("chrome");
|
|
172
172
|
};
|
|
173
|
-
|
|
174
|
-
* Converts camelCase text to humanized text.
|
|
175
|
-
*
|
|
176
|
-
* @param text text to convert
|
|
177
|
-
* @returns {string} humanized text with spaces between words
|
|
178
|
-
* @example camelCaseToHumanizedText("QuestionMarkCircle") => "Question Mark Circle"
|
|
179
|
-
*/
|
|
180
|
-
const camelCaseToHumanizedText = (text) => {
|
|
181
|
-
// Replace capital letters (except at the start) with space + letter
|
|
182
|
-
const humanizedText = text ? text.replace(/([A-Z])/g, " $1").trim() : "";
|
|
183
|
-
if (humanizedText.length === 0) {
|
|
184
|
-
return "";
|
|
185
|
-
}
|
|
186
|
-
// Optionally, capitalize the first letter of the result
|
|
187
|
-
return humanizedText.charAt(0).toUpperCase() + humanizedText.slice(1);
|
|
188
|
-
};
|
|
173
|
+
const ICON_CONTAINER_ID = uuid.v4();
|
|
189
174
|
/**
|
|
190
175
|
* - The Icon component is used to display an Icon.
|
|
191
176
|
* - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
|
|
@@ -194,7 +179,7 @@ const camelCaseToHumanizedText = (text) => {
|
|
|
194
179
|
* @param {IconProps} props - The props for the Icon component
|
|
195
180
|
* @returns {JSX.Element} Icon component
|
|
196
181
|
*/
|
|
197
|
-
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style,
|
|
182
|
+
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }) => {
|
|
198
183
|
const useTagRef = React.useRef(null);
|
|
199
184
|
const correctIconType = React.useMemo(() => {
|
|
200
185
|
if (size === "small" || size === "medium") {
|
|
@@ -216,7 +201,7 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, typ
|
|
|
216
201
|
useTagRef.current.setAttribute("href", href[correctIconType]);
|
|
217
202
|
}
|
|
218
203
|
}, [correctIconType, href]);
|
|
219
|
-
return (jsxRuntime.jsx("span", { className: cvaIcon({ color, size, className }), "data-testid": dataTestId, onClick: onClick, ref: forwardedRef, children: jsxRuntime.jsx("svg", { "aria-labelledby":
|
|
204
|
+
return (jsxRuntime.jsx("span", { "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel ? ariaLabel : stringTs.titleCase(iconName), "aria-labelledby": ariaLabelledBy, className: cvaIcon({ color, size, className }), "data-testid": dataTestId, id: ICON_CONTAINER_ID, onClick: onClick, ref: forwardedRef, children: jsxRuntime.jsx("svg", { "aria-labelledby": ICON_CONTAINER_ID, "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, role: "img", style: style, viewBox: correctIconType === "mini" ? "0 0 20 20" : "0 0 24 24", children: jsxRuntime.jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
|
|
220
205
|
};
|
|
221
206
|
|
|
222
207
|
const cvaTag = cssClassVarianceUtilities.cvaMerge([
|
|
@@ -1756,6 +1741,7 @@ const cvaChevronIcon = cssClassVarianceUtilities.cvaMerge([
|
|
|
1756
1741
|
},
|
|
1757
1742
|
});
|
|
1758
1743
|
|
|
1744
|
+
const LABEL_ID = uuid.v4();
|
|
1759
1745
|
/**
|
|
1760
1746
|
* The Collapse component is a container for additional information that adds context to various flows. It is used for displaying non-essential information that can be hidden away.
|
|
1761
1747
|
*
|
|
@@ -1781,7 +1767,7 @@ const Collapse = ({ id, initialExpanded = false, onToggle, label, children, clas
|
|
|
1781
1767
|
}
|
|
1782
1768
|
setExpanded(!expanded);
|
|
1783
1769
|
}, [expanded, onToggle]);
|
|
1784
|
-
return (jsxRuntime.jsxs("div", { className: cvaCollapse({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { "aria-controls": id, "aria-expanded": expanded, className: cvaCollapseHeader({ expanded, className: headerClassName }), onClick: handleClick, role: "button", children: [jsxRuntime.jsxs("div", { className: cvaCollapseLabelContainer(), children: [jsxRuntime.jsx(Icon, { className: cvaChevronIcon({ expanded }), name: "ChevronRight", size: "small" }), jsxRuntime.jsx(Text, { type: "span", weight: "bold", children: label })] }), headerAddon ? headerAddon : null] }), jsxRuntime.jsx(Collapsible, { expanded: expanded, id: id, children: children })] }));
|
|
1770
|
+
return (jsxRuntime.jsxs("div", { className: cvaCollapse({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { "aria-controls": id, "aria-expanded": expanded, className: cvaCollapseHeader({ expanded, className: headerClassName }), onClick: handleClick, role: "button", children: [jsxRuntime.jsxs("div", { className: cvaCollapseLabelContainer(), children: [jsxRuntime.jsx(Icon, { ariaLabelledBy: LABEL_ID, className: cvaChevronIcon({ expanded }), name: "ChevronRight", size: "small" }), jsxRuntime.jsx(Text, { id: LABEL_ID, type: "span", weight: "bold", children: label })] }), headerAddon ? headerAddon : null] }), jsxRuntime.jsx(Collapsible, { expanded: expanded, id: id, children: children })] }));
|
|
1785
1771
|
};
|
|
1786
1772
|
const Collapsible = ({ children, expanded, id }) => {
|
|
1787
1773
|
const [ref, { height }] = reactUse.useMeasure();
|
package/index.esm.js
CHANGED
|
@@ -7,10 +7,10 @@ import { iconNames } from '@trackunit/ui-icons';
|
|
|
7
7
|
import IconSpriteMini from '@trackunit/ui-icons/icons-sprite-mini.svg';
|
|
8
8
|
import IconSpriteOutline from '@trackunit/ui-icons/icons-sprite-outline.svg';
|
|
9
9
|
import IconSpriteSolid from '@trackunit/ui-icons/icons-sprite-solid.svg';
|
|
10
|
-
import { snakeCase } from 'string-ts';
|
|
10
|
+
import { snakeCase, titleCase } from 'string-ts';
|
|
11
|
+
import { v4 } from 'uuid';
|
|
11
12
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
12
13
|
import { Slottable, Slot } from '@radix-ui/react-slot';
|
|
13
|
-
import { v4 } from 'uuid';
|
|
14
14
|
import isEqual from 'lodash/isEqual';
|
|
15
15
|
import { usePrevious, useMeasure, useCopyToClipboard } from 'react-use';
|
|
16
16
|
import { Link, useBlocker } from '@tanstack/react-router';
|
|
@@ -139,22 +139,7 @@ const isSafari = () => {
|
|
|
139
139
|
const ua = navigator.userAgent.toLowerCase();
|
|
140
140
|
return ua.includes("safari") && !ua.includes("chrome");
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
* Converts camelCase text to humanized text.
|
|
144
|
-
*
|
|
145
|
-
* @param text text to convert
|
|
146
|
-
* @returns {string} humanized text with spaces between words
|
|
147
|
-
* @example camelCaseToHumanizedText("QuestionMarkCircle") => "Question Mark Circle"
|
|
148
|
-
*/
|
|
149
|
-
const camelCaseToHumanizedText = (text) => {
|
|
150
|
-
// Replace capital letters (except at the start) with space + letter
|
|
151
|
-
const humanizedText = text ? text.replace(/([A-Z])/g, " $1").trim() : "";
|
|
152
|
-
if (humanizedText.length === 0) {
|
|
153
|
-
return "";
|
|
154
|
-
}
|
|
155
|
-
// Optionally, capitalize the first letter of the result
|
|
156
|
-
return humanizedText.charAt(0).toUpperCase() + humanizedText.slice(1);
|
|
157
|
-
};
|
|
142
|
+
const ICON_CONTAINER_ID = v4();
|
|
158
143
|
/**
|
|
159
144
|
* - The Icon component is used to display an Icon.
|
|
160
145
|
* - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
|
|
@@ -163,7 +148,7 @@ const camelCaseToHumanizedText = (text) => {
|
|
|
163
148
|
* @param {IconProps} props - The props for the Icon component
|
|
164
149
|
* @returns {JSX.Element} Icon component
|
|
165
150
|
*/
|
|
166
|
-
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style,
|
|
151
|
+
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }) => {
|
|
167
152
|
const useTagRef = useRef(null);
|
|
168
153
|
const correctIconType = useMemo(() => {
|
|
169
154
|
if (size === "small" || size === "medium") {
|
|
@@ -185,7 +170,7 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, typ
|
|
|
185
170
|
useTagRef.current.setAttribute("href", href[correctIconType]);
|
|
186
171
|
}
|
|
187
172
|
}, [correctIconType, href]);
|
|
188
|
-
return (jsx("span", { className: cvaIcon({ color, size, className }), "data-testid": dataTestId, onClick: onClick, ref: forwardedRef, children: jsx("svg", { "aria-labelledby":
|
|
173
|
+
return (jsx("span", { "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel ? ariaLabel : titleCase(iconName), "aria-labelledby": ariaLabelledBy, className: cvaIcon({ color, size, className }), "data-testid": dataTestId, id: ICON_CONTAINER_ID, onClick: onClick, ref: forwardedRef, children: jsx("svg", { "aria-labelledby": ICON_CONTAINER_ID, "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, role: "img", style: style, viewBox: correctIconType === "mini" ? "0 0 20 20" : "0 0 24 24", children: jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
|
|
189
174
|
};
|
|
190
175
|
|
|
191
176
|
const cvaTag = cvaMerge([
|
|
@@ -1725,6 +1710,7 @@ const cvaChevronIcon = cvaMerge([
|
|
|
1725
1710
|
},
|
|
1726
1711
|
});
|
|
1727
1712
|
|
|
1713
|
+
const LABEL_ID = v4();
|
|
1728
1714
|
/**
|
|
1729
1715
|
* The Collapse component is a container for additional information that adds context to various flows. It is used for displaying non-essential information that can be hidden away.
|
|
1730
1716
|
*
|
|
@@ -1750,7 +1736,7 @@ const Collapse = ({ id, initialExpanded = false, onToggle, label, children, clas
|
|
|
1750
1736
|
}
|
|
1751
1737
|
setExpanded(!expanded);
|
|
1752
1738
|
}, [expanded, onToggle]);
|
|
1753
|
-
return (jsxs("div", { className: cvaCollapse({ className }), "data-testid": dataTestId, children: [jsxs("div", { "aria-controls": id, "aria-expanded": expanded, className: cvaCollapseHeader({ expanded, className: headerClassName }), onClick: handleClick, role: "button", children: [jsxs("div", { className: cvaCollapseLabelContainer(), children: [jsx(Icon, { className: cvaChevronIcon({ expanded }), name: "ChevronRight", size: "small" }), jsx(Text, { type: "span", weight: "bold", children: label })] }), headerAddon ? headerAddon : null] }), jsx(Collapsible, { expanded: expanded, id: id, children: children })] }));
|
|
1739
|
+
return (jsxs("div", { className: cvaCollapse({ className }), "data-testid": dataTestId, children: [jsxs("div", { "aria-controls": id, "aria-expanded": expanded, className: cvaCollapseHeader({ expanded, className: headerClassName }), onClick: handleClick, role: "button", children: [jsxs("div", { className: cvaCollapseLabelContainer(), children: [jsx(Icon, { ariaLabelledBy: LABEL_ID, className: cvaChevronIcon({ expanded }), name: "ChevronRight", size: "small" }), jsx(Text, { id: LABEL_ID, type: "span", weight: "bold", children: label })] }), headerAddon ? headerAddon : null] }), jsx(Collapsible, { expanded: expanded, id: id, children: children })] }));
|
|
1754
1740
|
};
|
|
1755
1741
|
const Collapsible = ({ children, expanded, id }) => {
|
|
1756
1742
|
const [ref, { height }] = useMeasure();
|
package/package.json
CHANGED
|
@@ -7,6 +7,8 @@ export interface CommonProps {
|
|
|
7
7
|
* A id that can be used in tests to get the component
|
|
8
8
|
*/
|
|
9
9
|
dataTestId?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Ihe id of the html element
|
|
12
|
+
*/
|
|
13
|
+
id?: string;
|
|
10
14
|
}
|
|
11
|
-
export type Density = "none" | "compact" | "comfortable" | "spacious" | "auto";
|
|
12
|
-
export type Size = "small" | "medium" | "large";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Density = "none" | "compact" | "comfortable" | "spacious" | "auto";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Size = "small" | "medium" | "large";
|
package/src/common/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { CommonProps, Density } from "../../common
|
|
2
|
+
import { CommonProps, Density } from "../../common";
|
|
3
3
|
import { HeadingVariant } from "../Heading/Heading";
|
|
4
4
|
export interface CardHeaderProps extends CommonProps {
|
|
5
5
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ActivityColors, CriticalityColors, GeneralColors, IntentColors, RentalStatusColors, SitesColors, UtilizationColors } from "@trackunit/ui-design-tokens";
|
|
2
2
|
import { IconName } from "@trackunit/ui-icons";
|
|
3
3
|
import { CSSProperties } from "react";
|
|
4
|
-
import { CommonProps, Size } from "../../common
|
|
4
|
+
import { CommonProps, Size } from "../../common";
|
|
5
|
+
import { AriaProps } from "../../common/AriaProps";
|
|
5
6
|
export type IconColors = IntentColors | GeneralColors | CriticalityColors | ActivityColors | UtilizationColors | SitesColors | RentalStatusColors;
|
|
6
7
|
export declare const iconPalette: {
|
|
7
8
|
ON_RENT: {
|
|
@@ -205,7 +206,11 @@ export declare const iconPalette: {
|
|
|
205
206
|
readonly 50: "239 246 255";
|
|
206
207
|
readonly 100: "219 234 254";
|
|
207
208
|
readonly 200: "191 219 254";
|
|
208
|
-
readonly 300: "147 197 253";
|
|
209
|
+
readonly 300: "147 197 253"; /**
|
|
210
|
+
* Select if the icon should be rendered as solid or outline.
|
|
211
|
+
* Default value depends on the Size prop, mini == solid, medium == solid, large == outline.
|
|
212
|
+
* Trackunit icons might not support both outline and Solid.
|
|
213
|
+
*/
|
|
209
214
|
readonly 400: "96 165 250";
|
|
210
215
|
readonly 500: "59 130 246";
|
|
211
216
|
readonly 600: "37 99 235";
|
|
@@ -217,11 +222,7 @@ export declare const iconPalette: {
|
|
|
217
222
|
readonly 50: "240 253 244";
|
|
218
223
|
readonly 100: "220 252 231";
|
|
219
224
|
readonly 200: "187 247 208";
|
|
220
|
-
readonly 300: "134 239 172";
|
|
221
|
-
* Custom styles object used to override existing styles or add some extra styling
|
|
222
|
-
*
|
|
223
|
-
* @memberof IconProps
|
|
224
|
-
*/
|
|
225
|
+
readonly 300: "134 239 172";
|
|
225
226
|
readonly 400: "74 222 128";
|
|
226
227
|
readonly 500: "34 197 94";
|
|
227
228
|
readonly 600: "22 163 74";
|
|
@@ -272,7 +273,7 @@ type IconPropsLarge = {
|
|
|
272
273
|
type?: "solid" | "outline";
|
|
273
274
|
};
|
|
274
275
|
type DiscriminatedIconProps = IconPropsFont | IconPropsSmall | IconPropsMedium | IconPropsLarge;
|
|
275
|
-
export type IconProps = DiscriminatedIconProps & CommonProps & {
|
|
276
|
+
export type IconProps = DiscriminatedIconProps & CommonProps & AriaProps & {
|
|
276
277
|
/**
|
|
277
278
|
* The name of the icon to be rendered.
|
|
278
279
|
* HeroIconName and TrackunitIconName are supported.
|
|
@@ -310,12 +311,6 @@ export type IconProps = DiscriminatedIconProps & CommonProps & {
|
|
|
310
311
|
* @memberof IconProps
|
|
311
312
|
*/
|
|
312
313
|
style?: CSSProperties;
|
|
313
|
-
/**
|
|
314
|
-
* The title (text) to put in the aria-labelledby.
|
|
315
|
-
* Default title is the name of the icon.
|
|
316
|
-
* If a custom title is needed, set it using this prop.
|
|
317
|
-
*/
|
|
318
|
-
title?: string;
|
|
319
314
|
};
|
|
320
315
|
/**
|
|
321
316
|
* - The Icon component is used to display an Icon.
|
|
@@ -325,5 +320,5 @@ export type IconProps = DiscriminatedIconProps & CommonProps & {
|
|
|
325
320
|
* @param {IconProps} props - The props for the Icon component
|
|
326
321
|
* @returns {JSX.Element} Icon component
|
|
327
322
|
*/
|
|
328
|
-
export declare const Icon: ({ name, size, className, dataTestId, color, onClick, type, style,
|
|
323
|
+
export declare const Icon: ({ name, size, className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }: IconProps) => JSX.Element;
|
|
329
324
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Size } from "@trackunit/shared-utils";
|
|
2
1
|
import * as React from "react";
|
|
3
|
-
import { CommonProps } from "../../../common";
|
|
2
|
+
import { CommonProps, Size } from "../../../common";
|
|
4
3
|
type MenuItemSize = Extract<Size, "small" | "medium">;
|
|
5
4
|
export interface MenuItemProps extends CommonProps {
|
|
6
5
|
id?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CommonProps, Size } from "../../common
|
|
2
|
+
import { CommonProps, Size } from "../../common";
|
|
3
3
|
type Centering = "horizontally" | "vertically" | "centered";
|
|
4
4
|
export interface SpinnerProps extends CommonProps {
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActivityColors, CriticalityColors, CustomerDataSourceColors, CustomerTypeColors, GeneralColors, IntentColors } from "@trackunit/ui-design-tokens";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { CommonProps, Size } from "../../common
|
|
3
|
+
import { CommonProps, Size } from "../../common";
|
|
4
4
|
export type TagSize = Extract<Size, "small" | "medium">;
|
|
5
5
|
export type TagColors = IntentColors | GeneralColors | CriticalityColors | ActivityColors | CustomerTypeColors | CustomerDataSourceColors;
|
|
6
6
|
export interface TagProps extends CommonProps {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { CommonProps, Size } from "../../common
|
|
2
|
+
import { CommonProps, Size } from "../../common";
|
|
3
3
|
export type TextType = "p" | "span" | "div";
|
|
4
4
|
export type TextAlign = "left" | "center" | "right";
|
|
5
5
|
export type TextWeight = "normal" | "thick" | "bold";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Size } from "
|
|
3
|
-
import { CommonProps } from "../../common";
|
|
2
|
+
import { CommonProps, Size } from "../../common";
|
|
4
3
|
import { LevelColors } from "./ValueBarTypes";
|
|
5
4
|
type ValueBarSize = Extract<Size, "small" | "large">;
|
|
6
5
|
export interface ValueBarProps extends CommonProps {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { GeneralColors } from "@trackunit/ui-design-tokens";
|
|
3
|
-
import { CommonProps, Size } from "../../../common
|
|
3
|
+
import { CommonProps, Size } from "../../../common";
|
|
4
4
|
export type ButtonVariant = Extract<GeneralColors, "primary" | "secondary"> | "primary-danger" | "secondary-danger" | "ghost" | "ghost-neutral";
|
|
5
5
|
export type ButtonType = "button" | "submit";
|
|
6
6
|
export interface ButtonCommonProps extends CommonProps {
|