@thecb/components 11.11.0-beta.7 → 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
@@ -40888,6 +40888,7 @@ var EditableList = function EditableList(_ref) {
40888
40888
  _ref$canAdd = _ref.canAdd,
40889
40889
  canAdd = _ref$canAdd === void 0 ? true : _ref$canAdd,
40890
40890
  addItem = _ref.addItem,
40891
+ addItemDestination = _ref.addItemDestination,
40891
40892
  removeItem = _ref.removeItem,
40892
40893
  editItem = _ref.editItem,
40893
40894
  itemName = _ref.itemName,
@@ -40995,6 +40996,8 @@ var EditableList = function EditableList(_ref) {
40995
40996
  padding: items.length === 0 ? "0" : "1rem 0 0"
40996
40997
  }, /*#__PURE__*/React__default.createElement(Placeholder$1, {
40997
40998
  text: addText,
40999
+ isLink: !!addItemDestination,
41000
+ destination: addItemDestination,
40998
41001
  action: addItem,
40999
41002
  dataQa: "Add " + qaPrefix,
41000
41003
  "aria-label": addText,
@@ -51472,6 +51475,7 @@ var fallbackValues$12 = {
51472
51475
  textColor: textColor$5
51473
51476
  };
51474
51477
 
51478
+ var TOOLTIP_THEME_SOURCE = "Popover";
51475
51479
  var Tooltip = function Tooltip(_ref) {
51476
51480
  var tooltipID = _ref.tooltipID,
51477
51481
  children = _ref.children,
@@ -51509,15 +51513,23 @@ var Tooltip = function Tooltip(_ref) {
51509
51513
  arrowBottom: "-8px",
51510
51514
  arrowLeft: "auto"
51511
51515
  } : _ref$arrowPosition,
51516
+ customTriggerRole = _ref.customTriggerRole,
51512
51517
  _ref$backgroundColor = _ref.backgroundColor,
51513
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
+ */
51514
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
+ */
51526
+ var containerRef = useRef(null);
51515
51527
  var _useState = useState(false),
51516
51528
  _useState2 = _slicedToArray(_useState, 2),
51517
51529
  tooltipOpen = _useState2[0],
51518
51530
  setTooltipOpen = _useState2[1];
51519
51531
  var themeContext = useContext(ThemeContext);
51520
- var themeValues = createThemeValues(themeContext, fallbackValues$12, "Tooltip");
51532
+ var themeValues = createThemeValues(themeContext, fallbackValues$12, TOOLTIP_THEME_SOURCE);
51521
51533
  var top = contentPosition.top,
51522
51534
  right = contentPosition.right,
51523
51535
  bottom = contentPosition.bottom,
@@ -51536,35 +51548,50 @@ var Tooltip = function Tooltip(_ref) {
51536
51548
  handleToggleTooltip(false);
51537
51549
  }
51538
51550
  };
51539
- var handleMouseEnter = function handleMouseEnter() {
51540
- if (closeTimeoutRef.current) {
51541
- clearTimeout(closeTimeoutRef.current);
51542
- closeTimeoutRef.current = null;
51543
- }
51544
- handleToggleTooltip(true);
51545
- };
51546
- var handleMouseLeave = function handleMouseLeave() {
51547
- closeTimeoutRef.current = setTimeout(function () {
51548
- handleToggleTooltip(false);
51549
- }, 300);
51550
- };
51551
- useEffect$1(function () {
51552
- return function () {
51553
- if (closeTimeoutRef.current) {
51554
- clearTimeout(closeTimeoutRef.current);
51555
- }
51556
- };
51557
- }, []);
51551
+
51552
+ /**
51553
+ * @function renderTrigger
51554
+ * Renders the tooltip trigger element.
51555
+ *
51556
+ * When `hasCustomTrigger` is true, the provided child element is cloned and
51557
+ * injected with the event handlers needed to control tooltip visibility:
51558
+ * - onFocus/onBlur: open and close for keyboard users
51559
+ * - onKeyDown: allows Escape to dismiss the tooltip
51560
+ * - onTouchStart: open on tap for touch/mobile users (onFocus is unreliable on touch)
51561
+ *
51562
+ * Mouse interactions (hover) are handled at the container level via
51563
+ * onMouseEnter/onMouseLeave, so they do not need to be injected here.
51564
+ *
51565
+ * Any existing event handlers on the child are preserved and called first,
51566
+ * so the child's own behavior is not overridden.
51567
+ *
51568
+ * When no custom trigger is provided, a default ButtonWithAction is rendered
51569
+ * using `triggerText` and `triggerButtonVariant`.
51570
+ */
51558
51571
  var renderTrigger = function renderTrigger() {
51572
+ if (hasCustomTrigger && !children) {
51573
+ console.warn("Tooltip: children prop is required when hasCustomTrigger is true");
51574
+ }
51559
51575
  if (hasCustomTrigger && children) {
51560
- var _child$props, _child$props2;
51576
+ var _child$props, _child$props$tabIndex, _child$props2, _child$props3, _child$props4;
51561
51577
  var child = React__default.Children.only(children);
51578
+ /**
51579
+ * Capture the child's existing handlers before overwriting
51580
+ */
51562
51581
  var _ref2 = (_child$props = child.props) !== null && _child$props !== void 0 ? _child$props : {},
51563
51582
  childOnFocus = _ref2.onFocus,
51564
51583
  childOnBlur = _ref2.onBlur,
51565
- childOnKeyDown = _ref2.onKeyDown;
51584
+ childOnKeyDown = _ref2.onKeyDown,
51585
+ childOnTouchStart = _ref2.onTouchStart;
51586
+
51587
+ /**
51588
+ * Clone the child element and add the necessary event handlers
51589
+ */
51566
51590
  return /*#__PURE__*/React__default.cloneElement(child, {
51567
- "aria-describedby": tooltipID,
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,
51592
+ style: _objectSpread2({
51593
+ cursor: "pointer"
51594
+ }, (_child$props3 = child.props) === null || _child$props3 === void 0 ? void 0 : _child$props3.style),
51568
51595
  onFocus: function onFocus(e) {
51569
51596
  childOnFocus === null || childOnFocus === void 0 || childOnFocus(e);
51570
51597
  handleToggleTooltip(true);
@@ -51577,33 +51604,88 @@ var Tooltip = function Tooltip(_ref) {
51577
51604
  childOnKeyDown === null || childOnKeyDown === void 0 || childOnKeyDown(e);
51578
51605
  handleKeyDown(e);
51579
51606
  },
51580
- tabIndex: "0",
51581
- style: _objectSpread2(_objectSpread2({}, (_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.style), {}, {
51582
- cursor: "pointer"
51583
- })
51607
+ onTouchStart: function onTouchStart(e) {
51608
+ childOnTouchStart === null || childOnTouchStart === void 0 || childOnTouchStart(e);
51609
+ handleToggleTooltip(true);
51610
+ },
51611
+ role: customTriggerRole || ((_child$props4 = child.props) === null || _child$props4 === void 0 ? void 0 : _child$props4.role),
51612
+ "aria-describedby": tooltipID,
51613
+ "data-qa": "tooltip-trigger-".concat(tooltipID)
51614
+ });
51615
+ } else {
51616
+ return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
51617
+ action: noop$1,
51618
+ onKeyDown: handleKeyDown,
51619
+ variant: triggerButtonVariant,
51620
+ text: triggerText,
51621
+ tabIndex: 0,
51622
+ ariaDescribedby: tooltipID,
51623
+ onFocus: function onFocus() {
51624
+ return handleToggleTooltip(true);
51625
+ },
51626
+ onBlur: function onBlur() {
51627
+ return handleToggleTooltip(false);
51628
+ },
51629
+ onTouchStart: function onTouchStart() {
51630
+ return handleToggleTooltip(true);
51631
+ },
51632
+ dataQa: "tooltip-trigger-".concat(tooltipID),
51633
+ extraStyles: "\n color: ".concat(themeValues.linkColor, ";\n &:hover { color: ").concat(themeValues.hoverColor, "; text-decoration: none;}\n &:active, &:focus { color: ").concat(themeValues.activeColor, ";text-decoration: none;}\n button, span, &:hover span { text-decoration: none; }\n ")
51584
51634
  });
51585
51635
  }
51586
- return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
51587
- action: noop$1,
51588
- "aria-describedby": tooltipID,
51589
- onKeyDown: handleKeyDown,
51590
- variant: triggerButtonVariant,
51591
- onFocus: function onFocus() {
51592
- return handleToggleTooltip(true);
51593
- },
51594
- onBlur: function onBlur() {
51595
- return handleToggleTooltip(false);
51596
- },
51597
- onTouchStart: function onTouchStart() {
51598
- return handleToggleTooltip(true);
51599
- },
51600
- "data-qa": "tooltip-trigger-".concat(tooltipID),
51601
- text: triggerText,
51602
- tabIndex: "0",
51603
- extraStyles: "\n color: ".concat(themeValues.linkColor, ";\n &:hover { color: ").concat(themeValues.hoverColor, "; text-decoration: none;}\n &:active, &:focus { color: ").concat(themeValues.activeColor, ";text-decoration: none;}\n button, span, &:hover span { text-decoration: none; }\n ")
51604
- });
51605
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
+ */
51643
+ var handleMouseEnter = function handleMouseEnter() {
51644
+ if (closeTimeoutRef.current) {
51645
+ clearTimeout(closeTimeoutRef.current);
51646
+ closeTimeoutRef.current = null;
51647
+ }
51648
+ handleToggleTooltip(true);
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
+ */
51656
+ var handleMouseLeave = function handleMouseLeave() {
51657
+ closeTimeoutRef.current = setTimeout(function () {
51658
+ handleToggleTooltip(false);
51659
+ }, 200);
51660
+ };
51661
+
51662
+ /**
51663
+ * Handles the touch start event for the tooltip container.
51664
+ * It closes the tooltip if the touch is outside the container.
51665
+ */
51666
+ useEffect$1(function () {
51667
+ if (!tooltipOpen) return;
51668
+ var handleOutsideTouch = function handleOutsideTouch(e) {
51669
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
51670
+ setTooltipOpen(false);
51671
+ }
51672
+ };
51673
+ document.addEventListener("touchstart", handleOutsideTouch);
51674
+ return function () {
51675
+ return document.removeEventListener("touchstart", handleOutsideTouch);
51676
+ };
51677
+ }, [tooltipOpen]);
51678
+
51679
+ /**
51680
+ * Cleans up the timeout when the component unmounts.
51681
+ */
51682
+ useEffect$1(function () {
51683
+ return function () {
51684
+ if (closeTimeoutRef !== null && closeTimeoutRef !== void 0 && closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51685
+ };
51686
+ }, []);
51606
51687
  return /*#__PURE__*/React__default.createElement(Box, {
51688
+ ref: containerRef,
51607
51689
  padding: "0",
51608
51690
  extraStyles: "position: relative; ".concat(containerExtraStyles),
51609
51691
  onMouseEnter: handleMouseEnter,
@@ -51621,9 +51703,9 @@ var Tooltip = function Tooltip(_ref) {
51621
51703
  borderRadius: "4px",
51622
51704
  minWidth: minWidth,
51623
51705
  maxWidth: maxWidth
51624
- }, typeof content === "string" ? /*#__PURE__*/React__default.createElement(Text$1, {
51706
+ }, typeof content === "string" && content !== "" ? /*#__PURE__*/React__default.createElement(Text$1, {
51625
51707
  color: themeValues.textColor
51626
- }, content) : content, /*#__PURE__*/React__default.createElement(Box, {
51708
+ }, content) : content !== undefined && content !== null ? content : null, /*#__PURE__*/React__default.createElement(Box, {
51627
51709
  padding: "0",
51628
51710
  extraStyles: "\n position: absolute;\n content: \"\";\n width: 0;\n height: 0;\n ".concat(arrowBorder(backgroundColor, arrowDirection, "8px"), ";\n filter: drop-shadow(2px 8px 14px black);\n bottom: ").concat(arrowBottom, ";\n right: ").concat(arrowRight, ";\n top: ").concat(arrowTop, ";\n left: ").concat(arrowLeft, ";\n ")
51629
51711
  })));