@trackunit/react-components 0.4.12 → 0.4.16

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
@@ -744,13 +744,13 @@ const Alert = ({ color = "info", title, className, children, primaryAction, seco
744
744
  const getIconFromColor = () => {
745
745
  switch (color) {
746
746
  case "danger":
747
- return jsxRuntime.jsx(Icon, { color: "danger", name: "ExclamationTriangle" });
747
+ return jsxRuntime.jsx(Icon, { color: color, name: "ExclamationTriangle" });
748
748
  case "warning":
749
- return jsxRuntime.jsx(Icon, { color: "warning", name: "ExclamationCircle" });
749
+ return jsxRuntime.jsx(Icon, { color: color, name: "ExclamationCircle" });
750
750
  case "success":
751
- return jsxRuntime.jsx(Icon, { color: "success", name: "CheckCircle" });
751
+ return jsxRuntime.jsx(Icon, { color: color, name: "CheckCircle" });
752
752
  case "info":
753
- return jsxRuntime.jsx(Icon, { color: "info", name: "InformationCircle" });
753
+ return jsxRuntime.jsx(Icon, { color: color, name: "InformationCircle" });
754
754
  default:
755
755
  return jsxRuntime.jsx(Icon, { name: "InformationCircle" });
756
756
  }
@@ -803,7 +803,7 @@ const cvaBadge = cssClassVarianceUtilities.cvaMerge([
803
803
  * @param {BadgeProps} props - The props for the Badge component
804
804
  * @returns {JSX.Element} Badge component
805
805
  */
806
- const Badge = ({ color = "primary", className, count, max, hideZero = false, dataTestId, ...rest }) => {
806
+ const Badge = ({ color = "primary", className, count, max, hideZero = false, dataTestId }) => {
807
807
  if (hideZero && count === 0) {
808
808
  return null;
809
809
  }
@@ -1084,7 +1084,7 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries })
1084
1084
  /**
1085
1085
  *
1086
1086
  */
1087
- const useDebounce = (value, delay = 500, direction) => {
1087
+ const useDebounce = (value, delay = 500, direction, onBounce) => {
1088
1088
  const [debouncedValue, setDebouncedValue] = React.useState(value);
1089
1089
  React.useEffect(() => {
1090
1090
  let handler;
@@ -1094,6 +1094,7 @@ const useDebounce = (value, delay = 500, direction) => {
1094
1094
  !direction) {
1095
1095
  handler = setTimeout(() => {
1096
1096
  setDebouncedValue(value);
1097
+ onBounce === null || onBounce === void 0 ? void 0 : onBounce(value);
1097
1098
  }, delay);
1098
1099
  }
1099
1100
  else {
@@ -1102,7 +1103,7 @@ const useDebounce = (value, delay = 500, direction) => {
1102
1103
  return () => {
1103
1104
  clearTimeout(handler);
1104
1105
  };
1105
- }, [value, delay, direction, debouncedValue]);
1106
+ }, [value, delay, direction, debouncedValue, onBounce]);
1106
1107
  return debouncedValue;
1107
1108
  };
1108
1109
 
@@ -1746,7 +1747,9 @@ const cvaCollapseHeader = cssClassVarianceUtilities.cvaMerge([
1746
1747
  "py-1.5",
1747
1748
  "transition-all",
1748
1749
  ], {
1749
- variants: { expanded: { true: ["border-secondary-200", "border-b", "border-solid"], false: "" } },
1750
+ variants: {
1751
+ expanded: { true: ["border-secondary-200", "border-b", "border-solid", "bg-secondary-50"], false: "" },
1752
+ },
1750
1753
  });
1751
1754
  const cvaCollapseLabelContainer = cssClassVarianceUtilities.cvaMerge(["flex", "items-center", "gap-2"]);
1752
1755
  const cvaCollapsible = cssClassVarianceUtilities.cvaMerge(["block", "relative", "p-4"]);
@@ -3612,6 +3615,8 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
3612
3615
  return (jsxRuntime.jsx("a", { className: cvaExternalLink({ className }), "data-testid": dataTestId, href: href, onClick: onClick, rel: rel, target: target, title: title, children: children }));
3613
3616
  };
3614
3617
 
3618
+ const DEFAULT_ACTIVATION = { click: true, hover: false, keyboardHandlers: true };
3619
+ const PADDING = 16;
3615
3620
  /**
3616
3621
  * The hook that powers the Popover component.
3617
3622
  * It should not be used directly, but rather through the Popover component.
@@ -3619,7 +3624,7 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
3619
3624
  * @param {PopoverProps} options The options for the popover
3620
3625
  * @returns {ReturnType<typeof usePopover>} The data for the popover
3621
3626
  */
3622
- const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = { click: true, hover: false }, dismissal, onOpenStateChange, ...restOptions }) => {
3627
+ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal, onOpenStateChange, ...restOptions }) => {
3623
3628
  const [uncontrolledIsOpen, setUncontrolledIsOpen] = React.useState(initialOpen);
3624
3629
  const [labelId, setLabelId] = React.useState();
3625
3630
  const [descriptionId, setDescriptionId] = React.useState();
@@ -3635,21 +3640,28 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
3635
3640
  middleware: [
3636
3641
  react.offset(8),
3637
3642
  react.flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
3638
- react.shift(),
3643
+ react.shift({ padding: PADDING }),
3639
3644
  react.size({
3640
3645
  apply({ availableWidth, availableHeight, elements }) {
3641
3646
  Object.assign(elements.floating.style, {
3642
- maxWidth: `${availableWidth}px`,
3643
- maxHeight: `${availableHeight}px`,
3647
+ maxWidth: `${availableWidth - PADDING}px`,
3648
+ maxHeight: `${availableHeight - PADDING}px`,
3644
3649
  });
3645
3650
  },
3646
3651
  }),
3647
3652
  ],
3648
3653
  });
3649
3654
  const popoverContext = popoverData.context;
3650
- const clickInteraction = react.useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
3655
+ const resolvedActivation = typeof activation === "function" ? activation(DEFAULT_ACTIVATION) : activation;
3656
+ const clickInteraction = react.useClick(popoverContext, {
3657
+ enabled: resolvedActivation.click,
3658
+ ignoreMouse: resolvedActivation.hover,
3659
+ keyboardHandlers: false,
3660
+ });
3651
3661
  const dismissInteraction = react.useDismiss(popoverContext, dismissal);
3652
- const hoverInteraction = react.useHover(popoverContext, { enabled: activation.hover });
3662
+ const hoverInteraction = react.useHover(popoverContext, {
3663
+ enabled: resolvedActivation.hover,
3664
+ });
3653
3665
  const roleInteraction = react.useRole(popoverContext);
3654
3666
  const combinedInteractions = react.useInteractions([
3655
3667
  clickInteraction,
@@ -4065,7 +4077,7 @@ const cvaInteractableItem = cssClassVarianceUtilities.cvaMerge("", {
4065
4077
  },
4066
4078
  });
4067
4079
 
4068
- const cvaMenuItemStyle = cssClassVarianceUtilities.cvaMerge(["py-2", "pl-2", "pr-3", "w-full", "h-auto", "flex", "flex-row", "items-center", "gap-x-2", "select-none", "rounded"], {
4080
+ const cvaMenuItemStyle = cssClassVarianceUtilities.cvaMerge(["py-2", "px-2", "w-full", "h-auto", "flex", "flex-row", "items-center", "gap-x-2", "select-none", "rounded"], {
4069
4081
  variants: {
4070
4082
  size: {
4071
4083
  small: "py-1",
@@ -4127,8 +4139,8 @@ const MenuItem = ({ className, dataTestId, label, size, children, selected, pref
4127
4139
  const cvaMenuList = cssClassVarianceUtilities.cvaMerge(["shadow-md", "rounded-lg", "z-popover", "bg-white", "border", "border-slate-300", "grid"], {
4128
4140
  variants: {
4129
4141
  stickyHeader: {
4130
- true: "grid-rows-min-fr grid overflow-y-hidden p-0",
4131
- false: "p-1",
4142
+ true: "grid-rows-min-fr grid overflow-y-hidden",
4143
+ false: "",
4132
4144
  },
4133
4145
  },
4134
4146
  });
package/index.esm.js CHANGED
@@ -724,13 +724,13 @@ const Alert = ({ color = "info", title, className, children, primaryAction, seco
724
724
  const getIconFromColor = () => {
725
725
  switch (color) {
726
726
  case "danger":
727
- return jsx(Icon, { color: "danger", name: "ExclamationTriangle" });
727
+ return jsx(Icon, { color: color, name: "ExclamationTriangle" });
728
728
  case "warning":
729
- return jsx(Icon, { color: "warning", name: "ExclamationCircle" });
729
+ return jsx(Icon, { color: color, name: "ExclamationCircle" });
730
730
  case "success":
731
- return jsx(Icon, { color: "success", name: "CheckCircle" });
731
+ return jsx(Icon, { color: color, name: "CheckCircle" });
732
732
  case "info":
733
- return jsx(Icon, { color: "info", name: "InformationCircle" });
733
+ return jsx(Icon, { color: color, name: "InformationCircle" });
734
734
  default:
735
735
  return jsx(Icon, { name: "InformationCircle" });
736
736
  }
@@ -783,7 +783,7 @@ const cvaBadge = cvaMerge([
783
783
  * @param {BadgeProps} props - The props for the Badge component
784
784
  * @returns {JSX.Element} Badge component
785
785
  */
786
- const Badge = ({ color = "primary", className, count, max, hideZero = false, dataTestId, ...rest }) => {
786
+ const Badge = ({ color = "primary", className, count, max, hideZero = false, dataTestId }) => {
787
787
  if (hideZero && count === 0) {
788
788
  return null;
789
789
  }
@@ -1064,7 +1064,7 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries })
1064
1064
  /**
1065
1065
  *
1066
1066
  */
1067
- const useDebounce = (value, delay = 500, direction) => {
1067
+ const useDebounce = (value, delay = 500, direction, onBounce) => {
1068
1068
  const [debouncedValue, setDebouncedValue] = useState(value);
1069
1069
  useEffect(() => {
1070
1070
  let handler;
@@ -1074,6 +1074,7 @@ const useDebounce = (value, delay = 500, direction) => {
1074
1074
  !direction) {
1075
1075
  handler = setTimeout(() => {
1076
1076
  setDebouncedValue(value);
1077
+ onBounce === null || onBounce === void 0 ? void 0 : onBounce(value);
1077
1078
  }, delay);
1078
1079
  }
1079
1080
  else {
@@ -1082,7 +1083,7 @@ const useDebounce = (value, delay = 500, direction) => {
1082
1083
  return () => {
1083
1084
  clearTimeout(handler);
1084
1085
  };
1085
- }, [value, delay, direction, debouncedValue]);
1086
+ }, [value, delay, direction, debouncedValue, onBounce]);
1086
1087
  return debouncedValue;
1087
1088
  };
1088
1089
 
@@ -1726,7 +1727,9 @@ const cvaCollapseHeader = cvaMerge([
1726
1727
  "py-1.5",
1727
1728
  "transition-all",
1728
1729
  ], {
1729
- variants: { expanded: { true: ["border-secondary-200", "border-b", "border-solid"], false: "" } },
1730
+ variants: {
1731
+ expanded: { true: ["border-secondary-200", "border-b", "border-solid", "bg-secondary-50"], false: "" },
1732
+ },
1730
1733
  });
1731
1734
  const cvaCollapseLabelContainer = cvaMerge(["flex", "items-center", "gap-2"]);
1732
1735
  const cvaCollapsible = cvaMerge(["block", "relative", "p-4"]);
@@ -3592,6 +3595,8 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
3592
3595
  return (jsx("a", { className: cvaExternalLink({ className }), "data-testid": dataTestId, href: href, onClick: onClick, rel: rel, target: target, title: title, children: children }));
3593
3596
  };
3594
3597
 
3598
+ const DEFAULT_ACTIVATION = { click: true, hover: false, keyboardHandlers: true };
3599
+ const PADDING = 16;
3595
3600
  /**
3596
3601
  * The hook that powers the Popover component.
3597
3602
  * It should not be used directly, but rather through the Popover component.
@@ -3599,7 +3604,7 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
3599
3604
  * @param {PopoverProps} options The options for the popover
3600
3605
  * @returns {ReturnType<typeof usePopover>} The data for the popover
3601
3606
  */
3602
- const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = { click: true, hover: false }, dismissal, onOpenStateChange, ...restOptions }) => {
3607
+ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal, onOpenStateChange, ...restOptions }) => {
3603
3608
  const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(initialOpen);
3604
3609
  const [labelId, setLabelId] = useState();
3605
3610
  const [descriptionId, setDescriptionId] = useState();
@@ -3615,21 +3620,28 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
3615
3620
  middleware: [
3616
3621
  offset(8),
3617
3622
  flip({ fallbackPlacements: ["top", "bottom", "right", "left"] }),
3618
- shift(),
3623
+ shift({ padding: PADDING }),
3619
3624
  size({
3620
3625
  apply({ availableWidth, availableHeight, elements }) {
3621
3626
  Object.assign(elements.floating.style, {
3622
- maxWidth: `${availableWidth}px`,
3623
- maxHeight: `${availableHeight}px`,
3627
+ maxWidth: `${availableWidth - PADDING}px`,
3628
+ maxHeight: `${availableHeight - PADDING}px`,
3624
3629
  });
3625
3630
  },
3626
3631
  }),
3627
3632
  ],
3628
3633
  });
3629
3634
  const popoverContext = popoverData.context;
3630
- const clickInteraction = useClick(popoverContext, { enabled: activation.click, ignoreMouse: activation.hover });
3635
+ const resolvedActivation = typeof activation === "function" ? activation(DEFAULT_ACTIVATION) : activation;
3636
+ const clickInteraction = useClick(popoverContext, {
3637
+ enabled: resolvedActivation.click,
3638
+ ignoreMouse: resolvedActivation.hover,
3639
+ keyboardHandlers: false,
3640
+ });
3631
3641
  const dismissInteraction = useDismiss(popoverContext, dismissal);
3632
- const hoverInteraction = useHover$1(popoverContext, { enabled: activation.hover });
3642
+ const hoverInteraction = useHover$1(popoverContext, {
3643
+ enabled: resolvedActivation.hover,
3644
+ });
3633
3645
  const roleInteraction = useRole(popoverContext);
3634
3646
  const combinedInteractions = useInteractions([
3635
3647
  clickInteraction,
@@ -4045,7 +4057,7 @@ const cvaInteractableItem = cvaMerge("", {
4045
4057
  },
4046
4058
  });
4047
4059
 
4048
- const cvaMenuItemStyle = cvaMerge(["py-2", "pl-2", "pr-3", "w-full", "h-auto", "flex", "flex-row", "items-center", "gap-x-2", "select-none", "rounded"], {
4060
+ const cvaMenuItemStyle = cvaMerge(["py-2", "px-2", "w-full", "h-auto", "flex", "flex-row", "items-center", "gap-x-2", "select-none", "rounded"], {
4049
4061
  variants: {
4050
4062
  size: {
4051
4063
  small: "py-1",
@@ -4107,8 +4119,8 @@ const MenuItem = ({ className, dataTestId, label, size, children, selected, pref
4107
4119
  const cvaMenuList = cvaMerge(["shadow-md", "rounded-lg", "z-popover", "bg-white", "border", "border-slate-300", "grid"], {
4108
4120
  variants: {
4109
4121
  stickyHeader: {
4110
- true: "grid-rows-min-fr grid overflow-y-hidden p-0",
4111
- false: "p-1",
4122
+ true: "grid-rows-min-fr grid overflow-y-hidden",
4123
+ false: "",
4112
4124
  },
4113
4125
  },
4114
4126
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.4.12",
3
+ "version": "0.4.16",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -7,8 +7,4 @@ export interface CommonProps {
7
7
  * A id that can be used in tests to get the component
8
8
  */
9
9
  dataTestId?: string;
10
- /**
11
- * Ihe id of the html element
12
- */
13
- id?: string;
14
10
  }
@@ -25,10 +25,6 @@ interface BaseBadgeProps extends CommonProps {
25
25
  * If enabled the badge is shown even if the count is 0.
26
26
  */
27
27
  hideZero?: boolean;
28
- /**
29
- * Child nodes.
30
- */
31
- children?: React.ReactNode;
32
28
  }
33
29
  export type BadgeProps = BaseBadgeProps;
34
30
  /**
@@ -37,5 +33,5 @@ export type BadgeProps = BaseBadgeProps;
37
33
  * @param {BadgeProps} props - The props for the Badge component
38
34
  * @returns {JSX.Element} Badge component
39
35
  */
40
- export declare const Badge: ({ color, className, count, max, hideZero, dataTestId, ...rest }: BadgeProps) => import("react/jsx-runtime").JSX.Element | null;
36
+ export declare const Badge: ({ color, className, count, max, hideZero, dataTestId }: BadgeProps) => import("react/jsx-runtime").JSX.Element | null;
41
37
  export {};
@@ -3,6 +3,7 @@ import { CommonProps } from "../../common";
3
3
  export type PopoverActivation = {
4
4
  click?: boolean;
5
5
  hover?: boolean;
6
+ keyboardHandlers?: boolean;
6
7
  };
7
8
  export type PopoverDismissal = Pick<UseDismissProps, "ancestorScroll" | "enabled" | "outsidePress" | "referencePress">;
8
9
  export type PopoverPlacement = "top" | "right" | "bottom" | "left" | "top-start" | "top-end" | "right-start" | "right-end" | "bottom-start" | "bottom-end" | "left-start" | "left-end";
@@ -27,7 +28,7 @@ export interface PopoverProps extends CommonProps {
27
28
  /**
28
29
  * Options for activation of the popover
29
30
  */
30
- activation?: PopoverActivation;
31
+ activation?: PopoverActivation | ((defaultActivation: PopoverActivation) => PopoverActivation);
31
32
  /**
32
33
  * Options for dismissal of the popover
33
34
  */
@@ -36,6 +37,10 @@ export interface PopoverProps extends CommonProps {
36
37
  * Callback to be called when the popover open state changes
37
38
  */
38
39
  onOpenStateChange?: (open: boolean) => void;
40
+ /**
41
+ * Ihe id of the html element
42
+ */
43
+ id?: string;
39
44
  }
40
45
  export type FloatingType = Omit<UseFloatingReturn, "middlewareData" | "floatingStyles" | "elements" | "refs">;
41
46
  export type ExtendedRefsType = ExtendedRefs<ReferenceType>;
@@ -48,6 +48,10 @@ export interface TextProps extends CommonProps {
48
48
  * Whether text is disabled or not.
49
49
  */
50
50
  disabled?: boolean;
51
+ /**
52
+ * Ihe id of the html element
53
+ */
54
+ id?: string;
51
55
  }
52
56
  /**
53
57
  * The Text component is used to apply Trackunit default typography styles to text.
@@ -29,6 +29,10 @@ export interface TooltipProps extends CommonProps {
29
29
  * The props for setting the icon on this tip.
30
30
  */
31
31
  iconProps?: Omit<IconProps, "type">;
32
+ /**
33
+ * Ihe id of the html element
34
+ */
35
+ id?: string;
32
36
  }
33
37
  /**
34
38
  * Tooltips display additional information upon hover. The information included should be contextual, helpful, and nonessential while providing that extra ability to communicate and give clarity to a user.
@@ -10,4 +10,4 @@ export type DebounceDirection = "in" | "out" | "both";
10
10
  /**
11
11
  *
12
12
  */
13
- export declare const useDebounce: <TValue>(value: TValue, delay?: number, direction?: DebounceDirection) => TValue;
13
+ export declare const useDebounce: <TValue>(value: TValue, delay?: number, direction?: DebounceDirection, onBounce?: (debouncedValue: TValue) => void) => TValue;