@trackunit/react-components 0.4.8 → 0.4.10

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);
@@ -4709,7 +4725,7 @@ function defaultHeader(date, showTime) {
4709
4725
  }
4710
4726
 
4711
4727
  const cvaToggleGroup = cssClassVarianceUtilities.cvaMerge(["inline-flex", "divide-x", "divide-slate-300"]);
4712
- const cvaToggleItem = cssClassVarianceUtilities.cvaMerge(["text-slate-600", "rounded-none", "bg-transparent", "flex", "border-x-0"], {
4728
+ const cvaToggleItem = cssClassVarianceUtilities.cvaMerge(["text-slate-600", "rounded-none", "bg-transparent", "flex", "border-x-0", "bg-white"], {
4713
4729
  variants: {
4714
4730
  selected: {
4715
4731
  true: ["bg-slate-200", "hover:bg-slate-200", "text-slate-800"],
@@ -4742,7 +4758,10 @@ const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false,
4742
4758
  onChange === null || onChange === void 0 ? void 0 : onChange(item.id);
4743
4759
  }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4744
4760
  };
4745
- const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
4761
+ /**
4762
+ * Individual TooggleItem to create custom ToggleGroups
4763
+ */
4764
+ const ToggleItem = ({ title, onClick, disabled = false, isIconOnly = false, iconName, size, className, selected = false, text, tooltip, dataTestId, }) => {
4746
4765
  return isIconOnly ? (jsxRuntime.jsx(Tooltip, { label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsxRuntime.jsx(IconButton, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, icon: iconName ? (jsxRuntime.jsx(Icon, { className: selected ? "text-slate-600" : "text-slate-400", name: iconName, size: "small" })) : null, onClick: onClick, size: size, title: iconName, variant: "secondary" }) })) : (jsxRuntime.jsx(Tooltip, { disabled: !(text === null || text === void 0 ? void 0 : text.truncate) && (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) === undefined, label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsxRuntime.jsx(Button, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, onClick: onClick, prefix: iconName ? (jsxRuntime.jsx(Icon, { className: selected ? "text-slate-600" : "text-slate-400", name: iconName, size: "small" })) : null, size: size, variant: "secondary", children: jsxRuntime.jsx("span", { className: cvaToggleItemText({ disabledAndSelected: disabled && selected, maxWidth: text === null || text === void 0 ? void 0 : text.maxWidth }), children: title }) }) }));
4747
4766
  };
4748
4767
 
@@ -5030,6 +5049,7 @@ exports.Text = Text;
5030
5049
  exports.Timeline = Timeline;
5031
5050
  exports.TimelineElement = TimelineElement;
5032
5051
  exports.ToggleGroup = ToggleGroup;
5052
+ exports.ToggleItem = ToggleItem;
5033
5053
  exports.Tooltip = Tooltip;
5034
5054
  exports.ValueBar = ValueBar;
5035
5055
  exports.VirtualizedList = VirtualizedList;
@@ -5071,6 +5091,7 @@ exports.useLocalStorageReducer = useLocalStorageReducer;
5071
5091
  exports.useOptionallyElevatedState = useOptionallyElevatedState;
5072
5092
  exports.useOverflowItems = useOverflowItems;
5073
5093
  exports.usePopoverContext = usePopoverContext;
5094
+ exports.usePrevious = usePrevious;
5074
5095
  exports.usePrompt = usePrompt;
5075
5096
  exports.useResize = useResize;
5076
5097
  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
 
@@ -4689,7 +4705,7 @@ function defaultHeader(date, showTime) {
4689
4705
  }
4690
4706
 
4691
4707
  const cvaToggleGroup = cvaMerge(["inline-flex", "divide-x", "divide-slate-300"]);
4692
- const cvaToggleItem = cvaMerge(["text-slate-600", "rounded-none", "bg-transparent", "flex", "border-x-0"], {
4708
+ const cvaToggleItem = cvaMerge(["text-slate-600", "rounded-none", "bg-transparent", "flex", "border-x-0", "bg-white"], {
4693
4709
  variants: {
4694
4710
  selected: {
4695
4711
  true: ["bg-slate-200", "hover:bg-slate-200", "text-slate-800"],
@@ -4722,7 +4738,10 @@ const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false,
4722
4738
  onChange === null || onChange === void 0 ? void 0 : onChange(item.id);
4723
4739
  }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4724
4740
  };
4725
- const ToggleItem = ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }) => {
4741
+ /**
4742
+ * Individual TooggleItem to create custom ToggleGroups
4743
+ */
4744
+ const ToggleItem = ({ title, onClick, disabled = false, isIconOnly = false, iconName, size, className, selected = false, text, tooltip, dataTestId, }) => {
4726
4745
  return isIconOnly ? (jsx(Tooltip, { label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsx(IconButton, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, icon: iconName ? (jsx(Icon, { className: selected ? "text-slate-600" : "text-slate-400", name: iconName, size: "small" })) : null, onClick: onClick, size: size, title: iconName, variant: "secondary" }) })) : (jsx(Tooltip, { disabled: !(text === null || text === void 0 ? void 0 : text.truncate) && (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) === undefined, label: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.content) || title, placement: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.placement) || "top", children: jsx(Button, { className: cvaToggleItem({ className, selected }), "data-testid": dataTestId, disabled: disabled, onClick: onClick, prefix: iconName ? (jsx(Icon, { className: selected ? "text-slate-600" : "text-slate-400", name: iconName, size: "small" })) : null, size: size, variant: "secondary", children: jsx("span", { className: cvaToggleItemText({ disabledAndSelected: disabled && selected, maxWidth: text === null || text === void 0 ? void 0 : text.maxWidth }), children: title }) }) }));
4727
4746
  };
4728
4747
 
@@ -4957,4 +4976,4 @@ const cvaClickable = cvaMerge([
4957
4976
  },
4958
4977
  });
4959
4978
 
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 };
4979
+ 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, ToggleItem, 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.8",
3
+ "version": "0.4.10",
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": "*",
@@ -65,8 +65,12 @@ export type ToggleGroupProps<TSelectedId extends string = string> = CommonProps
65
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
66
  export interface ToggleItemProps extends CommonProps, MappedOmit<BasicToggleGroupListProps<string>, "id"> {
67
67
  onClick: () => void;
68
- disabled: boolean;
69
- isIconOnly: boolean;
70
- size: "small" | "medium";
71
- selected: boolean;
68
+ disabled?: boolean;
69
+ isIconOnly?: boolean;
70
+ size?: "small" | "medium";
71
+ selected?: boolean;
72
72
  }
73
+ /**
74
+ * Individual TooggleItem to create custom ToggleGroups
75
+ */
76
+ export declare const ToggleItem: ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }: ToggleItemProps) => import("react/jsx-runtime").JSX.Element;
@@ -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;