@trackunit/utilization-indicator 1.24.7 → 1.24.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 CHANGED
@@ -62,10 +62,9 @@ const setupLibraryTranslations = () => {
62
62
  * Returns the activity indicator props.
63
63
  *
64
64
  * @param state - The activity state.
65
- * @param size - The size of the icon.
66
65
  * @returns {UseActivity} - The activity indicator props.
67
66
  */
68
- const useActivity = (state, size = "medium") => {
67
+ const useActivity = (state, _size) => {
69
68
  const [t] = useTranslation();
70
69
  return react.useMemo(() => {
71
70
  switch (state) {
@@ -73,7 +72,7 @@ const useActivity = (state, size = "medium") => {
73
72
  case "WORKING":
74
73
  return {
75
74
  activityIndicator: {
76
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "PlayCircle", size: size }),
75
+ iconName: "PlayCircle",
77
76
  label: t("indicator.activity.working"),
78
77
  color: "working",
79
78
  },
@@ -82,7 +81,7 @@ const useActivity = (state, size = "medium") => {
82
81
  case "IDLING":
83
82
  return {
84
83
  activityIndicator: {
85
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "PauseCircle", size: size }),
84
+ iconName: "PauseCircle",
86
85
  label: t("indicator.activity.idle"),
87
86
  color: "idle",
88
87
  },
@@ -91,7 +90,7 @@ const useActivity = (state, size = "medium") => {
91
90
  case "STOPPED":
92
91
  return {
93
92
  activityIndicator: {
94
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "StopCircle", size: size }),
93
+ iconName: "StopCircle",
95
94
  label: t("indicator.activity.stopped"),
96
95
  color: "stopped",
97
96
  },
@@ -100,7 +99,7 @@ const useActivity = (state, size = "medium") => {
100
99
  case "UNKNOWN":
101
100
  return {
102
101
  activityIndicator: {
103
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "QuestionMarkCircle", size: size }),
102
+ iconName: "QuestionMarkCircle",
104
103
  label: t("indicator.activity.unknown"),
105
104
  color: "unknown",
106
105
  },
@@ -108,7 +107,7 @@ const useActivity = (state, size = "medium") => {
108
107
  default:
109
108
  return { activityIndicator: undefined };
110
109
  }
111
- }, [state, size, t]);
110
+ }, [state, t]);
112
111
  };
113
112
 
114
113
  /**
@@ -118,8 +117,11 @@ const useActivity = (state, size = "medium") => {
118
117
  * @returns {ReactElement | null } - Activity indicator.
119
118
  */
120
119
  const ActivityIndicator = (props) => {
121
- const { activityIndicator } = useActivity(props.state, props.size);
122
- return activityIndicator ? jsxRuntime.jsx(reactComponents.Indicator, { ...activityIndicator, ...props }) : null;
120
+ const { activityIndicator } = useActivity(props.state);
121
+ if (!activityIndicator)
122
+ return null;
123
+ const { iconName, ...indicatorProps } = activityIndicator;
124
+ return jsxRuntime.jsx(reactComponents.Indicator, { ...indicatorProps, ...props, icon: jsxRuntime.jsx(reactComponents.Icon, { name: iconName, size: props.size }) });
123
125
  };
124
126
 
125
127
  /**
@@ -134,7 +136,7 @@ const useUtilization = state => {
134
136
  case utilizationTokens.UtilizationState.Unused:
135
137
  return {
136
138
  utilizationIndicator: {
137
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "ExclamationTriangle", size: "medium" }),
139
+ iconName: "ExclamationTriangle",
138
140
  label: t("indicator.utilization.unused"),
139
141
  color: "unused",
140
142
  },
@@ -142,7 +144,7 @@ const useUtilization = state => {
142
144
  case utilizationTokens.UtilizationState.Utilized:
143
145
  return {
144
146
  utilizationIndicator: {
145
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "CheckCircle", size: "medium" }),
147
+ iconName: "CheckCircle",
146
148
  label: t("indicator.utilization.utilized"),
147
149
  color: "utilized",
148
150
  },
@@ -150,7 +152,7 @@ const useUtilization = state => {
150
152
  case utilizationTokens.UtilizationState.HeavilyUtilized:
151
153
  return {
152
154
  utilizationIndicator: {
153
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "ShieldExclamation", size: "medium" }),
155
+ iconName: "ShieldExclamation",
154
156
  label: t("indicator.utilization.heavilyUtilized"),
155
157
  color: "heavily_utilized",
156
158
  },
@@ -158,7 +160,7 @@ const useUtilization = state => {
158
160
  case utilizationTokens.UtilizationState.Unknown:
159
161
  return {
160
162
  utilizationIndicator: {
161
- icon: jsxRuntime.jsx(reactComponents.Icon, { name: "QuestionMarkCircle", size: "medium" }),
163
+ iconName: "QuestionMarkCircle",
162
164
  label: "N/A",
163
165
  color: "unknown_utilization",
164
166
  },
@@ -177,7 +179,10 @@ const useUtilization = state => {
177
179
  */
178
180
  const UtilizationIndicator = (props) => {
179
181
  const { utilizationIndicator } = useUtilization(props.state);
180
- return utilizationIndicator ? jsxRuntime.jsx(reactComponents.Indicator, { ...utilizationIndicator, ...props }) : null;
182
+ if (!utilizationIndicator)
183
+ return null;
184
+ const { iconName, ...indicatorProps } = utilizationIndicator;
185
+ return jsxRuntime.jsx(reactComponents.Indicator, { ...indicatorProps, ...props, icon: jsxRuntime.jsx(reactComponents.Icon, { name: iconName, size: "medium" }) });
181
186
  };
182
187
 
183
188
  /*
package/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
3
- import { Icon, Indicator } from '@trackunit/react-components';
3
+ import { Indicator, Icon } from '@trackunit/react-components';
4
4
  import { assetActivityState, UtilizationState } from '@trackunit/utilization-tokens';
5
5
  import { useMemo } from 'react';
6
6
 
@@ -60,10 +60,9 @@ const setupLibraryTranslations = () => {
60
60
  * Returns the activity indicator props.
61
61
  *
62
62
  * @param state - The activity state.
63
- * @param size - The size of the icon.
64
63
  * @returns {UseActivity} - The activity indicator props.
65
64
  */
66
- const useActivity = (state, size = "medium") => {
65
+ const useActivity = (state, _size) => {
67
66
  const [t] = useTranslation();
68
67
  return useMemo(() => {
69
68
  switch (state) {
@@ -71,7 +70,7 @@ const useActivity = (state, size = "medium") => {
71
70
  case "WORKING":
72
71
  return {
73
72
  activityIndicator: {
74
- icon: jsx(Icon, { name: "PlayCircle", size: size }),
73
+ iconName: "PlayCircle",
75
74
  label: t("indicator.activity.working"),
76
75
  color: "working",
77
76
  },
@@ -80,7 +79,7 @@ const useActivity = (state, size = "medium") => {
80
79
  case "IDLING":
81
80
  return {
82
81
  activityIndicator: {
83
- icon: jsx(Icon, { name: "PauseCircle", size: size }),
82
+ iconName: "PauseCircle",
84
83
  label: t("indicator.activity.idle"),
85
84
  color: "idle",
86
85
  },
@@ -89,7 +88,7 @@ const useActivity = (state, size = "medium") => {
89
88
  case "STOPPED":
90
89
  return {
91
90
  activityIndicator: {
92
- icon: jsx(Icon, { name: "StopCircle", size: size }),
91
+ iconName: "StopCircle",
93
92
  label: t("indicator.activity.stopped"),
94
93
  color: "stopped",
95
94
  },
@@ -98,7 +97,7 @@ const useActivity = (state, size = "medium") => {
98
97
  case "UNKNOWN":
99
98
  return {
100
99
  activityIndicator: {
101
- icon: jsx(Icon, { name: "QuestionMarkCircle", size: size }),
100
+ iconName: "QuestionMarkCircle",
102
101
  label: t("indicator.activity.unknown"),
103
102
  color: "unknown",
104
103
  },
@@ -106,7 +105,7 @@ const useActivity = (state, size = "medium") => {
106
105
  default:
107
106
  return { activityIndicator: undefined };
108
107
  }
109
- }, [state, size, t]);
108
+ }, [state, t]);
110
109
  };
111
110
 
112
111
  /**
@@ -116,8 +115,11 @@ const useActivity = (state, size = "medium") => {
116
115
  * @returns {ReactElement | null } - Activity indicator.
117
116
  */
118
117
  const ActivityIndicator = (props) => {
119
- const { activityIndicator } = useActivity(props.state, props.size);
120
- return activityIndicator ? jsx(Indicator, { ...activityIndicator, ...props }) : null;
118
+ const { activityIndicator } = useActivity(props.state);
119
+ if (!activityIndicator)
120
+ return null;
121
+ const { iconName, ...indicatorProps } = activityIndicator;
122
+ return jsx(Indicator, { ...indicatorProps, ...props, icon: jsx(Icon, { name: iconName, size: props.size }) });
121
123
  };
122
124
 
123
125
  /**
@@ -132,7 +134,7 @@ const useUtilization = state => {
132
134
  case UtilizationState.Unused:
133
135
  return {
134
136
  utilizationIndicator: {
135
- icon: jsx(Icon, { name: "ExclamationTriangle", size: "medium" }),
137
+ iconName: "ExclamationTriangle",
136
138
  label: t("indicator.utilization.unused"),
137
139
  color: "unused",
138
140
  },
@@ -140,7 +142,7 @@ const useUtilization = state => {
140
142
  case UtilizationState.Utilized:
141
143
  return {
142
144
  utilizationIndicator: {
143
- icon: jsx(Icon, { name: "CheckCircle", size: "medium" }),
145
+ iconName: "CheckCircle",
144
146
  label: t("indicator.utilization.utilized"),
145
147
  color: "utilized",
146
148
  },
@@ -148,7 +150,7 @@ const useUtilization = state => {
148
150
  case UtilizationState.HeavilyUtilized:
149
151
  return {
150
152
  utilizationIndicator: {
151
- icon: jsx(Icon, { name: "ShieldExclamation", size: "medium" }),
153
+ iconName: "ShieldExclamation",
152
154
  label: t("indicator.utilization.heavilyUtilized"),
153
155
  color: "heavily_utilized",
154
156
  },
@@ -156,7 +158,7 @@ const useUtilization = state => {
156
158
  case UtilizationState.Unknown:
157
159
  return {
158
160
  utilizationIndicator: {
159
- icon: jsx(Icon, { name: "QuestionMarkCircle", size: "medium" }),
161
+ iconName: "QuestionMarkCircle",
160
162
  label: "N/A",
161
163
  color: "unknown_utilization",
162
164
  },
@@ -175,7 +177,10 @@ const useUtilization = state => {
175
177
  */
176
178
  const UtilizationIndicator = (props) => {
177
179
  const { utilizationIndicator } = useUtilization(props.state);
178
- return utilizationIndicator ? jsx(Indicator, { ...utilizationIndicator, ...props }) : null;
180
+ if (!utilizationIndicator)
181
+ return null;
182
+ const { iconName, ...indicatorProps } = utilizationIndicator;
183
+ return jsx(Indicator, { ...indicatorProps, ...props, icon: jsx(Icon, { name: iconName, size: "medium" }) });
179
184
  };
180
185
 
181
186
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/utilization-indicator",
3
- "version": "1.24.7",
3
+ "version": "1.24.8",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,6 +1,6 @@
1
1
  import { CommonProps, IndicatorProps, type Styleable } from "@trackunit/react-components";
2
2
  import { AssetActivityState } from "@trackunit/utilization-tokens";
3
- import { ReactElement } from "react";
3
+ import type { ReactElement } from "react";
4
4
  export interface ActivityIndicatorProps extends Pick<IndicatorProps, "withBackground" | "withLabel" | "ping" | "size" | "weight">, CommonProps, Styleable {
5
5
  state: AssetActivityState;
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import { CommonProps, IndicatorProps, type Styleable } from "@trackunit/react-components";
2
2
  import { UtilizationState } from "@trackunit/utilization-tokens";
3
- import { ReactElement } from "react";
3
+ import type { ReactElement } from "react";
4
4
  export interface UtilizationIndicatorProps extends Pick<IndicatorProps, "withBackground" | "withLabel" | "ping">, CommonProps, Styleable {
5
5
  state: UtilizationState;
6
6
  }
@@ -1,18 +1,19 @@
1
1
  import { ActivityColors } from "@trackunit/ui-design-tokens";
2
2
  import { AssetActivityState } from "@trackunit/utilization-tokens";
3
- import { ReactElement } from "react";
4
- type UseActivity = (state?: AssetActivityState, size?: "small" | "medium" | "large") => {
5
- activityIndicator?: {
6
- icon: ReactElement;
7
- label: string;
8
- color: ActivityColors;
9
- };
3
+ declare const activityIndicatorIconNames: readonly ["PlayCircle", "PauseCircle", "StopCircle", "QuestionMarkCircle"];
4
+ type ActivityIndicatorIconName = (typeof activityIndicatorIconNames)[number];
5
+ type ActivityIndicatorMetadata = Readonly<{
6
+ iconName: ActivityIndicatorIconName;
7
+ label: string;
8
+ color: ActivityColors;
9
+ }>;
10
+ type UseActivity = (state?: AssetActivityState, _size?: "small" | "medium" | "large") => {
11
+ activityIndicator?: ActivityIndicatorMetadata;
10
12
  };
11
13
  /**
12
14
  * Returns the activity indicator props.
13
15
  *
14
16
  * @param state - The activity state.
15
- * @param size - The size of the icon.
16
17
  * @returns {UseActivity} - The activity indicator props.
17
18
  */
18
19
  export declare const useActivity: UseActivity;
@@ -1,12 +1,14 @@
1
1
  import { UtilizationColors } from "@trackunit/ui-design-tokens";
2
2
  import { UtilizationState } from "@trackunit/utilization-tokens";
3
- import { ReactElement } from "react";
3
+ declare const utilizationIndicatorIconNames: readonly ["ExclamationTriangle", "CheckCircle", "ShieldExclamation", "QuestionMarkCircle"];
4
+ type UtilizationIndicatorIconName = (typeof utilizationIndicatorIconNames)[number];
5
+ type UtilizationIndicatorMetadata = Readonly<{
6
+ iconName: UtilizationIndicatorIconName;
7
+ label: string;
8
+ color: UtilizationColors;
9
+ }>;
4
10
  type UseUtilization = (state?: UtilizationState) => {
5
- utilizationIndicator?: {
6
- icon: ReactElement;
7
- label: string;
8
- color: UtilizationColors;
9
- };
11
+ utilizationIndicator?: UtilizationIndicatorMetadata;
10
12
  };
11
13
  /**
12
14
  * Returns the utilization indicator props.