@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.cjs.js CHANGED
@@ -51524,7 +51524,13 @@ var Tooltip = function Tooltip(_ref) {
51524
51524
  customTriggerRole = _ref.customTriggerRole,
51525
51525
  _ref$backgroundColor = _ref.backgroundColor,
51526
51526
  backgroundColor = _ref$backgroundColor === void 0 ? WHITE : _ref$backgroundColor;
51527
+ /**
51528
+ * 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.
51529
+ */
51527
51530
  var closeTimeoutRef = React.useRef(null);
51531
+ /**
51532
+ * 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.
51533
+ */
51528
51534
  var containerRef = React.useRef(null);
51529
51535
  var _useState = React.useState(false),
51530
51536
  _useState2 = _slicedToArray(_useState, 2),
@@ -51552,6 +51558,7 @@ var Tooltip = function Tooltip(_ref) {
51552
51558
  };
51553
51559
 
51554
51560
  /**
51561
+ * @function renderTrigger
51555
51562
  * Renders the tooltip trigger element.
51556
51563
  *
51557
51564
  * When `hasCustomTrigger` is true, the provided child element is cloned and
@@ -51576,12 +51583,18 @@ var Tooltip = function Tooltip(_ref) {
51576
51583
  if (hasCustomTrigger && children) {
51577
51584
  var _child$props, _child$props$tabIndex, _child$props2, _child$props3, _child$props4;
51578
51585
  var child = React__default.Children.only(children);
51579
- // Capture the child's existing handlers before overwriting
51586
+ /**
51587
+ * Capture the child's existing handlers before overwriting
51588
+ */
51580
51589
  var _ref2 = (_child$props = child.props) !== null && _child$props !== void 0 ? _child$props : {},
51581
51590
  childOnFocus = _ref2.onFocus,
51582
51591
  childOnBlur = _ref2.onBlur,
51583
51592
  childOnKeyDown = _ref2.onKeyDown,
51584
51593
  childOnTouchStart = _ref2.onTouchStart;
51594
+
51595
+ /**
51596
+ * Clone the child element and add the necessary event handlers
51597
+ */
51585
51598
  return /*#__PURE__*/React__default.cloneElement(child, {
51586
51599
  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,
51587
51600
  style: _objectSpread2({
@@ -51629,6 +51642,12 @@ var Tooltip = function Tooltip(_ref) {
51629
51642
  });
51630
51643
  }
51631
51644
  };
51645
+
51646
+ /**
51647
+ * @function handleMouseEnter
51648
+ * Handles the mouse enter event for the tooltip container.
51649
+ * It clears any existing timeout and opens the tooltip.
51650
+ */
51632
51651
  var handleMouseEnter = function handleMouseEnter() {
51633
51652
  if (closeTimeoutRef.current) {
51634
51653
  clearTimeout(closeTimeoutRef.current);
@@ -51636,13 +51655,22 @@ var Tooltip = function Tooltip(_ref) {
51636
51655
  }
51637
51656
  handleToggleTooltip(true);
51638
51657
  };
51658
+
51659
+ /**
51660
+ * @function handleMouseLeave
51661
+ * Handles the mouse leave event for the tooltip container.
51662
+ * It sets a timeout to close the tooltip after 200ms.
51663
+ */
51639
51664
  var handleMouseLeave = function handleMouseLeave() {
51640
51665
  closeTimeoutRef.current = setTimeout(function () {
51641
51666
  handleToggleTooltip(false);
51642
- }, 300);
51667
+ }, 200);
51643
51668
  };
51644
51669
 
51645
- // Touch listener effect
51670
+ /**
51671
+ * Handles the touch start event for the tooltip container.
51672
+ * It closes the tooltip if the touch is outside the container.
51673
+ */
51646
51674
  React.useEffect(function () {
51647
51675
  if (!tooltipOpen) return;
51648
51676
  var handleOutsideTouch = function handleOutsideTouch(e) {
@@ -51656,10 +51684,12 @@ var Tooltip = function Tooltip(_ref) {
51656
51684
  };
51657
51685
  }, [tooltipOpen]);
51658
51686
 
51659
- // Unmount cleanup only
51687
+ /**
51688
+ * Cleans up the timeout when the component unmounts.
51689
+ */
51660
51690
  React.useEffect(function () {
51661
51691
  return function () {
51662
- if (closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51692
+ if (closeTimeoutRef !== null && closeTimeoutRef !== void 0 && closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51663
51693
  };
51664
51694
  }, []);
51665
51695
  return /*#__PURE__*/React__default.createElement(Box, {