@trackunit/react-components 0.3.7 → 0.3.8
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 +29 -4
- package/index.esm.js +29 -4
- package/package.json +1 -1
- package/src/components/Icon/Icon.d.ts +9 -7
- package/src/components/Icon/Icon.variants.d.ts +2 -1
package/index.cjs.js
CHANGED
|
@@ -5,6 +5,7 @@ var React = require('react');
|
|
|
5
5
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
6
6
|
var uiDesignTokens = require('@trackunit/ui-design-tokens');
|
|
7
7
|
var uiIcons = require('@trackunit/ui-icons');
|
|
8
|
+
var IconSpriteMicro = require('@trackunit/ui-icons/icons-sprite-micro.svg');
|
|
8
9
|
var IconSpriteMini = require('@trackunit/ui-icons/icons-sprite-mini.svg');
|
|
9
10
|
var IconSpriteOutline = require('@trackunit/ui-icons/icons-sprite-outline.svg');
|
|
10
11
|
var IconSpriteSolid = require('@trackunit/ui-icons/icons-sprite-solid.svg');
|
|
@@ -104,9 +105,17 @@ const cvaIcon = cssClassVarianceUtilities.cvaMerge(["aspect-square", "inline-gri
|
|
|
104
105
|
small: "w-4",
|
|
105
106
|
medium: "w-5",
|
|
106
107
|
large: "w-6",
|
|
107
|
-
|
|
108
|
+
},
|
|
109
|
+
fontSize: {
|
|
110
|
+
true: "w-[1em]",
|
|
111
|
+
false: "",
|
|
108
112
|
},
|
|
109
113
|
},
|
|
114
|
+
compoundVariants: [
|
|
115
|
+
{ fontSize: true, size: "small", className: "w-[1em]" },
|
|
116
|
+
{ fontSize: true, size: "medium", className: "w-[1em]" },
|
|
117
|
+
{ fontSize: true, size: "large", className: "w-[1em]" },
|
|
118
|
+
],
|
|
110
119
|
defaultVariants: {
|
|
111
120
|
color: "default",
|
|
112
121
|
size: "large",
|
|
@@ -157,11 +166,14 @@ const isSafari = () => {
|
|
|
157
166
|
* @param {IconProps} props - The props for the Icon component
|
|
158
167
|
* @returns {JSX.Element} Icon component
|
|
159
168
|
*/
|
|
160
|
-
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }) => {
|
|
169
|
+
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, fontSize, ariaLabelledBy, ariaDescribedBy, }) => {
|
|
161
170
|
const useTagRef = React.useRef(null);
|
|
162
171
|
const ICON_CONTAINER_ID = uuid.v4();
|
|
163
172
|
const correctIconType = React.useMemo(() => {
|
|
164
|
-
if (size === "small"
|
|
173
|
+
if (size === "small") {
|
|
174
|
+
return "micro";
|
|
175
|
+
}
|
|
176
|
+
if (size === "medium") {
|
|
165
177
|
return "mini";
|
|
166
178
|
}
|
|
167
179
|
if (type === "solid") {
|
|
@@ -169,18 +181,31 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, typ
|
|
|
169
181
|
}
|
|
170
182
|
return "outline";
|
|
171
183
|
}, [type, size]);
|
|
184
|
+
const correctViewBox = React.useMemo(() => {
|
|
185
|
+
if (size === "small") {
|
|
186
|
+
return "0 0 16 16";
|
|
187
|
+
}
|
|
188
|
+
if (size === "medium") {
|
|
189
|
+
return "0 0 20 20";
|
|
190
|
+
}
|
|
191
|
+
if (type === "solid") {
|
|
192
|
+
return "0 0 24 24";
|
|
193
|
+
}
|
|
194
|
+
return "0 0 24 24";
|
|
195
|
+
}, [type, size]);
|
|
172
196
|
const iconName = uiIcons.iconNames[name];
|
|
173
197
|
const href = React.useMemo(() => ({
|
|
174
198
|
solid: `${IconSpriteSolid}#${iconName}`,
|
|
175
199
|
outline: `${IconSpriteOutline}#${iconName}`,
|
|
176
200
|
mini: `${IconSpriteMini}#${iconName}`,
|
|
201
|
+
micro: `${IconSpriteMicro}#${iconName}`,
|
|
177
202
|
}), [iconName]);
|
|
178
203
|
React.useEffect(() => {
|
|
179
204
|
if (isSafari() && useTagRef.current) {
|
|
180
205
|
useTagRef.current.setAttribute("href", href[correctIconType]);
|
|
181
206
|
}
|
|
182
207
|
}, [correctIconType, href]);
|
|
183
|
-
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:
|
|
208
|
+
return (jsxRuntime.jsx("span", { "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel ? ariaLabel : stringTs.titleCase(iconName), "aria-labelledby": ariaLabelledBy, className: cvaIcon({ color, size, fontSize, 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: correctViewBox, children: jsxRuntime.jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
|
|
184
209
|
};
|
|
185
210
|
|
|
186
211
|
const cvaTag = cssClassVarianceUtilities.cvaMerge([
|
package/index.esm.js
CHANGED
|
@@ -4,6 +4,7 @@ import React__default, { useRef, useMemo, useEffect, useState, useReducer, useCa
|
|
|
4
4
|
import { objectKeys, objectEntries, objectValues } from '@trackunit/shared-utils';
|
|
5
5
|
import { rentalStatusPalette, intentPalette, generalPalette, criticalityPalette, activityPalette, utilizationPalette, sitesPalette, themeScreenSizeAsNumber, color } from '@trackunit/ui-design-tokens';
|
|
6
6
|
import { iconNames } from '@trackunit/ui-icons';
|
|
7
|
+
import IconSpriteMicro from '@trackunit/ui-icons/icons-sprite-micro.svg';
|
|
7
8
|
import IconSpriteMini from '@trackunit/ui-icons/icons-sprite-mini.svg';
|
|
8
9
|
import IconSpriteOutline from '@trackunit/ui-icons/icons-sprite-outline.svg';
|
|
9
10
|
import IconSpriteSolid from '@trackunit/ui-icons/icons-sprite-solid.svg';
|
|
@@ -84,9 +85,17 @@ const cvaIcon = cvaMerge(["aspect-square", "inline-grid", "relative"], {
|
|
|
84
85
|
small: "w-4",
|
|
85
86
|
medium: "w-5",
|
|
86
87
|
large: "w-6",
|
|
87
|
-
|
|
88
|
+
},
|
|
89
|
+
fontSize: {
|
|
90
|
+
true: "w-[1em]",
|
|
91
|
+
false: "",
|
|
88
92
|
},
|
|
89
93
|
},
|
|
94
|
+
compoundVariants: [
|
|
95
|
+
{ fontSize: true, size: "small", className: "w-[1em]" },
|
|
96
|
+
{ fontSize: true, size: "medium", className: "w-[1em]" },
|
|
97
|
+
{ fontSize: true, size: "large", className: "w-[1em]" },
|
|
98
|
+
],
|
|
90
99
|
defaultVariants: {
|
|
91
100
|
color: "default",
|
|
92
101
|
size: "large",
|
|
@@ -137,11 +146,14 @@ const isSafari = () => {
|
|
|
137
146
|
* @param {IconProps} props - The props for the Icon component
|
|
138
147
|
* @returns {JSX.Element} Icon component
|
|
139
148
|
*/
|
|
140
|
-
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }) => {
|
|
149
|
+
const Icon = ({ name, size = "large", className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, fontSize, ariaLabelledBy, ariaDescribedBy, }) => {
|
|
141
150
|
const useTagRef = useRef(null);
|
|
142
151
|
const ICON_CONTAINER_ID = v4();
|
|
143
152
|
const correctIconType = useMemo(() => {
|
|
144
|
-
if (size === "small"
|
|
153
|
+
if (size === "small") {
|
|
154
|
+
return "micro";
|
|
155
|
+
}
|
|
156
|
+
if (size === "medium") {
|
|
145
157
|
return "mini";
|
|
146
158
|
}
|
|
147
159
|
if (type === "solid") {
|
|
@@ -149,18 +161,31 @@ const Icon = ({ name, size = "large", className, dataTestId, color, onClick, typ
|
|
|
149
161
|
}
|
|
150
162
|
return "outline";
|
|
151
163
|
}, [type, size]);
|
|
164
|
+
const correctViewBox = useMemo(() => {
|
|
165
|
+
if (size === "small") {
|
|
166
|
+
return "0 0 16 16";
|
|
167
|
+
}
|
|
168
|
+
if (size === "medium") {
|
|
169
|
+
return "0 0 20 20";
|
|
170
|
+
}
|
|
171
|
+
if (type === "solid") {
|
|
172
|
+
return "0 0 24 24";
|
|
173
|
+
}
|
|
174
|
+
return "0 0 24 24";
|
|
175
|
+
}, [type, size]);
|
|
152
176
|
const iconName = iconNames[name];
|
|
153
177
|
const href = useMemo(() => ({
|
|
154
178
|
solid: `${IconSpriteSolid}#${iconName}`,
|
|
155
179
|
outline: `${IconSpriteOutline}#${iconName}`,
|
|
156
180
|
mini: `${IconSpriteMini}#${iconName}`,
|
|
181
|
+
micro: `${IconSpriteMicro}#${iconName}`,
|
|
157
182
|
}), [iconName]);
|
|
158
183
|
useEffect(() => {
|
|
159
184
|
if (isSafari() && useTagRef.current) {
|
|
160
185
|
useTagRef.current.setAttribute("href", href[correctIconType]);
|
|
161
186
|
}
|
|
162
187
|
}, [correctIconType, href]);
|
|
163
|
-
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:
|
|
188
|
+
return (jsx("span", { "aria-describedby": ariaDescribedBy, "aria-label": ariaLabel ? ariaLabel : titleCase(iconName), "aria-labelledby": ariaLabelledBy, className: cvaIcon({ color, size, fontSize, 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: correctViewBox, children: jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
|
|
164
189
|
};
|
|
165
190
|
|
|
166
191
|
const cvaTag = cvaMerge([
|
package/package.json
CHANGED
|
@@ -252,10 +252,6 @@ export declare const iconPalette: {
|
|
|
252
252
|
};
|
|
253
253
|
};
|
|
254
254
|
export declare const iconColorNames: ("info" | "success" | "warning" | "danger" | "primary" | "secondary" | "accent" | "neutral" | "black" | "white" | "good" | "low" | "critical" | "working" | "idle" | "stopped" | "unknown" | "moving" | "active" | "unused" | "utilized" | "heavily_utilized" | "unknown_utilization" | "site" | "on_rent" | "returned" | "available" | "pickup_ready" | "transfer" | "in_repair" | "other_rental_status")[];
|
|
255
|
-
type IconPropsFont = {
|
|
256
|
-
size?: "font";
|
|
257
|
-
type?: "solid" | "outline";
|
|
258
|
-
};
|
|
259
255
|
type IconPropsSmall = {
|
|
260
256
|
size?: "small";
|
|
261
257
|
type?: "solid";
|
|
@@ -268,7 +264,7 @@ type IconPropsLarge = {
|
|
|
268
264
|
size?: "large";
|
|
269
265
|
type?: "solid" | "outline";
|
|
270
266
|
};
|
|
271
|
-
type DiscriminatedIconProps =
|
|
267
|
+
type DiscriminatedIconProps = IconPropsSmall | IconPropsMedium | IconPropsLarge;
|
|
272
268
|
export type IconProps = DiscriminatedIconProps & CommonProps & AriaProps & {
|
|
273
269
|
/**
|
|
274
270
|
* The name of the icon to be rendered.
|
|
@@ -287,7 +283,7 @@ export type IconProps = DiscriminatedIconProps & CommonProps & AriaProps & {
|
|
|
287
283
|
* Default value is Large.
|
|
288
284
|
* If a custom size is needed, set it in the className.
|
|
289
285
|
*/
|
|
290
|
-
size?: Size
|
|
286
|
+
size?: Size;
|
|
291
287
|
/**
|
|
292
288
|
* Select if the icon should be rendered as solid or outline.
|
|
293
289
|
* Default value depends on the Size prop, mini == solid, medium == solid, large == outline.
|
|
@@ -307,6 +303,12 @@ export type IconProps = DiscriminatedIconProps & CommonProps & AriaProps & {
|
|
|
307
303
|
* @memberof IconProps
|
|
308
304
|
*/
|
|
309
305
|
style?: CSSProperties;
|
|
306
|
+
/**
|
|
307
|
+
* If true, the icon will be rendered with the font size of the parent element.
|
|
308
|
+
*
|
|
309
|
+
* @default false
|
|
310
|
+
*/
|
|
311
|
+
fontSize?: boolean;
|
|
310
312
|
};
|
|
311
313
|
/**
|
|
312
314
|
* - The Icon component is used to display an Icon.
|
|
@@ -316,5 +318,5 @@ export type IconProps = DiscriminatedIconProps & CommonProps & AriaProps & {
|
|
|
316
318
|
* @param {IconProps} props - The props for the Icon component
|
|
317
319
|
* @returns {JSX.Element} Icon component
|
|
318
320
|
*/
|
|
319
|
-
export declare const Icon: ({ name, size, className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, ariaLabelledBy, ariaDescribedBy, }: IconProps) => import("react/jsx-runtime").JSX.Element;
|
|
321
|
+
export declare const Icon: ({ name, size, className, dataTestId, color, onClick, type, style, forwardedRef, ariaLabel, fontSize, ariaLabelledBy, ariaDescribedBy, }: IconProps) => import("react/jsx-runtime").JSX.Element;
|
|
320
322
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const cvaIcon: (props?: ({
|
|
2
2
|
color?: "default" | "primary" | "secondary" | "accent" | "neutral" | "info" | "success" | "warning" | "danger" | "good" | "low" | "critical" | "working" | "idle" | "moving" | "active" | "stopped" | "unknown" | "black" | "white" | "unused" | "utilized" | "heavily_utilized" | "unknown_utilization" | "site" | "on_rent" | "returned" | "available" | "pickup_ready" | "transfer" | "in_repair" | "other_rental_status" | null | undefined;
|
|
3
|
-
size?: "small" | "medium" | "large" |
|
|
3
|
+
size?: "small" | "medium" | "large" | null | undefined;
|
|
4
|
+
fontSize?: boolean | null | undefined;
|
|
4
5
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
5
6
|
export declare const cvaIconComponent: (props?: ({
|
|
6
7
|
iconType?: "solid" | "outline" | null | undefined;
|