@babylonlabs-io/core-ui 1.35.2 → 1.36.0

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.
@@ -13,16 +13,31 @@ const ICON_COLOR = {
13
13
  warning: "text-warning-main",
14
14
  error: "text-error-main",
15
15
  };
16
- export function Hint({ children, tooltip, status = "default", attachToChildren = false, icon, className, placement = "top", tooltipVariant = "primary", offset = [0, 8], }) {
16
+ export function Hint({ children, tooltip, status = "default", attachToChildren = false, icon, className, placement = "top", tooltipVariant = "primary", offset = [8, 8], }) {
17
17
  const id = useId();
18
18
  const statusColor = STATUS_COLORS[status];
19
19
  // Create custom middleware for horizontal offset
20
20
  const customOffset = {
21
21
  name: 'customOffset',
22
- fn: ({ x, y }) => ({
23
- x: x + offset[0], // horizontal offset
24
- y: y + offset[1], // vertical offset
25
- }),
22
+ fn: ({ x, y, placement }) => {
23
+ let nextX = x;
24
+ let nextY = y;
25
+ // Apply offsets based on placement direction so that positive offsets
26
+ // move the tooltip away from the reference element on the main axis
27
+ if (placement === 'top') {
28
+ nextY = y - offset[1];
29
+ }
30
+ else if (placement === 'bottom') {
31
+ nextY = y + offset[1];
32
+ }
33
+ else if (placement === 'left') {
34
+ nextX = x - offset[0];
35
+ }
36
+ else if (placement === 'right') {
37
+ nextX = x + offset[0];
38
+ }
39
+ return { x: nextX, y: nextY };
40
+ },
26
41
  };
27
42
  if (!tooltip) {
28
43
  // Use an inline wrapper when attaching to children to keep valid inline semantics
@@ -34,5 +49,5 @@ export function Hint({ children, tooltip, status = "default", attachToChildren =
34
49
  // Default icon with proper size and color
35
50
  const defaultIcon = _jsx(InfoIcon, { size: 16, className: ICON_COLOR[status] });
36
51
  const tooltipIcon = icon || defaultIcon;
37
- return (attachToChildren ? (_jsxs("span", { className: twJoin("inline-flex items-center gap-1", statusColor, className), children: [_jsx("span", { className: "cursor-pointer", "data-tooltip-id": id, "data-tooltip-content": typeof tooltip === "string" ? tooltip : undefined, "data-tooltip-place": placement, "data-tooltip-position-strategy": "fixed", "data-tooltip-offset": 0, "data-tooltip-wrapper": "span", children: children }), _jsx(Tooltip, { id: id, className: twJoin("react-tooltip", tooltipVariant === "secondary" && "react-tooltip--secondary"), openOnClick: false, clickable: true, place: placement, style: { zIndex: 99999 }, positionStrategy: "fixed", middlewares: [customOffset], offset: 0, children: typeof tooltip !== "string" && tooltip })] })) : (_jsxs("div", { className: twJoin("inline-flex items-center gap-1", statusColor, className), children: [children, _jsx("span", { className: twJoin("cursor-pointer inline-flex items-center", statusColor), "data-tooltip-id": id, "data-tooltip-content": typeof tooltip === "string" ? tooltip : undefined, "data-tooltip-place": placement, "data-tooltip-position-strategy": "fixed", "data-tooltip-offset": 0, "data-tooltip-wrapper": "span", children: tooltipIcon }), _jsx(Tooltip, { id: id, className: twJoin("react-tooltip", tooltipVariant === "secondary" && "react-tooltip--secondary"), openOnClick: false, clickable: true, place: placement, style: { zIndex: 99999 }, positionStrategy: "fixed", middlewares: [customOffset], offset: 0, children: typeof tooltip !== "string" && tooltip })] })));
52
+ return (attachToChildren ? (_jsxs("span", { className: twJoin("inline-flex items-center gap-1", statusColor, className), children: [_jsx("span", { className: "cursor-pointer", "data-tooltip-id": id, "data-tooltip-content": typeof tooltip === "string" ? tooltip : undefined, "data-tooltip-place": placement, "data-tooltip-position-strategy": "fixed", "data-tooltip-wrapper": "span", children: children }), _jsx(Tooltip, { id: id, className: twJoin("react-tooltip", tooltipVariant === "secondary" && "react-tooltip--secondary"), openOnClick: false, clickable: true, place: placement, style: { zIndex: 99999 }, positionStrategy: "fixed", middlewares: [customOffset], offset: 0, children: typeof tooltip !== "string" && tooltip })] })) : (_jsxs("div", { className: twJoin("inline-flex items-center gap-1", statusColor, className), children: [children, _jsx("span", { className: twJoin("cursor-pointer inline-flex items-center", statusColor), "data-tooltip-id": id, "data-tooltip-content": typeof tooltip === "string" ? tooltip : undefined, "data-tooltip-place": placement, "data-tooltip-position-strategy": "fixed", "data-tooltip-wrapper": "span", children: tooltipIcon }), _jsx(Tooltip, { id: id, className: twJoin("react-tooltip", tooltipVariant === "secondary" && "react-tooltip--secondary"), openOnClick: false, clickable: true, place: placement, style: { zIndex: 99999 }, positionStrategy: "fixed", middlewares: [customOffset], offset: 0, children: typeof tooltip !== "string" && tooltip })] })));
38
53
  }