@trackunit/react-components 0.3.6 → 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 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
- font: "w-[1em]",
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" || size === "medium") {
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: correctIconType === "mini" ? "0 0 20 20" : "0 0 24 24", children: jsxRuntime.jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
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([
@@ -4709,13 +4734,13 @@ const cvaToggleItemText = cssClassVarianceUtilities.cvaMerge(["text-ellipsis", "
4709
4734
  /**
4710
4735
  * Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
4711
4736
  *
4712
- * @param {ToggleGroupProps} props - The props for the ToggleGroup component
4713
- * @returns {JSX.Element} ToggleGroup component
4737
+ * @param {ToggleGroupProps} props - The props for the ToggleGroup component
4738
+ * @returns {JSX.Element} ToggleGroup component
4714
4739
  */
4715
- const ToggleGroup = ({ list, selected, setSelected, onClick, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
4740
+ const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
4716
4741
  return (jsxRuntime.jsx("div", { className: cvaToggleGroup(), "data-testid": dataTestId, children: list.map((item, index) => (jsxRuntime.jsx(ToggleItem, { className: tailwindMerge.twMerge(className, index === 0 ? ["rounded-l-md", "border-l"] : "", index === list.length - 1 ? ["rounded-r-md", "border-r"] : ""), dataTestId: item.dataTestId, disabled: disabled, iconName: item.iconName, isIconOnly: isIconOnly, onClick: () => {
4717
- onClick && onClick();
4718
4742
  setSelected(item.id);
4743
+ onChange === null || onChange === void 0 ? void 0 : onChange(item.id);
4719
4744
  }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4720
4745
  };
4721
4746
  const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
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
- font: "w-[1em]",
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" || size === "medium") {
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: correctIconType === "mini" ? "0 0 20 20" : "0 0 24 24", children: jsx("use", { href: href[correctIconType], ref: useTagRef }) }) }));
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([
@@ -4689,13 +4714,13 @@ const cvaToggleItemText = cvaMerge(["text-ellipsis", "truncate", "flex-grow"], {
4689
4714
  /**
4690
4715
  * Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
4691
4716
  *
4692
- * @param {ToggleGroupProps} props - The props for the ToggleGroup component
4693
- * @returns {JSX.Element} ToggleGroup component
4717
+ * @param {ToggleGroupProps} props - The props for the ToggleGroup component
4718
+ * @returns {JSX.Element} ToggleGroup component
4694
4719
  */
4695
- const ToggleGroup = ({ list, selected, setSelected, onClick, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
4720
+ const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false, size = "medium", isIconOnly = false, className, dataTestId, }) => {
4696
4721
  return (jsx("div", { className: cvaToggleGroup(), "data-testid": dataTestId, children: list.map((item, index) => (jsx(ToggleItem, { className: twMerge(className, index === 0 ? ["rounded-l-md", "border-l"] : "", index === list.length - 1 ? ["rounded-r-md", "border-r"] : ""), dataTestId: item.dataTestId, disabled: disabled, iconName: item.iconName, isIconOnly: isIconOnly, onClick: () => {
4697
- onClick && onClick();
4698
4722
  setSelected(item.id);
4723
+ onChange === null || onChange === void 0 ? void 0 : onChange(item.id);
4699
4724
  }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4700
4725
  };
4701
4726
  const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Type that ensures that if one property is passed, ALL are required.
3
+ *
4
+ * @example
5
+ * AllOrNone<{
6
+ selected?: TSelectedId | null;
7
+ setSelected?: React.Dispatch<React.SetStateAction<TSelectedId | null>>;
8
+ }>
9
+ */
10
+ export type AllOrNone<TProps> = (TProps & Required<TProps>) | {
11
+ [Key in keyof TProps]?: never;
12
+ };
@@ -1,3 +1,4 @@
1
+ export * from "./AllOrNone";
1
2
  export * from "./AriaProps";
2
3
  export * from "./CommonProps";
3
4
  export * from "./Density";
@@ -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 = IconPropsFont | IconPropsSmall | IconPropsMedium | IconPropsLarge;
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 | "font";
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" | "font" | null | undefined;
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;
@@ -1,13 +1,14 @@
1
1
  import { VariantProps } from "@trackunit/css-class-variance-utilities";
2
+ import { MappedOmit } from "@trackunit/shared-utils";
2
3
  import { IconName } from "@trackunit/ui-icons";
3
4
  import { CommonProps } from "../../common/CommonProps";
4
5
  import { TooltipPlacement } from "../Tooltip/Tooltip";
5
6
  import { cvaToggleGroup } from "./ToggleGroup.variants";
6
- export interface BasicToggleGroupListProps {
7
+ export interface BasicToggleGroupListProps<TSelectedId extends string = string> {
7
8
  /**
8
9
  * Used to identify an individual button to be able to highlight the selected one.
9
10
  */
10
- id: string;
11
+ id: TSelectedId;
11
12
  /**
12
13
  * Tooltip's fallback and button's text content.
13
14
  */
@@ -18,8 +19,8 @@ export interface BasicToggleGroupListProps {
18
19
  iconName?: IconName;
19
20
  /**
20
21
  * Due to size of the text, one might need to truncate a button's content or another.
21
- * This behaviour is individual for each button.
22
- * For a button that utilises this feature, the full text can be read on hover.
22
+ * This behavior is individual for each button.
23
+ * For a button that use this feature, the full text can be read on hover.
23
24
  * Truncation should be avoided if possible.
24
25
  */
25
26
  text?: {
@@ -37,14 +38,12 @@ export interface BasicToggleGroupListProps {
37
38
  };
38
39
  dataTestId?: string;
39
40
  }
40
- export interface ToggleGroupProps extends CommonProps, Omit<VariantProps<typeof cvaToggleGroup>, "className"> {
41
- list: BasicToggleGroupListProps[];
42
- selected: string;
43
- setSelected: React.Dispatch<React.SetStateAction<string>>;
41
+ export type ToggleGroupProps<TSelectedId extends string = string> = CommonProps & Omit<VariantProps<typeof cvaToggleGroup>, "className"> & {
42
+ list: readonly BasicToggleGroupListProps<TSelectedId>[];
44
43
  /**
45
- * For when the click event needs to do more than select an id
44
+ * Instead of onClick, we now use onChange to return the selected value
46
45
  */
47
- onClick?: () => void;
46
+ onChange?: (selectedId: TSelectedId) => void;
48
47
  disabled?: boolean;
49
48
  /**
50
49
  * ToggleGroup buttons can be one of two sizes
@@ -54,15 +53,17 @@ export interface ToggleGroupProps extends CommonProps, Omit<VariantProps<typeof
54
53
  * Enable to use toggle buttons with icons only and a tooltip on hover
55
54
  */
56
55
  isIconOnly?: boolean;
57
- }
56
+ selected: TSelectedId;
57
+ setSelected: React.Dispatch<React.SetStateAction<TSelectedId>>;
58
+ };
58
59
  /**
59
60
  * Toggle Group allows users to toggle between two or more closely related options, and immediately apply that selection.
60
61
  *
61
- * @param {ToggleGroupProps} props - The props for the ToggleGroup component
62
- * @returns {JSX.Element} ToggleGroup component
62
+ * @param {ToggleGroupProps} props - The props for the ToggleGroup component
63
+ * @returns {JSX.Element} ToggleGroup component
63
64
  */
64
- export declare const ToggleGroup: ({ list, selected, setSelected, onClick, disabled, size, isIconOnly, className, dataTestId, }: ToggleGroupProps) => import("react/jsx-runtime").JSX.Element;
65
- export interface ToggleItemProps extends CommonProps, Omit<BasicToggleGroupListProps, "id"> {
65
+ export declare const ToggleGroup: <TSelectedId extends string = string>({ list, selected, setSelected, onChange, disabled, size, isIconOnly, className, dataTestId, }: ToggleGroupProps<TSelectedId>) => import("react/jsx-runtime").JSX.Element;
66
+ export interface ToggleItemProps extends CommonProps, MappedOmit<BasicToggleGroupListProps<string>, "id"> {
66
67
  onClick: () => void;
67
68
  disabled: boolean;
68
69
  isIconOnly: boolean;