@trackunit/react-components 0.1.384 → 0.1.386

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 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,6 @@ 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
- };
189
173
  /**
190
174
  * - The Icon component is used to display an Icon.
191
175
  * - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
@@ -194,8 +178,9 @@ const camelCaseToHumanizedText = (text) => {
194
178
  * @param {IconProps} props - The props for the Icon component
195
179
  * @returns {JSX.Element} Icon component
196
180
  */
197
- const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, title, forwardedRef, }) => {
181
+ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }) => {
198
182
  const useTagRef = React.useRef(null);
183
+ const ICON_CONTAINER_ID = uuid.v4();
199
184
  const correctIconType = React.useMemo(() => {
200
185
  if (size === "small" || size === "medium") {
201
186
  return "mini";
@@ -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": title ? title : camelCaseToHumanizedText(iconName), "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 }) }) }));
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([
@@ -1774,6 +1759,7 @@ const cvaChevronIcon = cssClassVarianceUtilities.cvaMerge([
1774
1759
  * @returns {JSX.Element} Collapse component
1775
1760
  */
1776
1761
  const Collapse = ({ id, initialExpanded = false, onToggle, label, children, className, headerClassName, headerAddon, dataTestId, }) => {
1762
+ const LABEL_ID = uuid.v4();
1777
1763
  const [expanded, setExpanded] = React__namespace.useState(initialExpanded);
1778
1764
  const handleClick = React__namespace.useCallback((e) => {
1779
1765
  if (onToggle) {
@@ -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,6 @@ 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
- };
158
142
  /**
159
143
  * - The Icon component is used to display an Icon.
160
144
  * - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
@@ -163,8 +147,9 @@ const camelCaseToHumanizedText = (text) => {
163
147
  * @param {IconProps} props - The props for the Icon component
164
148
  * @returns {JSX.Element} Icon component
165
149
  */
166
- const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, title, forwardedRef, }) => {
150
+ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }) => {
167
151
  const useTagRef = useRef(null);
152
+ const ICON_CONTAINER_ID = v4();
168
153
  const correctIconType = useMemo(() => {
169
154
  if (size === "small" || size === "medium") {
170
155
  return "mini";
@@ -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": title ? title : camelCaseToHumanizedText(iconName), "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 }) }) }));
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([
@@ -1743,6 +1728,7 @@ const cvaChevronIcon = cvaMerge([
1743
1728
  * @returns {JSX.Element} Collapse component
1744
1729
  */
1745
1730
  const Collapse = ({ id, initialExpanded = false, onToggle, label, children, className, headerClassName, headerAddon, dataTestId, }) => {
1731
+ const LABEL_ID = v4();
1746
1732
  const [expanded, setExpanded] = React.useState(initialExpanded);
1747
1733
  const handleClick = React.useCallback((e) => {
1748
1734
  if (onToggle) {
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.384",
3
+ "version": "0.1.386",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,5 @@
1
+ export type AriaProps = {
2
+ ariaLabel?: string;
3
+ ariaLabelledBy?: string;
4
+ ariaDescribedBy?: string;
5
+ };
@@ -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";
@@ -1,3 +1,6 @@
1
+ export * from "./AriaProps";
1
2
  export * from "./CommonProps";
3
+ export * from "./Density";
4
+ export * from "./Size";
2
5
  export * from "./StorybookProps";
3
6
  export * from "./useContainerProps";
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CommonProps, Density } from "../../common/CommonProps";
2
+ import { CommonProps, Density } from "../../common";
3
3
  export interface CardBodyProps extends CommonProps {
4
4
  /**
5
5
  * Sets gap, padding and margin.
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CommonProps, Density } from "../../common/CommonProps";
2
+ import { CommonProps, Density } from "../../common";
3
3
  export interface CardFooterProps extends CommonProps {
4
4
  /**
5
5
  * Sets gap, padding and margin.
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CommonProps, Density } from "../../common/CommonProps";
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/CommonProps";
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, title, forwardedRef, }: IconProps) => JSX.Element;
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/CommonProps";
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/CommonProps";
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/CommonProps";
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 "@trackunit/shared-utils";
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,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { CommonProps, Density } from "../../common/CommonProps";
2
+ import { CommonProps, Density } from "../../common";
3
3
  export interface WidgetBodyProps extends CommonProps {
4
4
  /**
5
5
  * Sets gap, padding and margin.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { GeneralColors } from "@trackunit/ui-design-tokens";
3
- import { CommonProps, Size } from "../../../common/CommonProps";
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 {