@trackunit/react-components 0.1.202 → 0.1.206
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 +16 -6
- package/index.esm.js +17 -7
- package/package.json +1 -1
- package/src/components/Icon/Icon.d.ts +10 -8
package/index.cjs.js
CHANGED
|
@@ -195,6 +195,10 @@ cssClassVarianceUtilities.cvaMerge([
|
|
|
195
195
|
|
|
196
196
|
const iconPalette = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, uiDesignTokens.intentPalette), uiDesignTokens.generalPalette), uiDesignTokens.criticalityPalette), uiDesignTokens.activityPalette), uiDesignTokens.utilizationPalette), uiDesignTokens.sitesPalette), uiDesignTokens.rentalStatusPalette);
|
|
197
197
|
const iconColorNames = Object.keys(iconPalette).map(key => key.toLowerCase()); // This users the object in the Object.keys() to infer the type of the keys.
|
|
198
|
+
const isSafari = () => {
|
|
199
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
200
|
+
return ua.includes("safari") && !ua.includes("chrome");
|
|
201
|
+
};
|
|
198
202
|
/**
|
|
199
203
|
* - The Icon component is used to display an Icon.
|
|
200
204
|
* - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
|
|
@@ -204,16 +208,22 @@ const iconColorNames = Object.keys(iconPalette).map(key => key.toLowerCase()); /
|
|
|
204
208
|
* @returns {JSX.Element} Icon component
|
|
205
209
|
*/
|
|
206
210
|
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, fillColor, type, style, forwardedRef, }) => {
|
|
207
|
-
const
|
|
211
|
+
const useTagRef = React.useRef(null);
|
|
212
|
+
const correctIconType = React.useMemo(() => (type ? type : size === "large" ? "outline" : "solid"), [type, size]);
|
|
208
213
|
const iconName = uiIcons.iconNames[name];
|
|
214
|
+
const href = React.useMemo(() => ({
|
|
215
|
+
solid: `${IconSpriteSolid__default["default"]}#${iconName}`,
|
|
216
|
+
outline: `${IconSpriteOutline__default["default"]}#${iconName}`,
|
|
217
|
+
}), [iconName]);
|
|
218
|
+
React.useEffect(() => {
|
|
219
|
+
if (isSafari() && useTagRef.current) {
|
|
220
|
+
useTagRef.current.setAttribute("href", href[correctIconType]);
|
|
221
|
+
}
|
|
222
|
+
}, [correctIconType, href]);
|
|
209
223
|
if (!iconName) {
|
|
210
224
|
return null;
|
|
211
225
|
}
|
|
212
|
-
|
|
213
|
-
solid: `${IconSpriteSolid__default["default"]}#${iconName}`,
|
|
214
|
-
outline: `${IconSpriteOutline__default["default"]}#${iconName}`,
|
|
215
|
-
};
|
|
216
|
-
return (jsxRuntime.jsx("span", { className: cvaIcon({ color, size, className }), onClick: onClick, "data-testid": dataTestId, ref: forwardedRef, children: jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, style: fillColor ? Object.assign(Object.assign({}, style), { fill: fillColor }) : Object.assign({}, style), children: jsxRuntime.jsx("use", { href: href[correctIconType] }) }) }));
|
|
226
|
+
return (jsxRuntime.jsx("span", { className: cvaIcon({ color, size, className }), onClick: onClick, "data-testid": dataTestId, ref: forwardedRef, children: jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, style: fillColor ? Object.assign(Object.assign({}, style), { fill: fillColor }) : Object.assign({}, style), children: jsxRuntime.jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
|
|
217
227
|
};
|
|
218
228
|
|
|
219
229
|
const cvaTag = cssClassVarianceUtilities.cvaMerge([
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, {
|
|
3
|
+
import React__default, { useRef, useMemo, useEffect, useState, createContext, useContext, forwardRef, isValidElement, cloneElement, useCallback, memo, Children, useReducer } from 'react';
|
|
4
4
|
import { rentalStatusPalette, intentPalette, generalPalette, criticalityPalette, activityPalette, utilizationPalette, sitesPalette, color } from '@trackunit/ui-design-tokens';
|
|
5
5
|
import { iconNames } from '@trackunit/ui-icons';
|
|
6
6
|
import IconSpriteOutline from '@trackunit/ui-icons/icons-sprite-outline.svg';
|
|
@@ -166,6 +166,10 @@ cvaMerge([
|
|
|
166
166
|
|
|
167
167
|
const iconPalette = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, intentPalette), generalPalette), criticalityPalette), activityPalette), utilizationPalette), sitesPalette), rentalStatusPalette);
|
|
168
168
|
const iconColorNames = Object.keys(iconPalette).map(key => key.toLowerCase()); // This users the object in the Object.keys() to infer the type of the keys.
|
|
169
|
+
const isSafari = () => {
|
|
170
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
171
|
+
return ua.includes("safari") && !ua.includes("chrome");
|
|
172
|
+
};
|
|
169
173
|
/**
|
|
170
174
|
* - The Icon component is used to display an Icon.
|
|
171
175
|
* - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
|
|
@@ -175,16 +179,22 @@ const iconColorNames = Object.keys(iconPalette).map(key => key.toLowerCase()); /
|
|
|
175
179
|
* @returns {JSX.Element} Icon component
|
|
176
180
|
*/
|
|
177
181
|
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, fillColor, type, style, forwardedRef, }) => {
|
|
178
|
-
const
|
|
182
|
+
const useTagRef = useRef(null);
|
|
183
|
+
const correctIconType = useMemo(() => (type ? type : size === "large" ? "outline" : "solid"), [type, size]);
|
|
179
184
|
const iconName = iconNames[name];
|
|
185
|
+
const href = useMemo(() => ({
|
|
186
|
+
solid: `${IconSpriteSolid}#${iconName}`,
|
|
187
|
+
outline: `${IconSpriteOutline}#${iconName}`,
|
|
188
|
+
}), [iconName]);
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
if (isSafari() && useTagRef.current) {
|
|
191
|
+
useTagRef.current.setAttribute("href", href[correctIconType]);
|
|
192
|
+
}
|
|
193
|
+
}, [correctIconType, href]);
|
|
180
194
|
if (!iconName) {
|
|
181
195
|
return null;
|
|
182
196
|
}
|
|
183
|
-
|
|
184
|
-
solid: `${IconSpriteSolid}#${iconName}`,
|
|
185
|
-
outline: `${IconSpriteOutline}#${iconName}`,
|
|
186
|
-
};
|
|
187
|
-
return (jsx("span", { className: cvaIcon({ color, size, className }), onClick: onClick, "data-testid": dataTestId, ref: forwardedRef, children: jsx("svg", { viewBox: "0 0 24 24", "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, style: fillColor ? Object.assign(Object.assign({}, style), { fill: fillColor }) : Object.assign({}, style), children: jsx("use", { href: href[correctIconType] }) }) }));
|
|
197
|
+
return (jsx("span", { className: cvaIcon({ color, size, className }), onClick: onClick, "data-testid": dataTestId, ref: forwardedRef, children: jsx("svg", { viewBox: "0 0 24 24", "data-testid": dataTestId ? `${dataTestId}-${iconName}` : iconName, style: fillColor ? Object.assign(Object.assign({}, style), { fill: fillColor }) : Object.assign({}, style), children: jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
|
|
188
198
|
};
|
|
189
199
|
|
|
190
200
|
const cvaTag = cvaMerge([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { ActivityColors, CriticalityColors, GeneralColors, IntentColors, RentalStatusColors, SitesColors, UtilizationColors } from "@trackunit/ui-design-tokens";
|
|
2
3
|
import { IconName } from "@trackunit/ui-icons";
|
|
3
|
-
import * as React from "react";
|
|
4
4
|
import { CommonProps, Size } from "../../common/CommonProps";
|
|
5
5
|
export type IconColors = IntentColors | GeneralColors | CriticalityColors | ActivityColors | UtilizationColors | SitesColors | RentalStatusColors;
|
|
6
6
|
export declare const iconPalette: {
|
|
@@ -190,12 +190,7 @@ export declare const iconPalette: {
|
|
|
190
190
|
readonly 300: "212 212 212";
|
|
191
191
|
readonly 400: "163 163 163";
|
|
192
192
|
readonly 500: "115 115 115";
|
|
193
|
-
readonly 600: "82 82 82";
|
|
194
|
-
* The size of the icon.
|
|
195
|
-
* Small = 16x16px, medium = 20x20px, Large = 24x24px.
|
|
196
|
-
* Default value is Large.
|
|
197
|
-
* If a custom size is needed, set it in the className.
|
|
198
|
-
*/
|
|
193
|
+
readonly 600: "82 82 82";
|
|
199
194
|
readonly 700: "64 64 64";
|
|
200
195
|
readonly 800: "38 38 38";
|
|
201
196
|
readonly 900: "23 23 23";
|
|
@@ -214,7 +209,14 @@ export declare const iconPalette: {
|
|
|
214
209
|
readonly 400: "96 165 250";
|
|
215
210
|
readonly 500: "59 130 246";
|
|
216
211
|
readonly 600: "37 99 235";
|
|
217
|
-
readonly 700: "29 78 216";
|
|
212
|
+
readonly 700: "29 78 216"; /**
|
|
213
|
+
* - The Icon component is used to display an Icon.
|
|
214
|
+
* - Icons are semantic vector graphics that adds character and improves the visual appeal of elements when combined with.
|
|
215
|
+
* - All the [HeroIcons](https://heroicons.dev/) as well as custom Trackunit icons are available.
|
|
216
|
+
|
|
217
|
+
* @param {IconProps} props - The props for the Icon component
|
|
218
|
+
* @returns {JSX.Element} Icon component
|
|
219
|
+
*/
|
|
218
220
|
readonly 800: "30 64 175";
|
|
219
221
|
readonly 900: "30 58 138";
|
|
220
222
|
};
|