@trackunit/react-components 0.4.6 → 0.4.9

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
@@ -14,8 +14,8 @@ var uuid = require('uuid');
14
14
  var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
15
15
  var reactSlot = require('@radix-ui/react-slot');
16
16
  var isEqual = require('lodash/isEqual');
17
- var reactUse = require('react-use');
18
17
  var reactRouter = require('@tanstack/react-router');
18
+ var usehooksTs = require('usehooks-ts');
19
19
  var reactSwipeable = require('react-swipeable');
20
20
  var react = require('@floating-ui/react');
21
21
  var omit = require('lodash/omit');
@@ -865,6 +865,21 @@ const initLocalStorageState = ({ key, defaultState, schema, }) => {
865
865
  return validateState({ state: localStorageItemJSON, defaultState, schema });
866
866
  };
867
867
 
868
+ /**
869
+ * The usePrevious hook is a useful tool for tracking the previous value of a variable in a functional component. This can be particularly handy in scenarios where it is necessary to compare the current value with the previous one, such as triggering actions or rendering based on changes.
870
+ *
871
+ * @example
872
+ * const [color, setColor] = React.useState(getRandomColor());
873
+ const previousColor = usePrevious(color);
874
+ */
875
+ const usePrevious = (value) => {
876
+ const ref = React.useRef();
877
+ React.useEffect(() => {
878
+ ref.current = value;
879
+ }, [value]);
880
+ return ref.current;
881
+ };
882
+
868
883
  /**
869
884
  * Custom hook for synchronizing a state variable with local storage,
870
885
  * with optional schema validation and callbacks.
@@ -873,7 +888,7 @@ const initLocalStorageState = ({ key, defaultState, schema, }) => {
873
888
  * @param {LocalStorageParams<TState> & LocalStorageCallbacks & { state: TState }} params - The parameters for the useLocalStorageEffect hook.
874
889
  */
875
890
  const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }) => {
876
- const prevState = reactUse.usePrevious(state);
891
+ const prevState = usePrevious(state);
877
892
  React.useEffect(() => {
878
893
  if (isEqual(prevState, state)) {
879
894
  return;
@@ -1788,7 +1803,8 @@ const Collapse = ({ id, initialExpanded = false, onToggle, label, children, clas
1788
1803
  return (jsxRuntime.jsxs("div", { className: cvaCollapse({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { "aria-controls": id, "aria-expanded": expanded, className: cvaCollapseHeader({ expanded, className: headerClassName }), onClick: handleClick, role: "button", children: [jsxRuntime.jsxs("div", { className: cvaCollapseLabelContainer(), children: [jsxRuntime.jsx(Icon, { ariaLabelledBy: LABEL_ID, className: cvaChevronIcon({ expanded }), name: "ChevronRight", size: "small" }), jsxRuntime.jsx(Text, { id: LABEL_ID, type: "span", weight: "bold", children: label })] }), headerAddon ? headerAddon : null] }), jsxRuntime.jsx(Collapsible, { expanded: expanded, id: id, children: children })] }));
1789
1804
  };
1790
1805
  const Collapsible = ({ children, expanded, id }) => {
1791
- const [ref, { height }] = reactUse.useMeasure();
1806
+ const ref = React.useRef(null);
1807
+ const { height } = useGeometry(ref);
1792
1808
  return (jsxRuntime.jsx("div", { className: cvaCollapseAnimated({ expanded }), id: id, style: { height: expanded ? height : "0" }, children: jsxRuntime.jsx("div", { ref: ref, children: jsxRuntime.jsx("div", { className: cvaCollapsible(), children: children }) }) }));
1793
1809
  };
1794
1810
 
@@ -1853,7 +1869,7 @@ const CopyableText = ({ text, alternativeText, dataTestId, className }) => {
1853
1869
  var _a;
1854
1870
  const value = (_a = alternativeText !== null && alternativeText !== void 0 ? alternativeText : text) !== null && _a !== void 0 ? _a : "";
1855
1871
  const [animating, setAnimating] = React.useState(false);
1856
- const [, copyToClipboard] = reactUse.useCopyToClipboard();
1872
+ const [, copyToClipboard] = usehooksTs.useCopyToClipboard();
1857
1873
  const handleOnClick = () => {
1858
1874
  copyToClipboard(value);
1859
1875
  setAnimating(true);
@@ -5071,6 +5087,7 @@ exports.useLocalStorageReducer = useLocalStorageReducer;
5071
5087
  exports.useOptionallyElevatedState = useOptionallyElevatedState;
5072
5088
  exports.useOverflowItems = useOverflowItems;
5073
5089
  exports.usePopoverContext = usePopoverContext;
5090
+ exports.usePrevious = usePrevious;
5074
5091
  exports.usePrompt = usePrompt;
5075
5092
  exports.useResize = useResize;
5076
5093
  exports.useSelfUpdatingRef = useSelfUpdatingRef;
package/index.esm.js CHANGED
@@ -13,8 +13,8 @@ import { v4 } from 'uuid';
13
13
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
14
14
  import { Slottable, Slot } from '@radix-ui/react-slot';
15
15
  import isEqual from 'lodash/isEqual';
16
- import { usePrevious, useMeasure, useCopyToClipboard } from 'react-use';
17
16
  import { Link, useBlocker } from '@tanstack/react-router';
17
+ import { useCopyToClipboard } from 'usehooks-ts';
18
18
  import { useSwipeable } from 'react-swipeable';
19
19
  import { useFloating, autoUpdate, offset, flip, shift, size, useClick, useDismiss, useHover as useHover$1, useRole, useInteractions, useMergeRefs, FloatingPortal, FloatingFocusManager, arrow, useTransitionStatus, FloatingArrow } from '@floating-ui/react';
20
20
  import omit from 'lodash/omit';
@@ -845,6 +845,21 @@ const initLocalStorageState = ({ key, defaultState, schema, }) => {
845
845
  return validateState({ state: localStorageItemJSON, defaultState, schema });
846
846
  };
847
847
 
848
+ /**
849
+ * The usePrevious hook is a useful tool for tracking the previous value of a variable in a functional component. This can be particularly handy in scenarios where it is necessary to compare the current value with the previous one, such as triggering actions or rendering based on changes.
850
+ *
851
+ * @example
852
+ * const [color, setColor] = React.useState(getRandomColor());
853
+ const previousColor = usePrevious(color);
854
+ */
855
+ const usePrevious = (value) => {
856
+ const ref = useRef();
857
+ useEffect(() => {
858
+ ref.current = value;
859
+ }, [value]);
860
+ return ref.current;
861
+ };
862
+
848
863
  /**
849
864
  * Custom hook for synchronizing a state variable with local storage,
850
865
  * with optional schema validation and callbacks.
@@ -1768,7 +1783,8 @@ const Collapse = ({ id, initialExpanded = false, onToggle, label, children, clas
1768
1783
  return (jsxs("div", { className: cvaCollapse({ className }), "data-testid": dataTestId, children: [jsxs("div", { "aria-controls": id, "aria-expanded": expanded, className: cvaCollapseHeader({ expanded, className: headerClassName }), onClick: handleClick, role: "button", children: [jsxs("div", { className: cvaCollapseLabelContainer(), children: [jsx(Icon, { ariaLabelledBy: LABEL_ID, className: cvaChevronIcon({ expanded }), name: "ChevronRight", size: "small" }), jsx(Text, { id: LABEL_ID, type: "span", weight: "bold", children: label })] }), headerAddon ? headerAddon : null] }), jsx(Collapsible, { expanded: expanded, id: id, children: children })] }));
1769
1784
  };
1770
1785
  const Collapsible = ({ children, expanded, id }) => {
1771
- const [ref, { height }] = useMeasure();
1786
+ const ref = useRef(null);
1787
+ const { height } = useGeometry(ref);
1772
1788
  return (jsx("div", { className: cvaCollapseAnimated({ expanded }), id: id, style: { height: expanded ? height : "0" }, children: jsx("div", { ref: ref, children: jsx("div", { className: cvaCollapsible(), children: children }) }) }));
1773
1789
  };
1774
1790
 
@@ -4957,4 +4973,4 @@ const cvaClickable = cvaMerge([
4957
4973
  },
4958
4974
  });
4959
4975
 
4960
- 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, Polygon, 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, cvaInteractableItem, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useViewportSize, useWindowActivity };
4976
+ 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, Polygon, 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, cvaInteractableItem, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrevious, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useViewportSize, useWindowActivity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.4.6",
3
+ "version": "0.4.9",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -11,7 +11,7 @@
11
11
  "@radix-ui/react-slot": "^1.0.2",
12
12
  "react": "18.3.1",
13
13
  "@trackunit/css-class-variance-utilities": "*",
14
- "react-use": "^17.4.0",
14
+ "usehooks-ts": "^3.1.0",
15
15
  "date-fns": "^2.30.0",
16
16
  "@radix-ui/react-tabs": "^1.0.4",
17
17
  "@trackunit/ui-icons": "*",
@@ -11,6 +11,7 @@ export * from "./useIsFirstRender";
11
11
  export * from "./useIsFullScreen";
12
12
  export * from "./useIsTextCutOff";
13
13
  export * from "./useOptionallyElevatedState";
14
+ export * from "./usePrevious";
14
15
  export * from "./useResize";
15
16
  export * from "./useSelfUpdatingRef";
16
17
  export * from "./useTimeout";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The usePrevious hook is a useful tool for tracking the previous value of a variable in a functional component. This can be particularly handy in scenarios where it is necessary to compare the current value with the previous one, such as triggering actions or rendering based on changes.
3
+ *
4
+ * @example
5
+ * const [color, setColor] = React.useState(getRandomColor());
6
+ const previousColor = usePrevious(color);
7
+ */
8
+ export declare const usePrevious: <TValue>(value: TValue) => TValue | undefined;