@thecb/components 11.11.0-beta.8 → 11.11.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.
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,14 +51583,21 @@ 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,
51600
+ ariaDescribedby: tooltipID,
51587
51601
  style: _objectSpread2({
51588
51602
  cursor: "pointer"
51589
51603
  }, (_child$props3 = child.props) === null || _child$props3 === void 0 ? void 0 : _child$props3.style),
@@ -51614,7 +51628,7 @@ var Tooltip = function Tooltip(_ref) {
51614
51628
  variant: triggerButtonVariant,
51615
51629
  text: triggerText,
51616
51630
  tabIndex: 0,
51617
- ariaDescribedby: tooltipID,
51631
+ "aria-describedby": tooltipID,
51618
51632
  onFocus: function onFocus() {
51619
51633
  return handleToggleTooltip(true);
51620
51634
  },
@@ -51629,6 +51643,12 @@ var Tooltip = function Tooltip(_ref) {
51629
51643
  });
51630
51644
  }
51631
51645
  };
51646
+
51647
+ /**
51648
+ * @function handleMouseEnter
51649
+ * Handles the mouse enter event for the tooltip container.
51650
+ * It clears any existing timeout and opens the tooltip.
51651
+ */
51632
51652
  var handleMouseEnter = function handleMouseEnter() {
51633
51653
  if (closeTimeoutRef.current) {
51634
51654
  clearTimeout(closeTimeoutRef.current);
@@ -51636,13 +51656,22 @@ var Tooltip = function Tooltip(_ref) {
51636
51656
  }
51637
51657
  handleToggleTooltip(true);
51638
51658
  };
51659
+
51660
+ /**
51661
+ * @function handleMouseLeave
51662
+ * Handles the mouse leave event for the tooltip container.
51663
+ * It sets a timeout to close the tooltip after 200ms.
51664
+ */
51639
51665
  var handleMouseLeave = function handleMouseLeave() {
51640
51666
  closeTimeoutRef.current = setTimeout(function () {
51641
51667
  handleToggleTooltip(false);
51642
- }, 300);
51668
+ }, 200);
51643
51669
  };
51644
51670
 
51645
- // Touch listener effect
51671
+ /**
51672
+ * Handles the touch start event for the tooltip container.
51673
+ * It closes the tooltip if the touch is outside the container.
51674
+ */
51646
51675
  React.useEffect(function () {
51647
51676
  if (!tooltipOpen) return;
51648
51677
  var handleOutsideTouch = function handleOutsideTouch(e) {
@@ -51656,10 +51685,12 @@ var Tooltip = function Tooltip(_ref) {
51656
51685
  };
51657
51686
  }, [tooltipOpen]);
51658
51687
 
51659
- // Unmount cleanup only
51688
+ /**
51689
+ * Cleans up the timeout when the component unmounts.
51690
+ */
51660
51691
  React.useEffect(function () {
51661
51692
  return function () {
51662
- if (closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51693
+ if (closeTimeoutRef !== null && closeTimeoutRef !== void 0 && closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51663
51694
  };
51664
51695
  }, []);
51665
51696
  return /*#__PURE__*/React__default.createElement(Box, {