@trackunit/react-components 0.1.392 → 0.1.394

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
@@ -1037,6 +1037,9 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries })
1037
1037
  setIsRunning(false); // Update the status when stopped
1038
1038
  };
1039
1039
  const startTimeouts = () => {
1040
+ if (isRunning) {
1041
+ return; // Prevent multiple timeouts from running
1042
+ }
1040
1043
  startTimeout();
1041
1044
  setIsRunning(true); // Update the status when started
1042
1045
  };
@@ -1312,55 +1315,29 @@ const useSelfUpdatingRef = (initialState) => {
1312
1315
  return stateRef;
1313
1316
  };
1314
1317
 
1315
- /**
1316
- * Returns a callback that will be called when the visibility state of the document changes.
1317
- */
1318
- const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
1319
- React.useEffect(() => {
1320
- const handleVisibilityChange = () => {
1321
- if (document.visibilityState === targetState) {
1322
- onChange();
1323
- }
1324
- };
1325
- window.addEventListener("visibilitychange", handleVisibilityChange);
1326
- return () => {
1327
- window.removeEventListener("visibilitychange", handleVisibilityChange);
1328
- };
1329
- }, [onChange, targetState]);
1330
- };
1331
-
1332
1318
  const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
1333
1319
  /**
1334
1320
  * Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
1335
1321
  */
1336
- const useWindowActivity = ({ onFocus, onBlur } = {}) => {
1322
+ const useWindowActivity = ({ onFocus, onBlur } = { onBlur: undefined, onFocus: undefined }) => {
1337
1323
  const [focused, setFocused] = React.useState(hasFocus());
1324
+ const onFocusInternal = React.useCallback(() => {
1325
+ setFocused(hasFocus());
1326
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus();
1327
+ }, [onFocus]);
1328
+ const onBlurInternal = React.useCallback(() => {
1329
+ setFocused(hasFocus());
1330
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1331
+ }, [onBlur]);
1338
1332
  React.useEffect(() => {
1339
- const onFocusInternal = () => {
1340
- setFocused(true);
1341
- onFocus === null || onFocus === void 0 ? void 0 : onFocus();
1342
- };
1343
- const onBlurInternal = () => {
1344
- setFocused(false);
1345
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1346
- };
1347
- const handleVisibilityChange = () => {
1348
- if (!document.hasFocus()) {
1349
- onBlurInternal();
1350
- }
1351
- else {
1352
- onFocusInternal();
1353
- }
1354
- };
1355
- window.addEventListener("visibilitychange", handleVisibilityChange);
1356
- window.addEventListener("focus", handleVisibilityChange);
1357
- window.addEventListener("blur", handleVisibilityChange);
1333
+ setFocused(hasFocus()); // Focus for additional renders
1334
+ window.addEventListener("focus", onFocusInternal);
1335
+ window.addEventListener("blur", onBlurInternal);
1358
1336
  return () => {
1359
- window.removeEventListener("visibilitychange", handleVisibilityChange);
1360
- window.removeEventListener("focus", handleVisibilityChange);
1361
- window.removeEventListener("blur", handleVisibilityChange);
1337
+ window.removeEventListener("focus", onFocusInternal);
1338
+ window.removeEventListener("blur", onBlurInternal);
1362
1339
  };
1363
- }, [onBlur, onFocus]);
1340
+ }, [onBlurInternal, onFocusInternal]);
1364
1341
  return { focused };
1365
1342
  };
1366
1343
 
@@ -1819,7 +1796,6 @@ const CopyableText = ({ text, alternativeText, dataTestId, className }) => {
1819
1796
  };
1820
1797
 
1821
1798
  const cvaDialog = cssClassVarianceUtilities.cvaMerge([
1822
- "fixed",
1823
1799
  "z-toast",
1824
1800
  "pointer-events-auto",
1825
1801
  "absolute",
@@ -1906,10 +1882,10 @@ const cvaDialog = cssClassVarianceUtilities.cvaMerge([
1906
1882
  },
1907
1883
  ],
1908
1884
  });
1909
- const cvaDialogContainer = cssClassVarianceUtilities.cvaMerge(["relative", "flex", "h-full", "flex-col", "p-4"]);
1885
+ const cvaDialogContainer = cssClassVarianceUtilities.cvaMerge(["relative", "flex", "h-full", "flex-col"]);
1910
1886
  const cvaSwipeContainer = cssClassVarianceUtilities.cvaMerge(["mb-4", "flex", "items-center", "justify-center", "lg:hidden"]);
1911
1887
  const cvaSwipeIcon = cssClassVarianceUtilities.cvaMerge(["block", "h-1", "w-10", "rounded-full", "bg-gray-400"]);
1912
- const cvaToogleContainer = cssClassVarianceUtilities.cvaMerge(["z-8", "absolute"], {
1888
+ const cvaToogleContainer = cssClassVarianceUtilities.cvaMerge(["z-8", "relative"], {
1913
1889
  variants: {
1914
1890
  position: {
1915
1891
  left: "right-[-24px] top-[calc(50%-24px)]",
@@ -2036,7 +2012,7 @@ const ToogleButton = ({ open, position, onToggle }) => {
2036
2012
  * @param {DrawerProps} props - The props for the MapSidebar component
2037
2013
  * @returns {JSX.Element | null} Drawer component
2038
2014
  */
2039
- const Drawer = ({ open = true, onToggle, onClose, disableOverlay, position = "left", children, dataTestId, }) => {
2015
+ const Drawer = ({ open = true, onToggle, onClose, disableOverlay, position = "left", children, dataTestId, className, dialogClassName, }) => {
2040
2016
  const { width } = useResize();
2041
2017
  const isLargeScreen = width >= 1024;
2042
2018
  const initialSidebarMode = () => {
@@ -2106,11 +2082,12 @@ const Drawer = ({ open = true, onToggle, onClose, disableOverlay, position = "le
2106
2082
  if (!isVisible && !onToggle) {
2107
2083
  return null;
2108
2084
  }
2109
- return (jsxRuntime.jsxs("div", { "data-testid": dataTestId, children: [!disableOverlay ? jsxRuntime.jsx(Overlay, { onClose: onClose, open: isAnimationStart }) : null, jsxRuntime.jsx("div", { ...handlers, className: cvaDialog({
2085
+ return (jsxRuntime.jsxs("div", { className: className, "data-testid": dataTestId, children: [!disableOverlay ? jsxRuntime.jsx(Overlay, { onClose: onClose, open: isAnimationStart }) : null, jsxRuntime.jsx("div", { ...handlers, className: cvaDialog({
2110
2086
  sidebarMode: isLargeScreen ? null : sidebarMode,
2111
2087
  isLargeScreen,
2112
2088
  open: isAnimationStart,
2113
2089
  position,
2090
+ className: dialogClassName,
2114
2091
  }), "data-testid": dataTestId ? `${dataTestId}-container` : undefined, onTransitionEnd: handleAnimationEnd, children: jsxRuntime.jsxs("div", { className: cvaDialogContainer(), children: [jsxRuntime.jsx("div", { className: cvaSwipeContainer(), children: jsxRuntime.jsx("div", { className: cvaSwipeIcon() }) }), isLargeScreen && onToggle ? jsxRuntime.jsx(ToogleButton, { onToggle: onToggle, open: open, position: position }) : null, children] }) })] }));
2115
2092
  };
2116
2093
 
@@ -4945,5 +4922,4 @@ exports.usePrompt = usePrompt;
4945
4922
  exports.useResize = useResize;
4946
4923
  exports.useSelfUpdatingRef = useSelfUpdatingRef;
4947
4924
  exports.useTimeout = useTimeout;
4948
- exports.useVisibilityChange = useVisibilityChange;
4949
4925
  exports.useWindowActivity = useWindowActivity;
package/index.esm.js CHANGED
@@ -1017,6 +1017,9 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries })
1017
1017
  setIsRunning(false); // Update the status when stopped
1018
1018
  };
1019
1019
  const startTimeouts = () => {
1020
+ if (isRunning) {
1021
+ return; // Prevent multiple timeouts from running
1022
+ }
1020
1023
  startTimeout();
1021
1024
  setIsRunning(true); // Update the status when started
1022
1025
  };
@@ -1292,55 +1295,29 @@ const useSelfUpdatingRef = (initialState) => {
1292
1295
  return stateRef;
1293
1296
  };
1294
1297
 
1295
- /**
1296
- * Returns a callback that will be called when the visibility state of the document changes.
1297
- */
1298
- const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
1299
- useEffect(() => {
1300
- const handleVisibilityChange = () => {
1301
- if (document.visibilityState === targetState) {
1302
- onChange();
1303
- }
1304
- };
1305
- window.addEventListener("visibilitychange", handleVisibilityChange);
1306
- return () => {
1307
- window.removeEventListener("visibilitychange", handleVisibilityChange);
1308
- };
1309
- }, [onChange, targetState]);
1310
- };
1311
-
1312
1298
  const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
1313
1299
  /**
1314
1300
  * Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
1315
1301
  */
1316
- const useWindowActivity = ({ onFocus, onBlur } = {}) => {
1302
+ const useWindowActivity = ({ onFocus, onBlur } = { onBlur: undefined, onFocus: undefined }) => {
1317
1303
  const [focused, setFocused] = useState(hasFocus());
1304
+ const onFocusInternal = useCallback(() => {
1305
+ setFocused(hasFocus());
1306
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus();
1307
+ }, [onFocus]);
1308
+ const onBlurInternal = useCallback(() => {
1309
+ setFocused(hasFocus());
1310
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1311
+ }, [onBlur]);
1318
1312
  useEffect(() => {
1319
- const onFocusInternal = () => {
1320
- setFocused(true);
1321
- onFocus === null || onFocus === void 0 ? void 0 : onFocus();
1322
- };
1323
- const onBlurInternal = () => {
1324
- setFocused(false);
1325
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
1326
- };
1327
- const handleVisibilityChange = () => {
1328
- if (!document.hasFocus()) {
1329
- onBlurInternal();
1330
- }
1331
- else {
1332
- onFocusInternal();
1333
- }
1334
- };
1335
- window.addEventListener("visibilitychange", handleVisibilityChange);
1336
- window.addEventListener("focus", handleVisibilityChange);
1337
- window.addEventListener("blur", handleVisibilityChange);
1313
+ setFocused(hasFocus()); // Focus for additional renders
1314
+ window.addEventListener("focus", onFocusInternal);
1315
+ window.addEventListener("blur", onBlurInternal);
1338
1316
  return () => {
1339
- window.removeEventListener("visibilitychange", handleVisibilityChange);
1340
- window.removeEventListener("focus", handleVisibilityChange);
1341
- window.removeEventListener("blur", handleVisibilityChange);
1317
+ window.removeEventListener("focus", onFocusInternal);
1318
+ window.removeEventListener("blur", onBlurInternal);
1342
1319
  };
1343
- }, [onBlur, onFocus]);
1320
+ }, [onBlurInternal, onFocusInternal]);
1344
1321
  return { focused };
1345
1322
  };
1346
1323
 
@@ -1799,7 +1776,6 @@ const CopyableText = ({ text, alternativeText, dataTestId, className }) => {
1799
1776
  };
1800
1777
 
1801
1778
  const cvaDialog = cvaMerge([
1802
- "fixed",
1803
1779
  "z-toast",
1804
1780
  "pointer-events-auto",
1805
1781
  "absolute",
@@ -1886,10 +1862,10 @@ const cvaDialog = cvaMerge([
1886
1862
  },
1887
1863
  ],
1888
1864
  });
1889
- const cvaDialogContainer = cvaMerge(["relative", "flex", "h-full", "flex-col", "p-4"]);
1865
+ const cvaDialogContainer = cvaMerge(["relative", "flex", "h-full", "flex-col"]);
1890
1866
  const cvaSwipeContainer = cvaMerge(["mb-4", "flex", "items-center", "justify-center", "lg:hidden"]);
1891
1867
  const cvaSwipeIcon = cvaMerge(["block", "h-1", "w-10", "rounded-full", "bg-gray-400"]);
1892
- const cvaToogleContainer = cvaMerge(["z-8", "absolute"], {
1868
+ const cvaToogleContainer = cvaMerge(["z-8", "relative"], {
1893
1869
  variants: {
1894
1870
  position: {
1895
1871
  left: "right-[-24px] top-[calc(50%-24px)]",
@@ -2016,7 +1992,7 @@ const ToogleButton = ({ open, position, onToggle }) => {
2016
1992
  * @param {DrawerProps} props - The props for the MapSidebar component
2017
1993
  * @returns {JSX.Element | null} Drawer component
2018
1994
  */
2019
- const Drawer = ({ open = true, onToggle, onClose, disableOverlay, position = "left", children, dataTestId, }) => {
1995
+ const Drawer = ({ open = true, onToggle, onClose, disableOverlay, position = "left", children, dataTestId, className, dialogClassName, }) => {
2020
1996
  const { width } = useResize();
2021
1997
  const isLargeScreen = width >= 1024;
2022
1998
  const initialSidebarMode = () => {
@@ -2086,11 +2062,12 @@ const Drawer = ({ open = true, onToggle, onClose, disableOverlay, position = "le
2086
2062
  if (!isVisible && !onToggle) {
2087
2063
  return null;
2088
2064
  }
2089
- return (jsxs("div", { "data-testid": dataTestId, children: [!disableOverlay ? jsx(Overlay, { onClose: onClose, open: isAnimationStart }) : null, jsx("div", { ...handlers, className: cvaDialog({
2065
+ return (jsxs("div", { className: className, "data-testid": dataTestId, children: [!disableOverlay ? jsx(Overlay, { onClose: onClose, open: isAnimationStart }) : null, jsx("div", { ...handlers, className: cvaDialog({
2090
2066
  sidebarMode: isLargeScreen ? null : sidebarMode,
2091
2067
  isLargeScreen,
2092
2068
  open: isAnimationStart,
2093
2069
  position,
2070
+ className: dialogClassName,
2094
2071
  }), "data-testid": dataTestId ? `${dataTestId}-container` : undefined, onTransitionEnd: handleAnimationEnd, children: jsxs("div", { className: cvaDialogContainer(), children: [jsx("div", { className: cvaSwipeContainer(), children: jsx("div", { className: cvaSwipeIcon() }) }), isLargeScreen && onToggle ? jsx(ToogleButton, { onToggle: onToggle, open: open, position: position }) : null, children] }) })] }));
2095
2072
  };
2096
2073
 
@@ -4829,4 +4806,4 @@ const cvaClickable = cvaMerge([
4829
4806
  },
4830
4807
  });
4831
4808
 
4832
- export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useVisibilityChange, useWindowActivity };
4809
+ export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useWindowActivity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.1.392",
3
+ "version": "0.1.394",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -25,6 +25,7 @@ export interface DrawerProps extends CommonProps {
25
25
  * The child node that will be rendered inside the drawer.
26
26
  */
27
27
  children?: React.ReactNode;
28
+ dialogClassName?: string;
28
29
  }
29
30
  /**
30
31
  * MapSidebar is a sidebar component used with Maps.
@@ -33,4 +34,4 @@ export interface DrawerProps extends CommonProps {
33
34
  * @param {DrawerProps} props - The props for the MapSidebar component
34
35
  * @returns {JSX.Element | null} Drawer component
35
36
  */
36
- export declare const Drawer: ({ open, onToggle, onClose, disableOverlay, position, children, dataTestId, }: DrawerProps) => JSX.Element | null;
37
+ export declare const Drawer: ({ open, onToggle, onClose, disableOverlay, position, children, dataTestId, className, dialogClassName, }: DrawerProps) => JSX.Element | null;
@@ -14,5 +14,4 @@ export * from "./useOptionallyElevatedState";
14
14
  export * from "./useResize";
15
15
  export * from "./useSelfUpdatingRef";
16
16
  export * from "./useTimeout";
17
- export * from "./useVisibilityChange";
18
17
  export * from "./useWindowActivity";
@@ -1,10 +0,0 @@
1
- type VisibilityState = "hidden" | "visible";
2
- interface VisibilityChangeOptions {
3
- onChange: () => void;
4
- targetState: VisibilityState;
5
- }
6
- /**
7
- * Returns a callback that will be called when the visibility state of the document changes.
8
- */
9
- export declare const useVisibilityChange: ({ onChange, targetState }: VisibilityChangeOptions) => void;
10
- export default useVisibilityChange;