@thecb/components 11.11.0-beta.7 → 11.11.0-beta.8

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
@@ -40896,6 +40896,7 @@ var EditableList = function EditableList(_ref) {
40896
40896
  _ref$canAdd = _ref.canAdd,
40897
40897
  canAdd = _ref$canAdd === void 0 ? true : _ref$canAdd,
40898
40898
  addItem = _ref.addItem,
40899
+ addItemDestination = _ref.addItemDestination,
40899
40900
  removeItem = _ref.removeItem,
40900
40901
  editItem = _ref.editItem,
40901
40902
  itemName = _ref.itemName,
@@ -41003,6 +41004,8 @@ var EditableList = function EditableList(_ref) {
41003
41004
  padding: items.length === 0 ? "0" : "1rem 0 0"
41004
41005
  }, /*#__PURE__*/React__default.createElement(Placeholder$1, {
41005
41006
  text: addText,
41007
+ isLink: !!addItemDestination,
41008
+ destination: addItemDestination,
41006
41009
  action: addItem,
41007
41010
  dataQa: "Add " + qaPrefix,
41008
41011
  "aria-label": addText,
@@ -51480,6 +51483,7 @@ var fallbackValues$12 = {
51480
51483
  textColor: textColor$5
51481
51484
  };
51482
51485
 
51486
+ var TOOLTIP_THEME_SOURCE = "Popover";
51483
51487
  var Tooltip = function Tooltip(_ref) {
51484
51488
  var tooltipID = _ref.tooltipID,
51485
51489
  children = _ref.children,
@@ -51517,15 +51521,17 @@ var Tooltip = function Tooltip(_ref) {
51517
51521
  arrowBottom: "-8px",
51518
51522
  arrowLeft: "auto"
51519
51523
  } : _ref$arrowPosition,
51524
+ customTriggerRole = _ref.customTriggerRole,
51520
51525
  _ref$backgroundColor = _ref.backgroundColor,
51521
51526
  backgroundColor = _ref$backgroundColor === void 0 ? WHITE : _ref$backgroundColor;
51522
51527
  var closeTimeoutRef = React.useRef(null);
51528
+ var containerRef = React.useRef(null);
51523
51529
  var _useState = React.useState(false),
51524
51530
  _useState2 = _slicedToArray(_useState, 2),
51525
51531
  tooltipOpen = _useState2[0],
51526
51532
  setTooltipOpen = _useState2[1];
51527
51533
  var themeContext = React.useContext(styled.ThemeContext);
51528
- var themeValues = createThemeValues(themeContext, fallbackValues$12, "Tooltip");
51534
+ var themeValues = createThemeValues(themeContext, fallbackValues$12, TOOLTIP_THEME_SOURCE);
51529
51535
  var top = contentPosition.top,
51530
51536
  right = contentPosition.right,
51531
51537
  bottom = contentPosition.bottom,
@@ -51544,35 +51550,43 @@ var Tooltip = function Tooltip(_ref) {
51544
51550
  handleToggleTooltip(false);
51545
51551
  }
51546
51552
  };
51547
- var handleMouseEnter = function handleMouseEnter() {
51548
- if (closeTimeoutRef.current) {
51549
- clearTimeout(closeTimeoutRef.current);
51550
- closeTimeoutRef.current = null;
51551
- }
51552
- handleToggleTooltip(true);
51553
- };
51554
- var handleMouseLeave = function handleMouseLeave() {
51555
- closeTimeoutRef.current = setTimeout(function () {
51556
- handleToggleTooltip(false);
51557
- }, 300);
51558
- };
51559
- React.useEffect(function () {
51560
- return function () {
51561
- if (closeTimeoutRef.current) {
51562
- clearTimeout(closeTimeoutRef.current);
51563
- }
51564
- };
51565
- }, []);
51553
+
51554
+ /**
51555
+ * Renders the tooltip trigger element.
51556
+ *
51557
+ * When `hasCustomTrigger` is true, the provided child element is cloned and
51558
+ * injected with the event handlers needed to control tooltip visibility:
51559
+ * - onFocus/onBlur: open and close for keyboard users
51560
+ * - onKeyDown: allows Escape to dismiss the tooltip
51561
+ * - onTouchStart: open on tap for touch/mobile users (onFocus is unreliable on touch)
51562
+ *
51563
+ * Mouse interactions (hover) are handled at the container level via
51564
+ * onMouseEnter/onMouseLeave, so they do not need to be injected here.
51565
+ *
51566
+ * Any existing event handlers on the child are preserved and called first,
51567
+ * so the child's own behavior is not overridden.
51568
+ *
51569
+ * When no custom trigger is provided, a default ButtonWithAction is rendered
51570
+ * using `triggerText` and `triggerButtonVariant`.
51571
+ */
51566
51572
  var renderTrigger = function renderTrigger() {
51573
+ if (hasCustomTrigger && !children) {
51574
+ console.warn("Tooltip: children prop is required when hasCustomTrigger is true");
51575
+ }
51567
51576
  if (hasCustomTrigger && children) {
51568
- var _child$props, _child$props2;
51577
+ var _child$props, _child$props$tabIndex, _child$props2, _child$props3, _child$props4;
51569
51578
  var child = React__default.Children.only(children);
51579
+ // Capture the child's existing handlers before overwriting
51570
51580
  var _ref2 = (_child$props = child.props) !== null && _child$props !== void 0 ? _child$props : {},
51571
51581
  childOnFocus = _ref2.onFocus,
51572
51582
  childOnBlur = _ref2.onBlur,
51573
- childOnKeyDown = _ref2.onKeyDown;
51583
+ childOnKeyDown = _ref2.onKeyDown,
51584
+ childOnTouchStart = _ref2.onTouchStart;
51574
51585
  return /*#__PURE__*/React__default.cloneElement(child, {
51575
- "aria-describedby": tooltipID,
51586
+ 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
+ style: _objectSpread2({
51588
+ cursor: "pointer"
51589
+ }, (_child$props3 = child.props) === null || _child$props3 === void 0 ? void 0 : _child$props3.style),
51576
51590
  onFocus: function onFocus(e) {
51577
51591
  childOnFocus === null || childOnFocus === void 0 || childOnFocus(e);
51578
51592
  handleToggleTooltip(true);
@@ -51585,33 +51599,71 @@ var Tooltip = function Tooltip(_ref) {
51585
51599
  childOnKeyDown === null || childOnKeyDown === void 0 || childOnKeyDown(e);
51586
51600
  handleKeyDown(e);
51587
51601
  },
51588
- tabIndex: "0",
51589
- style: _objectSpread2(_objectSpread2({}, (_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : _child$props2.style), {}, {
51590
- cursor: "pointer"
51591
- })
51602
+ onTouchStart: function onTouchStart(e) {
51603
+ childOnTouchStart === null || childOnTouchStart === void 0 || childOnTouchStart(e);
51604
+ handleToggleTooltip(true);
51605
+ },
51606
+ role: customTriggerRole || ((_child$props4 = child.props) === null || _child$props4 === void 0 ? void 0 : _child$props4.role),
51607
+ "aria-describedby": tooltipID,
51608
+ "data-qa": "tooltip-trigger-".concat(tooltipID)
51609
+ });
51610
+ } else {
51611
+ return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
51612
+ action: noop$1,
51613
+ onKeyDown: handleKeyDown,
51614
+ variant: triggerButtonVariant,
51615
+ text: triggerText,
51616
+ tabIndex: 0,
51617
+ ariaDescribedby: tooltipID,
51618
+ onFocus: function onFocus() {
51619
+ return handleToggleTooltip(true);
51620
+ },
51621
+ onBlur: function onBlur() {
51622
+ return handleToggleTooltip(false);
51623
+ },
51624
+ onTouchStart: function onTouchStart() {
51625
+ return handleToggleTooltip(true);
51626
+ },
51627
+ dataQa: "tooltip-trigger-".concat(tooltipID),
51628
+ 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 ")
51592
51629
  });
51593
51630
  }
51594
- return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
51595
- action: noop$1,
51596
- "aria-describedby": tooltipID,
51597
- onKeyDown: handleKeyDown,
51598
- variant: triggerButtonVariant,
51599
- onFocus: function onFocus() {
51600
- return handleToggleTooltip(true);
51601
- },
51602
- onBlur: function onBlur() {
51603
- return handleToggleTooltip(false);
51604
- },
51605
- onTouchStart: function onTouchStart() {
51606
- return handleToggleTooltip(true);
51607
- },
51608
- "data-qa": "tooltip-trigger-".concat(tooltipID),
51609
- text: triggerText,
51610
- tabIndex: "0",
51611
- 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 ")
51612
- });
51613
51631
  };
51632
+ var handleMouseEnter = function handleMouseEnter() {
51633
+ if (closeTimeoutRef.current) {
51634
+ clearTimeout(closeTimeoutRef.current);
51635
+ closeTimeoutRef.current = null;
51636
+ }
51637
+ handleToggleTooltip(true);
51638
+ };
51639
+ var handleMouseLeave = function handleMouseLeave() {
51640
+ closeTimeoutRef.current = setTimeout(function () {
51641
+ handleToggleTooltip(false);
51642
+ }, 300);
51643
+ };
51644
+
51645
+ // Touch listener effect
51646
+ React.useEffect(function () {
51647
+ if (!tooltipOpen) return;
51648
+ var handleOutsideTouch = function handleOutsideTouch(e) {
51649
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
51650
+ setTooltipOpen(false);
51651
+ }
51652
+ };
51653
+ document.addEventListener("touchstart", handleOutsideTouch);
51654
+ return function () {
51655
+ return document.removeEventListener("touchstart", handleOutsideTouch);
51656
+ };
51657
+ }, [tooltipOpen]);
51658
+
51659
+ // Unmount cleanup only
51660
+ React.useEffect(function () {
51661
+ return function () {
51662
+ if (closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
51663
+ };
51664
+ }, []);
51614
51665
  return /*#__PURE__*/React__default.createElement(Box, {
51666
+ ref: containerRef,
51615
51667
  padding: "0",
51616
51668
  extraStyles: "position: relative; ".concat(containerExtraStyles),
51617
51669
  onMouseEnter: handleMouseEnter,
@@ -51629,9 +51681,9 @@ var Tooltip = function Tooltip(_ref) {
51629
51681
  borderRadius: "4px",
51630
51682
  minWidth: minWidth,
51631
51683
  maxWidth: maxWidth
51632
- }, typeof content === "string" ? /*#__PURE__*/React__default.createElement(Text$1, {
51684
+ }, typeof content === "string" && content !== "" ? /*#__PURE__*/React__default.createElement(Text$1, {
51633
51685
  color: themeValues.textColor
51634
- }, content) : content, /*#__PURE__*/React__default.createElement(Box, {
51686
+ }, content) : content !== undefined && content !== null ? content : null, /*#__PURE__*/React__default.createElement(Box, {
51635
51687
  padding: "0",
51636
51688
  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 ")
51637
51689
  })));