@trackunit/react-components 1.4.61 → 1.4.64

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
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
4
5
  var sharedUtils = require('@trackunit/shared-utils');
5
6
  var uiDesignTokens = require('@trackunit/ui-design-tokens');
6
7
  var uiIcons = require('@trackunit/ui-icons');
@@ -8,7 +9,6 @@ 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');
11
- var react = require('react');
12
12
  var stringTs = require('string-ts');
13
13
  var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
14
14
  var reactSlot = require('@radix-ui/react-slot');
@@ -184,13 +184,12 @@ const cvaTag = cssClassVarianceUtilities.cvaMerge([
184
184
  "py-1",
185
185
  "px-2",
186
186
  "text-center",
187
- "whitespace-nowrap",
188
187
  "h-min",
189
188
  "min-w-[1.5rem]",
190
189
  "font-medium",
191
190
  "truncate",
192
191
  "max-w-full",
193
- "w-min",
192
+ "w-fit",
194
193
  "text-xs",
195
194
  ], {
196
195
  variants: {
@@ -199,7 +198,8 @@ const cvaTag = cssClassVarianceUtilities.cvaMerge([
199
198
  medium: "",
200
199
  },
201
200
  layout: {
202
- withIcon: "gap-2 pr-1",
201
+ containsDismiss: "gap-1 pr-1",
202
+ containsIcon: "gap-1",
203
203
  default: "",
204
204
  },
205
205
  color: {
@@ -207,7 +207,7 @@ const cvaTag = cssClassVarianceUtilities.cvaMerge([
207
207
  secondary: "bg-secondary-100 text-secondary-700",
208
208
  neutral: "bg-neutral-100 text-neutral-700",
209
209
  black: "bg-neutral-100 text-neutral-700",
210
- white: "bg-white-100 text-white-700",
210
+ white: "bg-white-100 text-neutral-600",
211
211
  info: "bg-info-100 text-info-700",
212
212
  success: "bg-success-100 text-success-700",
213
213
  warning: "bg-warning-100 text-warning-700",
@@ -222,6 +222,10 @@ const cvaTag = cssClassVarianceUtilities.cvaMerge([
222
222
  moving: "bg-neutral-100 text-neutral-700",
223
223
  active: "bg-neutral-100 text-neutral-700",
224
224
  },
225
+ border: {
226
+ none: "border-none",
227
+ default: "border border-slate-300",
228
+ },
225
229
  },
226
230
  defaultVariants: {
227
231
  size: "medium",
@@ -229,8 +233,9 @@ const cvaTag = cssClassVarianceUtilities.cvaMerge([
229
233
  color: "primary",
230
234
  },
231
235
  });
236
+ const cvaTagText = cssClassVarianceUtilities.cvaMerge(["truncate"]);
232
237
  const cvaTagIconContainer = cssClassVarianceUtilities.cvaMerge(["inline-flex", "self-center"]);
233
- const cvaTagIcon = cssClassVarianceUtilities.cvaMerge(["cursor-pointer", "transition-opacity", "hover:opacity-70"]);
238
+ const cvaTagIcon = cssClassVarianceUtilities.cvaMerge(["cursor-pointer", "transition-opacity", "hover:opacity-70", "text-neutral-500"]);
234
239
 
235
240
  /**
236
241
  * The tag component is used to categorize elements in the ui.
@@ -244,10 +249,25 @@ const cvaTagIcon = cssClassVarianceUtilities.cvaMerge(["cursor-pointer", "transi
244
249
  * @param {TagProps} props - The props for the tag component
245
250
  * @returns {ReactElement} tag component
246
251
  */
247
- const Tag = ({ className, dataTestId, children, size = "medium", onClose, color = "primary", disabled = false, ref, }) => {
248
- return (jsxRuntime.jsxs("span", { className: cvaTag({ className, size, color, layout: onClose ? "withIcon" : "default" }), "data-testid": dataTestId, ref: ref, children: [children, Boolean(onClose) && !disabled ? (
252
+ const Tag = ({ className, dataTestId, children, size = "medium", onClose, color = "primary", disabled = false, ref, icon, }) => {
253
+ const isSupportedDismissColor = react.useMemo(() => {
254
+ if (color === "neutral" || color === "primary" || color === "white") {
255
+ return true;
256
+ }
257
+ return false;
258
+ }, [color]);
259
+ const layout = react.useMemo(() => {
260
+ if (onClose && isSupportedDismissColor) {
261
+ return "containsDismiss";
262
+ }
263
+ if (icon) {
264
+ return "containsIcon";
265
+ }
266
+ return "default";
267
+ }, [onClose, icon, isSupportedDismissColor]);
268
+ return (jsxRuntime.jsxs("div", { className: cvaTag({ className, size, color, layout, border: color === "white" ? "default" : "none" }), "data-testid": dataTestId, ref: ref, children: [icon && size === "medium" ? jsxRuntime.jsx("div", { className: cvaTagIconContainer(), children: icon }) : null, jsxRuntime.jsx("span", { className: cvaTagText(), children: children }), Boolean(onClose) && isSupportedDismissColor && size === "medium" && !disabled ? (
249
269
  // a fix for multiselect deselecting tags working together with fade out animation
250
- jsxRuntime.jsx("div", { className: cvaTagIconContainer(), onMouseDown: onClose, children: jsxRuntime.jsx(Icon, { className: cvaTagIcon(), dataTestId: dataTestId + "Icon", name: "XCircle", size: size, style: { WebkitTransition: "-webkit-transform 0.150s" }, type: "solid" }) })) : null] }));
270
+ jsxRuntime.jsx("div", { className: cvaTagIconContainer(), onMouseDown: onClose, children: jsxRuntime.jsx(Icon, { className: cvaTagIcon(), dataTestId: dataTestId + "Icon", name: "XCircle", size: "small", style: { WebkitTransition: "-webkit-transform 0.150s" }, type: "solid" }) })) : null] }));
251
271
  };
252
272
  Tag.displayName = "Tag";
253
273
 
package/index.esm.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { useRef, useMemo, useEffect, useState, useCallback, createElement, useReducer, memo, forwardRef, createContext, useContext, isValidElement, cloneElement, Children } from 'react';
2
3
  import { objectKeys, uuidv4, objectEntries, objectValues } from '@trackunit/shared-utils';
3
4
  import { intentPalette, generalPalette, criticalityPalette, activityPalette, utilizationPalette, sitesPalette, rentalStatusPalette, themeScreenSizeAsNumber, color } from '@trackunit/ui-design-tokens';
4
5
  import { iconNames } from '@trackunit/ui-icons';
@@ -6,7 +7,6 @@ import IconSpriteMicro from '@trackunit/ui-icons/icons-sprite-micro.svg';
6
7
  import IconSpriteMini from '@trackunit/ui-icons/icons-sprite-mini.svg';
7
8
  import IconSpriteOutline from '@trackunit/ui-icons/icons-sprite-outline.svg';
8
9
  import IconSpriteSolid from '@trackunit/ui-icons/icons-sprite-solid.svg';
9
- import { useRef, useMemo, useEffect, useState, useCallback, createElement, useReducer, memo, forwardRef, createContext, useContext, isValidElement, cloneElement, Children } from 'react';
10
10
  import { snakeCase, titleCase } from 'string-ts';
11
11
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
12
12
  import { Slottable, Slot } from '@radix-ui/react-slot';
@@ -182,13 +182,12 @@ const cvaTag = cvaMerge([
182
182
  "py-1",
183
183
  "px-2",
184
184
  "text-center",
185
- "whitespace-nowrap",
186
185
  "h-min",
187
186
  "min-w-[1.5rem]",
188
187
  "font-medium",
189
188
  "truncate",
190
189
  "max-w-full",
191
- "w-min",
190
+ "w-fit",
192
191
  "text-xs",
193
192
  ], {
194
193
  variants: {
@@ -197,7 +196,8 @@ const cvaTag = cvaMerge([
197
196
  medium: "",
198
197
  },
199
198
  layout: {
200
- withIcon: "gap-2 pr-1",
199
+ containsDismiss: "gap-1 pr-1",
200
+ containsIcon: "gap-1",
201
201
  default: "",
202
202
  },
203
203
  color: {
@@ -205,7 +205,7 @@ const cvaTag = cvaMerge([
205
205
  secondary: "bg-secondary-100 text-secondary-700",
206
206
  neutral: "bg-neutral-100 text-neutral-700",
207
207
  black: "bg-neutral-100 text-neutral-700",
208
- white: "bg-white-100 text-white-700",
208
+ white: "bg-white-100 text-neutral-600",
209
209
  info: "bg-info-100 text-info-700",
210
210
  success: "bg-success-100 text-success-700",
211
211
  warning: "bg-warning-100 text-warning-700",
@@ -220,6 +220,10 @@ const cvaTag = cvaMerge([
220
220
  moving: "bg-neutral-100 text-neutral-700",
221
221
  active: "bg-neutral-100 text-neutral-700",
222
222
  },
223
+ border: {
224
+ none: "border-none",
225
+ default: "border border-slate-300",
226
+ },
223
227
  },
224
228
  defaultVariants: {
225
229
  size: "medium",
@@ -227,8 +231,9 @@ const cvaTag = cvaMerge([
227
231
  color: "primary",
228
232
  },
229
233
  });
234
+ const cvaTagText = cvaMerge(["truncate"]);
230
235
  const cvaTagIconContainer = cvaMerge(["inline-flex", "self-center"]);
231
- const cvaTagIcon = cvaMerge(["cursor-pointer", "transition-opacity", "hover:opacity-70"]);
236
+ const cvaTagIcon = cvaMerge(["cursor-pointer", "transition-opacity", "hover:opacity-70", "text-neutral-500"]);
232
237
 
233
238
  /**
234
239
  * The tag component is used to categorize elements in the ui.
@@ -242,10 +247,25 @@ const cvaTagIcon = cvaMerge(["cursor-pointer", "transition-opacity", "hover:opac
242
247
  * @param {TagProps} props - The props for the tag component
243
248
  * @returns {ReactElement} tag component
244
249
  */
245
- const Tag = ({ className, dataTestId, children, size = "medium", onClose, color = "primary", disabled = false, ref, }) => {
246
- return (jsxs("span", { className: cvaTag({ className, size, color, layout: onClose ? "withIcon" : "default" }), "data-testid": dataTestId, ref: ref, children: [children, Boolean(onClose) && !disabled ? (
250
+ const Tag = ({ className, dataTestId, children, size = "medium", onClose, color = "primary", disabled = false, ref, icon, }) => {
251
+ const isSupportedDismissColor = useMemo(() => {
252
+ if (color === "neutral" || color === "primary" || color === "white") {
253
+ return true;
254
+ }
255
+ return false;
256
+ }, [color]);
257
+ const layout = useMemo(() => {
258
+ if (onClose && isSupportedDismissColor) {
259
+ return "containsDismiss";
260
+ }
261
+ if (icon) {
262
+ return "containsIcon";
263
+ }
264
+ return "default";
265
+ }, [onClose, icon, isSupportedDismissColor]);
266
+ return (jsxs("div", { className: cvaTag({ className, size, color, layout, border: color === "white" ? "default" : "none" }), "data-testid": dataTestId, ref: ref, children: [icon && size === "medium" ? jsx("div", { className: cvaTagIconContainer(), children: icon }) : null, jsx("span", { className: cvaTagText(), children: children }), Boolean(onClose) && isSupportedDismissColor && size === "medium" && !disabled ? (
247
267
  // a fix for multiselect deselecting tags working together with fade out animation
248
- jsx("div", { className: cvaTagIconContainer(), onMouseDown: onClose, children: jsx(Icon, { className: cvaTagIcon(), dataTestId: dataTestId + "Icon", name: "XCircle", size: size, style: { WebkitTransition: "-webkit-transform 0.150s" }, type: "solid" }) })) : null] }));
268
+ jsx("div", { className: cvaTagIconContainer(), onMouseDown: onClose, children: jsx(Icon, { className: cvaTagIcon(), dataTestId: dataTestId + "Icon", name: "XCircle", size: "small", style: { WebkitTransition: "-webkit-transform 0.150s" }, type: "solid" }) })) : null] }));
249
269
  };
250
270
  Tag.displayName = "Tag";
251
271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "1.4.61",
3
+ "version": "1.4.64",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -18,11 +18,11 @@
18
18
  "@tanstack/react-router": "1.47.1",
19
19
  "string-ts": "^2.0.0",
20
20
  "tailwind-merge": "^2.0.0",
21
- "@trackunit/ui-design-tokens": "1.3.49",
22
- "@trackunit/css-class-variance-utilities": "1.3.49",
23
- "@trackunit/shared-utils": "1.5.49",
24
- "@trackunit/ui-icons": "1.3.49",
25
- "@trackunit/react-table-pagination": "1.3.50"
21
+ "@trackunit/ui-design-tokens": "1.3.51",
22
+ "@trackunit/css-class-variance-utilities": "1.3.51",
23
+ "@trackunit/shared-utils": "1.5.51",
24
+ "@trackunit/ui-icons": "1.3.51",
25
+ "@trackunit/react-table-pagination": "1.3.52"
26
26
  },
27
27
  "module": "./index.esm.js",
28
28
  "main": "./index.cjs.js",
@@ -12,6 +12,7 @@ export interface TagProps extends CommonProps {
12
12
  /**
13
13
  * A handler for a click event triggered on X icon.
14
14
  * If not passed then x icon won't be visible.
15
+ * Available only for neutral, primary and white tags.
15
16
  *
16
17
  */
17
18
  onClose?: MouseEventHandler<HTMLDivElement>;
@@ -31,7 +32,11 @@ export interface TagProps extends CommonProps {
31
32
  /**
32
33
  * A ref for the component
33
34
  */
34
- ref?: Ref<HTMLElement>;
35
+ ref?: Ref<HTMLDivElement>;
36
+ /**
37
+ * The icon to display. Only supported for medium size.
38
+ */
39
+ icon?: ReactNode;
35
40
  }
36
41
  /**
37
42
  * The tag component is used to categorize elements in the ui.
@@ -46,6 +51,6 @@ export interface TagProps extends CommonProps {
46
51
  * @returns {ReactElement} tag component
47
52
  */
48
53
  export declare const Tag: {
49
- ({ className, dataTestId, children, size, onClose, color, disabled, ref, }: TagProps): import("react/jsx-runtime").JSX.Element;
54
+ ({ className, dataTestId, children, size, onClose, color, disabled, ref, icon, }: TagProps): import("react/jsx-runtime").JSX.Element;
50
55
  displayName: string;
51
56
  };
@@ -1,7 +1,9 @@
1
1
  export declare const cvaTag: (props?: ({
2
2
  size?: "small" | "medium" | null | undefined;
3
- layout?: "default" | "withIcon" | null | undefined;
3
+ layout?: "default" | "containsDismiss" | "containsIcon" | null | undefined;
4
4
  color?: "primary" | "secondary" | "neutral" | "black" | "white" | "info" | "success" | "warning" | "danger" | "good" | "low" | "critical" | "working" | "stopped" | "idle" | "unknown" | "moving" | "active" | null | undefined;
5
+ border?: "default" | "none" | null | undefined;
5
6
  } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
7
+ export declare const cvaTagText: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
6
8
  export declare const cvaTagIconContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
7
9
  export declare const cvaTagIcon: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;