@trackunit/react-components 0.1.284 → 0.1.285

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
@@ -170,6 +170,22 @@ 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
189
  /**
174
190
  * - The Icon component is used to display an Icon.
175
191
  * - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
@@ -178,7 +194,7 @@ const isSafari = () => {
178
194
  * @param {IconProps} props - The props for the Icon component
179
195
  * @returns {JSX.Element} Icon component
180
196
  */
181
- const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, title, }) => {
197
+ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, title, forwardedRef, }) => {
182
198
  const useTagRef = React.useRef(null);
183
199
  const correctIconType = React.useMemo(() => {
184
200
  if (size === "small" || size === "medium") {
@@ -200,7 +216,7 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, typ
200
216
  useTagRef.current.setAttribute("href", href[correctIconType]);
201
217
  }
202
218
  }, [correctIconType, href]);
203
- return (jsxRuntime.jsx("span", { className: cvaIcon({ color, size, className }), "data-testid": dataTestId, onClick: onClick, ref: forwardedRef, children: jsxRuntime.jsxs("svg", { "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, role: "img", style: style, viewBox: correctIconType === "mini" ? "0 0 20 20" : "0 0 24 24", children: [jsxRuntime.jsx("title", { children: title ? title : iconName }), jsxRuntime.jsx("use", { href: href[correctIconType], ref: useTagRef })] }) }));
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
220
  };
205
221
 
206
222
  const cvaTag = cssClassVarianceUtilities.cvaMerge([
package/index.esm.js CHANGED
@@ -139,6 +139,22 @@ 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
158
  /**
143
159
  * - The Icon component is used to display an Icon.
144
160
  * - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
@@ -147,7 +163,7 @@ const isSafari = () => {
147
163
  * @param {IconProps} props - The props for the Icon component
148
164
  * @returns {JSX.Element} Icon component
149
165
  */
150
- const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, title, }) => {
166
+ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, title, forwardedRef, }) => {
151
167
  const useTagRef = useRef(null);
152
168
  const correctIconType = useMemo(() => {
153
169
  if (size === "small" || size === "medium") {
@@ -169,7 +185,7 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, typ
169
185
  useTagRef.current.setAttribute("href", href[correctIconType]);
170
186
  }
171
187
  }, [correctIconType, href]);
172
- return (jsx("span", { className: cvaIcon({ color, size, className }), "data-testid": dataTestId, onClick: onClick, ref: forwardedRef, children: jsxs("svg", { "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, role: "img", style: style, viewBox: correctIconType === "mini" ? "0 0 20 20" : "0 0 24 24", children: [jsx("title", { children: title ? title : iconName }), jsx("use", { href: href[correctIconType], ref: useTagRef })] }) }));
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
189
  };
174
190
 
175
191
  const cvaTag = cvaMerge([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.284",
3
+ "version": "0.1.285",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -311,7 +311,7 @@ export type IconProps = DiscriminatedIconProps & CommonProps & {
311
311
  */
312
312
  style?: CSSProperties;
313
313
  /**
314
- * The title (text) to show in the tooltip when hovering over an icon
314
+ * The title (text) to put in the aria-labelledby.
315
315
  * Default title is the name of the icon.
316
316
  * If a custom title is needed, set it using this prop.
317
317
  */
@@ -325,5 +325,5 @@ export type IconProps = DiscriminatedIconProps & CommonProps & {
325
325
  * @param {IconProps} props - The props for the Icon component
326
326
  * @returns {JSX.Element} Icon component
327
327
  */
328
- export declare const Icon: ({ name, size, className, dataTestId, color, onClick, type, style, forwardedRef, title, }: IconProps) => JSX.Element;
328
+ export declare const Icon: ({ name, size, className, dataTestId, color, onClick, type, style, title, forwardedRef, }: IconProps) => JSX.Element;
329
329
  export {};