@thecb/components 11.11.0-beta.8 → 11.11.0-beta.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/dist/index.esm.js CHANGED
@@ -51516,7 +51516,13 @@ var Tooltip = function Tooltip(_ref) {
51516
51516
  customTriggerRole = _ref.customTriggerRole,
51517
51517
  _ref$backgroundColor = _ref.backgroundColor,
51518
51518
  backgroundColor = _ref$backgroundColor === void 0 ? WHITE : _ref$backgroundColor;
51519
+ /**
51520
+ * closeTimeoutRef is used internally to store a timer ID for delaying tooltip close. It will have a `.current` property (the timer ID) when the effect or event handlers set it.
51521
+ */
51519
51522
  var closeTimeoutRef = useRef(null);
51523
+ /**
51524
+ * containerRef is used to store a reference to the container element. It will have a `.current` property (the container element) when the effect or event handlers set it.
51525
+ */
51520
51526
  var containerRef = useRef(null);
51521
51527
  var _useState = useState(false),
51522
51528
  _useState2 = _slicedToArray(_useState, 2),
@@ -51544,6 +51550,7 @@ var Tooltip = function Tooltip(_ref) {
51544
51550
  };
51545
51551
 
51546
51552
  /**
51553
+ * @function renderTrigger
51547
51554
  * Renders the tooltip trigger element.
51548
51555
  *
51549
51556
  * When `hasCustomTrigger` is true, the provided child element is cloned and
@@ -51568,12 +51575,18 @@ var Tooltip = function Tooltip(_ref) {
51568
51575
  if (hasCustomTrigger && children) {
51569
51576
  var _child$props, _child$props$tabIndex, _child$props2, _child$props3, _child$props4;
51570
51577
  var child = React__default.Children.only(children);
51571
- // Capture the child's existing handlers before overwriting
51578
+ /**
51579
+ * Capture the child's existing handlers before overwriting
51580
+ */
51572
51581
  var _ref2 = (_child$props = child.props) !== null && _child$props !== void 0 ? _child$props : {},
51573
51582
  childOnFocus = _ref2.onFocus,
51574
51583
  childOnBlur = _ref2.onBlur,
51575
51584
  childOnKeyDown = _ref2.onKeyDown,
51576
51585
  childOnTouchStart = _ref2.onTouchStart;
51586
+
51587
+ /**
51588
+ * Clone the child element and add the necessary event handlers
51589
+ */
51577
51590
  return /*#__PURE__*/React__default.cloneElement(child, {
51578
51591
  tabIndex: (_child$props$tabIndex = (_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.tabIndex) !== null && _child$props$tabIndex !== void 0 ? _child$props$tabIndex : 0,
51579
51592
  style: _objectSpread2({
@@ -51621,6 +51634,12 @@ var Tooltip = function Tooltip(_ref) {
51621
51634
  });
51622
51635
  }
51623
51636
  };
51637
+
51638
+ /**
51639
+ * @function handleMouseEnter
51640
+ * Handles the mouse enter event for the tooltip container.
51641
+ * It clears any existing timeout and opens the tooltip.
51642
+ */
51624
51643
  var handleMouseEnter = function handleMouseEnter() {
51625
51644
  if (closeTimeoutRef.current) {
51626
51645
  clearTimeout(closeTimeoutRef.current);
@@ -51628,13 +51647,22 @@ var Tooltip = function Tooltip(_ref) {
51628
51647
  }
51629
51648
  handleToggleTooltip(true);
51630
51649
  };
51650
+
51651
+ /**
51652
+ * @function handleMouseLeave
51653
+ * Handles the mouse leave event for the tooltip container.
51654
+ * It sets a timeout to close the tooltip after 200ms.
51655
+ */
51631
51656
  var handleMouseLeave = function handleMouseLeave() {
51632
51657
  closeTimeoutRef.current = setTimeout(function () {
51633
51658
  handleToggleTooltip(false);
51634
- }, 300);
51659
+ }, 200);
51635
51660
  };
51636
51661
 
51637
- // Touch listener effect
51662
+ /**
51663
+ * Handles the touch start event for the tooltip container.
51664
+ * It closes the tooltip if the touch is outside the container.
51665
+ */
51638
51666
  useEffect$1(function () {
51639
51667
  if (!tooltipOpen) return;
51640
51668
  var handleOutsideTouch = function handleOutsideTouch(e) {
@@ -51648,10 +51676,12 @@ var Tooltip = function Tooltip(_ref) {
51648
51676
  };
51649
51677
  }, [tooltipOpen]);
51650
51678
 
51651
- // Unmount cleanup only
51679
+ /**
51680
+ * Cleans up the timeout when the component unmounts.
51681
+ */
51652
51682
  useEffect$1(function () {
51653
51683
  return function () {
51654
- if (closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51684
+ if (closeTimeoutRef !== null && closeTimeoutRef !== void 0 && closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51655
51685
  };
51656
51686
  }, []);
51657
51687
  return /*#__PURE__*/React__default.createElement(Box, {