@trackunit/react-components 0.5.5 → 0.5.7

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
@@ -12,7 +12,6 @@ var IconSpriteSolid = require('@trackunit/ui-icons/icons-sprite-solid.svg');
12
12
  var stringTs = require('string-ts');
13
13
  var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
14
14
  var reactSlot = require('@radix-ui/react-slot');
15
- var isEqual = require('lodash/isEqual');
16
15
  var usehooksTs = require('usehooks-ts');
17
16
  var reactRouter = require('@tanstack/react-router');
18
17
  var react = require('@floating-ui/react');
@@ -833,7 +832,7 @@ const setLocalStorage = (key, value) => {
833
832
  const validateState = ({ state, schema, onValidationFailed, onValidationSuccessful, defaultState, }) => {
834
833
  try {
835
834
  const parsedState = schema.parse(state);
836
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful();
835
+ onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(parsedState);
837
836
  return parsedState;
838
837
  }
839
838
  catch (error) {
@@ -888,7 +887,7 @@ const usePrevious = (value) => {
888
887
  const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }) => {
889
888
  const prevState = usePrevious(state);
890
889
  React.useEffect(() => {
891
- if (isEqual(prevState, state)) {
890
+ if (JSON.stringify(prevState) === JSON.stringify(state)) {
892
891
  return;
893
892
  }
894
893
  if (schema) {
@@ -902,9 +901,9 @@ const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationF
902
901
  localStorage.removeItem(key);
903
902
  onValidationFailed === null || onValidationFailed === void 0 ? void 0 : onValidationFailed(error);
904
903
  },
905
- onValidationSuccessful: () => {
906
- setLocalStorage(key, state);
907
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful();
904
+ onValidationSuccessful: data => {
905
+ setLocalStorage(key, data);
906
+ onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(data);
908
907
  },
909
908
  });
910
909
  }
@@ -927,7 +926,14 @@ const useLocalStorage = ({ key, defaultState, schema, onValidationFailed, onVali
927
926
  throw new Error("useLocalStorage key may not be falsy");
928
927
  }
929
928
  const [state, setState] = React.useState(initLocalStorageState({ key, defaultState, schema }));
930
- useLocalStorageEffect({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful });
929
+ useLocalStorageEffect({
930
+ key,
931
+ state,
932
+ defaultState,
933
+ schema,
934
+ onValidationFailed,
935
+ onValidationSuccessful,
936
+ });
931
937
  const reset = () => {
932
938
  setState(defaultState);
933
939
  };
@@ -3506,7 +3512,7 @@ const PopoverTrigger = React.forwardRef(function PopoverTrigger({ children, rend
3506
3512
  }
3507
3513
  });
3508
3514
 
3509
- const cvaTooltipFlexContainer = cssClassVarianceUtilities.cvaMerge(["flex"]);
3515
+ const cvaTooltipContainer = cssClassVarianceUtilities.cvaMerge(["flex"]);
3510
3516
  const cvaTooltipIcon = cssClassVarianceUtilities.cvaMerge(["flex", "h-max", "w-fit", "text-slate-300", "transition", "hover:cursor-pointer", "hover:text-slate-400"], {
3511
3517
  variants: {
3512
3518
  color: {
@@ -3529,11 +3535,11 @@ const cvaTooltipPopoverTail = cssClassVarianceUtilities.cvaMerge("", {
3529
3535
  "bottom-start": "bottom-full left-[5%]",
3530
3536
  "bottom-end": "bottom-full right-[5%]",
3531
3537
  left: "left-full top-2/4 mt-[-6px]",
3532
- "left-start": "top-1/4 top-[8%]",
3533
- "left-end": "bottom-1/4 bottom-[8%]",
3538
+ "left-start": "top-[8%]",
3539
+ "left-end": "bottom-[8%]",
3534
3540
  right: "right-full top-2/4 mt-[-6px] ",
3535
- "right-start": "top-1/4 top-[8%]",
3536
- "right-end": "bottom-1/4 bottom-[8%]",
3541
+ "right-start": "top-[8%]",
3542
+ "right-end": "bottom-[8%]",
3537
3543
  },
3538
3544
  mode: {
3539
3545
  light: "fill-white",
@@ -3579,7 +3585,7 @@ const FloatingArrowContainer = ({ arrowRef, mode = "dark", }) => {
3579
3585
  * @param {TooltipProps} props - The props for the Tooltip component
3580
3586
  * @returns {JSX.Element} Tooltip component
3581
3587
  */
3582
- const Tooltip = ({ children, dataTestId = "tool-tip", disabled, className, label, placement = "auto", mode = "dark", iconProps, id, }) => {
3588
+ const Tooltip = ({ children, dataTestId = "tool-tip", disabled, className, childrenWrapperClassName, label, placement = "auto", mode = "dark", iconProps, id, }) => {
3583
3589
  const [isOpen, setIsOpen] = React__namespace.useState(false);
3584
3590
  const arrowRef = React__namespace.useRef(null);
3585
3591
  const { refs, floatingStyles, context } = react.useFloating({
@@ -3592,7 +3598,7 @@ const Tooltip = ({ children, dataTestId = "tool-tip", disabled, className, label
3592
3598
  const { isMounted } = react.useTransitionStatus(context);
3593
3599
  // Please don't try to move this into the component body directly
3594
3600
  // I tried and it caused infinite re-renders some places (for whatever reason)
3595
- const wrappedChildren = (jsxRuntime.jsx("div", { className: cvaTooltipFlexContainer({ className }), "data-testid": dataTestId ? `${dataTestId}-parent` : undefined, children: children }));
3601
+ const wrappedChildren = (jsxRuntime.jsx("div", { className: cvaTooltipContainer({ className: childrenWrapperClassName }), "data-testid": dataTestId ? `${dataTestId}-parent` : undefined, children: children }));
3596
3602
  const openTooltip = React__namespace.useCallback(() => {
3597
3603
  if (disabled) {
3598
3604
  return;
@@ -4645,7 +4651,7 @@ const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false,
4645
4651
  }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4646
4652
  };
4647
4653
  /**
4648
- * Individual TooggleItem to create custom ToggleGroups
4654
+ * Individual ToggleItem to create custom ToggleGroups
4649
4655
  */
4650
4656
  const ToggleItem = ({ title, onClick, disabled = false, isIconOnly = false, iconName, size, className, selected = false, text, tooltip, dataTestId, }) => {
4651
4657
  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 }) }) }));
package/index.esm.js CHANGED
@@ -11,7 +11,6 @@ import IconSpriteSolid from '@trackunit/ui-icons/icons-sprite-solid.svg';
11
11
  import { snakeCase, titleCase } from 'string-ts';
12
12
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
13
13
  import { Slottable, Slot } from '@radix-ui/react-slot';
14
- import isEqual from 'lodash/isEqual';
15
14
  import { useDebounceCallback, useCopyToClipboard } from 'usehooks-ts';
16
15
  import { Link, useBlocker } from '@tanstack/react-router';
17
16
  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';
@@ -813,7 +812,7 @@ const setLocalStorage = (key, value) => {
813
812
  const validateState = ({ state, schema, onValidationFailed, onValidationSuccessful, defaultState, }) => {
814
813
  try {
815
814
  const parsedState = schema.parse(state);
816
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful();
815
+ onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(parsedState);
817
816
  return parsedState;
818
817
  }
819
818
  catch (error) {
@@ -868,7 +867,7 @@ const usePrevious = (value) => {
868
867
  const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }) => {
869
868
  const prevState = usePrevious(state);
870
869
  useEffect(() => {
871
- if (isEqual(prevState, state)) {
870
+ if (JSON.stringify(prevState) === JSON.stringify(state)) {
872
871
  return;
873
872
  }
874
873
  if (schema) {
@@ -882,9 +881,9 @@ const useLocalStorageEffect = ({ key, state, defaultState, schema, onValidationF
882
881
  localStorage.removeItem(key);
883
882
  onValidationFailed === null || onValidationFailed === void 0 ? void 0 : onValidationFailed(error);
884
883
  },
885
- onValidationSuccessful: () => {
886
- setLocalStorage(key, state);
887
- onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful();
884
+ onValidationSuccessful: data => {
885
+ setLocalStorage(key, data);
886
+ onValidationSuccessful === null || onValidationSuccessful === void 0 ? void 0 : onValidationSuccessful(data);
888
887
  },
889
888
  });
890
889
  }
@@ -907,7 +906,14 @@ const useLocalStorage = ({ key, defaultState, schema, onValidationFailed, onVali
907
906
  throw new Error("useLocalStorage key may not be falsy");
908
907
  }
909
908
  const [state, setState] = useState(initLocalStorageState({ key, defaultState, schema }));
910
- useLocalStorageEffect({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful });
909
+ useLocalStorageEffect({
910
+ key,
911
+ state,
912
+ defaultState,
913
+ schema,
914
+ onValidationFailed,
915
+ onValidationSuccessful,
916
+ });
911
917
  const reset = () => {
912
918
  setState(defaultState);
913
919
  };
@@ -3486,7 +3492,7 @@ const PopoverTrigger = forwardRef(function PopoverTrigger({ children, renderButt
3486
3492
  }
3487
3493
  });
3488
3494
 
3489
- const cvaTooltipFlexContainer = cvaMerge(["flex"]);
3495
+ const cvaTooltipContainer = cvaMerge(["flex"]);
3490
3496
  const cvaTooltipIcon = cvaMerge(["flex", "h-max", "w-fit", "text-slate-300", "transition", "hover:cursor-pointer", "hover:text-slate-400"], {
3491
3497
  variants: {
3492
3498
  color: {
@@ -3509,11 +3515,11 @@ const cvaTooltipPopoverTail = cvaMerge("", {
3509
3515
  "bottom-start": "bottom-full left-[5%]",
3510
3516
  "bottom-end": "bottom-full right-[5%]",
3511
3517
  left: "left-full top-2/4 mt-[-6px]",
3512
- "left-start": "top-1/4 top-[8%]",
3513
- "left-end": "bottom-1/4 bottom-[8%]",
3518
+ "left-start": "top-[8%]",
3519
+ "left-end": "bottom-[8%]",
3514
3520
  right: "right-full top-2/4 mt-[-6px] ",
3515
- "right-start": "top-1/4 top-[8%]",
3516
- "right-end": "bottom-1/4 bottom-[8%]",
3521
+ "right-start": "top-[8%]",
3522
+ "right-end": "bottom-[8%]",
3517
3523
  },
3518
3524
  mode: {
3519
3525
  light: "fill-white",
@@ -3559,7 +3565,7 @@ const FloatingArrowContainer = ({ arrowRef, mode = "dark", }) => {
3559
3565
  * @param {TooltipProps} props - The props for the Tooltip component
3560
3566
  * @returns {JSX.Element} Tooltip component
3561
3567
  */
3562
- const Tooltip = ({ children, dataTestId = "tool-tip", disabled, className, label, placement = "auto", mode = "dark", iconProps, id, }) => {
3568
+ const Tooltip = ({ children, dataTestId = "tool-tip", disabled, className, childrenWrapperClassName, label, placement = "auto", mode = "dark", iconProps, id, }) => {
3563
3569
  const [isOpen, setIsOpen] = React.useState(false);
3564
3570
  const arrowRef = React.useRef(null);
3565
3571
  const { refs, floatingStyles, context } = useFloating({
@@ -3572,7 +3578,7 @@ const Tooltip = ({ children, dataTestId = "tool-tip", disabled, className, label
3572
3578
  const { isMounted } = useTransitionStatus(context);
3573
3579
  // Please don't try to move this into the component body directly
3574
3580
  // I tried and it caused infinite re-renders some places (for whatever reason)
3575
- const wrappedChildren = (jsx("div", { className: cvaTooltipFlexContainer({ className }), "data-testid": dataTestId ? `${dataTestId}-parent` : undefined, children: children }));
3581
+ const wrappedChildren = (jsx("div", { className: cvaTooltipContainer({ className: childrenWrapperClassName }), "data-testid": dataTestId ? `${dataTestId}-parent` : undefined, children: children }));
3576
3582
  const openTooltip = React.useCallback(() => {
3577
3583
  if (disabled) {
3578
3584
  return;
@@ -4625,7 +4631,7 @@ const ToggleGroup = ({ list, selected, setSelected, onChange, disabled = false,
4625
4631
  }, selected: selected === item.id, size: size, text: item.text, title: item.title, tooltip: item.tooltip }, item.id))) }));
4626
4632
  };
4627
4633
  /**
4628
- * Individual TooggleItem to create custom ToggleGroups
4634
+ * Individual ToggleItem to create custom ToggleGroups
4629
4635
  */
4630
4636
  const ToggleItem = ({ title, onClick, disabled = false, isIconOnly = false, iconName, size, className, selected = false, text, tooltip, dataTestId, }) => {
4631
4637
  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 }) }) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -71,6 +71,6 @@ export interface ToggleItemProps extends CommonProps, MappedOmit<BasicToggleGrou
71
71
  selected?: boolean;
72
72
  }
73
73
  /**
74
- * Individual TooggleItem to create custom ToggleGroups
74
+ * Individual ToggleItem to create custom ToggleGroups
75
75
  */
76
76
  export declare const ToggleItem: ({ title, onClick, disabled, isIconOnly, iconName, size, className, selected, text, tooltip, dataTestId, }: ToggleItemProps) => import("react/jsx-runtime").JSX.Element;
@@ -28,6 +28,10 @@ export interface TooltipProps extends CommonProps {
28
28
  * The props for setting the icon on this tip.
29
29
  */
30
30
  iconProps?: Omit<IconProps, "type">;
31
+ /**
32
+ * The className to be passed to the children wrapper.
33
+ */
34
+ childrenWrapperClassName?: string;
31
35
  /**
32
36
  * Ihe id of the html element
33
37
  */
@@ -45,4 +49,4 @@ export interface TooltipProps extends CommonProps {
45
49
  * @param {TooltipProps} props - The props for the Tooltip component
46
50
  * @returns {JSX.Element} Tooltip component
47
51
  */
48
- export declare const Tooltip: ({ children, dataTestId, disabled, className, label, placement, mode, iconProps, id, }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
52
+ export declare const Tooltip: ({ children, dataTestId, disabled, className, childrenWrapperClassName, label, placement, mode, iconProps, id, }: TooltipProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- export declare const cvaTooltipFlexContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
1
+ export declare const cvaTooltipContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
2
2
  export declare const cvaTooltipIcon: (props?: ({
3
3
  color?: "light" | "dark" | null | undefined;
4
4
  defaultVariants?: "color" | null | undefined;
@@ -13,7 +13,7 @@ export interface LocalStorageParams<TState> {
13
13
  */
14
14
  schema?: z.Schema<TState>;
15
15
  }
16
- export interface LocalStorageCallbacks {
16
+ export interface LocalStorageCallbacks<TState> {
17
17
  /**
18
18
  * Optional callback function called when validation fails.
19
19
  *
@@ -23,5 +23,5 @@ export interface LocalStorageCallbacks {
23
23
  /**
24
24
  * Optional callback function called when validation succeeds.
25
25
  */
26
- onValidationSuccessful?: () => void;
26
+ onValidationSuccessful?: (data: TState) => void;
27
27
  }
@@ -7,4 +7,4 @@ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
7
7
  * @param {Omit<LocalStorageParams<TState>, "state"> & LocalStorageCallbacks} options - The options for useLocalStorage.
8
8
  * @returns {[TState, Dispatch<SetStateAction<TState>>, () => void]} - A tuple containing the current value, a function to update the value, and a function to remove the value from local storage.
9
9
  */
10
- export declare const useLocalStorage: <TState>({ key, defaultState, schema, onValidationFailed, onValidationSuccessful, }: LocalStorageParams<TState> & LocalStorageCallbacks) => readonly [TState, Dispatch<SetStateAction<TState>>, () => void];
10
+ export declare const useLocalStorage: <TState>({ key, defaultState, schema, onValidationFailed, onValidationSuccessful, }: LocalStorageParams<TState> & LocalStorageCallbacks<TState>) => readonly [TState, Dispatch<SetStateAction<TState>>, () => void];
@@ -6,6 +6,6 @@ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
6
6
  * @template TState - The type of the state variable.
7
7
  * @param {LocalStorageParams<TState> & LocalStorageCallbacks & { state: TState }} params - The parameters for the useLocalStorageEffect hook.
8
8
  */
9
- export declare const useLocalStorageEffect: <TState>({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }: LocalStorageParams<TState> & LocalStorageCallbacks & {
9
+ export declare const useLocalStorageEffect: <TState>({ key, state, defaultState, schema, onValidationFailed, onValidationSuccessful, }: LocalStorageParams<TState> & LocalStorageCallbacks<TState> & {
10
10
  state: TState;
11
11
  }) => void;
@@ -10,4 +10,4 @@ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
10
10
  */
11
11
  export declare const useLocalStorageReducer: <TState, TAction>({ key, defaultState, reducer, schema, onValidationFailed, onValidationSuccessful, }: {
12
12
  reducer: (state: TState, action: TAction) => TState;
13
- } & LocalStorageParams<TState> & LocalStorageCallbacks) => readonly [TState, Dispatch<TAction>];
13
+ } & LocalStorageParams<TState> & LocalStorageCallbacks<TState>) => readonly [TState, Dispatch<TAction>];
@@ -2,7 +2,7 @@ import { LocalStorageCallbacks, LocalStorageParams } from "./types";
2
2
  type ValidateStateOptions<TState> = Required<Pick<LocalStorageParams<TState>, "schema">> & {
3
3
  state: TState;
4
4
  defaultState: TState;
5
- } & LocalStorageCallbacks;
5
+ } & LocalStorageCallbacks<TState>;
6
6
  /**
7
7
  * Validates the state object using a Zod schema.
8
8
  *
@@ -1,16 +0,0 @@
1
- export interface UseContainerProps {
2
- className?: string;
3
- dataTestId?: string;
4
- }
5
- /**
6
- * Utility for common props on containers.
7
- *
8
- * @param {UseContainerProps} ContainerProps - Props for the utility
9
- * @param {string} ContainerProps.className - Optional custom className
10
- * @param {string} ContainerProps.dataTestId - Optional custom data-TestId
11
- * @returns {UseContainerProps} - Object with undefined values removed
12
- */
13
- export declare const useContainerProps: ({ className, dataTestId }: UseContainerProps) => {
14
- className: string | undefined;
15
- "data-testid": string | undefined;
16
- };