@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.cjs.js +130 -48
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +130 -48
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/editable-list/EditableList.js +3 -0
- package/src/components/molecules/tooltip/Tooltip.js +127 -49
- package/src/components/molecules/tooltip/Tooltip.stories.js +20 -9
- package/src/components/molecules/tooltip/index.d.ts +2 -1
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,23 @@ 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;
|
|
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
|
+
*/
|
|
51522
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
|
+
*/
|
|
51534
|
+
var containerRef = React.useRef(null);
|
|
51523
51535
|
var _useState = React.useState(false),
|
|
51524
51536
|
_useState2 = _slicedToArray(_useState, 2),
|
|
51525
51537
|
tooltipOpen = _useState2[0],
|
|
51526
51538
|
setTooltipOpen = _useState2[1];
|
|
51527
51539
|
var themeContext = React.useContext(styled.ThemeContext);
|
|
51528
|
-
var themeValues = createThemeValues(themeContext, fallbackValues$12,
|
|
51540
|
+
var themeValues = createThemeValues(themeContext, fallbackValues$12, TOOLTIP_THEME_SOURCE);
|
|
51529
51541
|
var top = contentPosition.top,
|
|
51530
51542
|
right = contentPosition.right,
|
|
51531
51543
|
bottom = contentPosition.bottom,
|
|
@@ -51544,35 +51556,50 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
51544
51556
|
handleToggleTooltip(false);
|
|
51545
51557
|
}
|
|
51546
51558
|
};
|
|
51547
|
-
|
|
51548
|
-
|
|
51549
|
-
|
|
51550
|
-
|
|
51551
|
-
|
|
51552
|
-
|
|
51553
|
-
|
|
51554
|
-
|
|
51555
|
-
|
|
51556
|
-
|
|
51557
|
-
|
|
51558
|
-
|
|
51559
|
-
|
|
51560
|
-
|
|
51561
|
-
|
|
51562
|
-
|
|
51563
|
-
|
|
51564
|
-
|
|
51565
|
-
|
|
51559
|
+
|
|
51560
|
+
/**
|
|
51561
|
+
* @function renderTrigger
|
|
51562
|
+
* Renders the tooltip trigger element.
|
|
51563
|
+
*
|
|
51564
|
+
* When `hasCustomTrigger` is true, the provided child element is cloned and
|
|
51565
|
+
* injected with the event handlers needed to control tooltip visibility:
|
|
51566
|
+
* - onFocus/onBlur: open and close for keyboard users
|
|
51567
|
+
* - onKeyDown: allows Escape to dismiss the tooltip
|
|
51568
|
+
* - onTouchStart: open on tap for touch/mobile users (onFocus is unreliable on touch)
|
|
51569
|
+
*
|
|
51570
|
+
* Mouse interactions (hover) are handled at the container level via
|
|
51571
|
+
* onMouseEnter/onMouseLeave, so they do not need to be injected here.
|
|
51572
|
+
*
|
|
51573
|
+
* Any existing event handlers on the child are preserved and called first,
|
|
51574
|
+
* so the child's own behavior is not overridden.
|
|
51575
|
+
*
|
|
51576
|
+
* When no custom trigger is provided, a default ButtonWithAction is rendered
|
|
51577
|
+
* using `triggerText` and `triggerButtonVariant`.
|
|
51578
|
+
*/
|
|
51566
51579
|
var renderTrigger = function renderTrigger() {
|
|
51580
|
+
if (hasCustomTrigger && !children) {
|
|
51581
|
+
console.warn("Tooltip: children prop is required when hasCustomTrigger is true");
|
|
51582
|
+
}
|
|
51567
51583
|
if (hasCustomTrigger && children) {
|
|
51568
|
-
var _child$props, _child$props2;
|
|
51584
|
+
var _child$props, _child$props$tabIndex, _child$props2, _child$props3, _child$props4;
|
|
51569
51585
|
var child = React__default.Children.only(children);
|
|
51586
|
+
/**
|
|
51587
|
+
* Capture the child's existing handlers before overwriting
|
|
51588
|
+
*/
|
|
51570
51589
|
var _ref2 = (_child$props = child.props) !== null && _child$props !== void 0 ? _child$props : {},
|
|
51571
51590
|
childOnFocus = _ref2.onFocus,
|
|
51572
51591
|
childOnBlur = _ref2.onBlur,
|
|
51573
|
-
childOnKeyDown = _ref2.onKeyDown
|
|
51592
|
+
childOnKeyDown = _ref2.onKeyDown,
|
|
51593
|
+
childOnTouchStart = _ref2.onTouchStart;
|
|
51594
|
+
|
|
51595
|
+
/**
|
|
51596
|
+
* Clone the child element and add the necessary event handlers
|
|
51597
|
+
*/
|
|
51574
51598
|
return /*#__PURE__*/React__default.cloneElement(child, {
|
|
51575
|
-
|
|
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
|
+
style: _objectSpread2({
|
|
51601
|
+
cursor: "pointer"
|
|
51602
|
+
}, (_child$props3 = child.props) === null || _child$props3 === void 0 ? void 0 : _child$props3.style),
|
|
51576
51603
|
onFocus: function onFocus(e) {
|
|
51577
51604
|
childOnFocus === null || childOnFocus === void 0 || childOnFocus(e);
|
|
51578
51605
|
handleToggleTooltip(true);
|
|
@@ -51585,33 +51612,88 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
51585
51612
|
childOnKeyDown === null || childOnKeyDown === void 0 || childOnKeyDown(e);
|
|
51586
51613
|
handleKeyDown(e);
|
|
51587
51614
|
},
|
|
51588
|
-
|
|
51589
|
-
|
|
51590
|
-
|
|
51591
|
-
}
|
|
51615
|
+
onTouchStart: function onTouchStart(e) {
|
|
51616
|
+
childOnTouchStart === null || childOnTouchStart === void 0 || childOnTouchStart(e);
|
|
51617
|
+
handleToggleTooltip(true);
|
|
51618
|
+
},
|
|
51619
|
+
role: customTriggerRole || ((_child$props4 = child.props) === null || _child$props4 === void 0 ? void 0 : _child$props4.role),
|
|
51620
|
+
"aria-describedby": tooltipID,
|
|
51621
|
+
"data-qa": "tooltip-trigger-".concat(tooltipID)
|
|
51622
|
+
});
|
|
51623
|
+
} else {
|
|
51624
|
+
return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
|
|
51625
|
+
action: noop$1,
|
|
51626
|
+
onKeyDown: handleKeyDown,
|
|
51627
|
+
variant: triggerButtonVariant,
|
|
51628
|
+
text: triggerText,
|
|
51629
|
+
tabIndex: 0,
|
|
51630
|
+
ariaDescribedby: tooltipID,
|
|
51631
|
+
onFocus: function onFocus() {
|
|
51632
|
+
return handleToggleTooltip(true);
|
|
51633
|
+
},
|
|
51634
|
+
onBlur: function onBlur() {
|
|
51635
|
+
return handleToggleTooltip(false);
|
|
51636
|
+
},
|
|
51637
|
+
onTouchStart: function onTouchStart() {
|
|
51638
|
+
return handleToggleTooltip(true);
|
|
51639
|
+
},
|
|
51640
|
+
dataQa: "tooltip-trigger-".concat(tooltipID),
|
|
51641
|
+
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
51642
|
});
|
|
51593
51643
|
}
|
|
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
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
|
+
*/
|
|
51651
|
+
var handleMouseEnter = function handleMouseEnter() {
|
|
51652
|
+
if (closeTimeoutRef.current) {
|
|
51653
|
+
clearTimeout(closeTimeoutRef.current);
|
|
51654
|
+
closeTimeoutRef.current = null;
|
|
51655
|
+
}
|
|
51656
|
+
handleToggleTooltip(true);
|
|
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
|
+
*/
|
|
51664
|
+
var handleMouseLeave = function handleMouseLeave() {
|
|
51665
|
+
closeTimeoutRef.current = setTimeout(function () {
|
|
51666
|
+
handleToggleTooltip(false);
|
|
51667
|
+
}, 200);
|
|
51668
|
+
};
|
|
51669
|
+
|
|
51670
|
+
/**
|
|
51671
|
+
* Handles the touch start event for the tooltip container.
|
|
51672
|
+
* It closes the tooltip if the touch is outside the container.
|
|
51673
|
+
*/
|
|
51674
|
+
React.useEffect(function () {
|
|
51675
|
+
if (!tooltipOpen) return;
|
|
51676
|
+
var handleOutsideTouch = function handleOutsideTouch(e) {
|
|
51677
|
+
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
|
51678
|
+
setTooltipOpen(false);
|
|
51679
|
+
}
|
|
51680
|
+
};
|
|
51681
|
+
document.addEventListener("touchstart", handleOutsideTouch);
|
|
51682
|
+
return function () {
|
|
51683
|
+
return document.removeEventListener("touchstart", handleOutsideTouch);
|
|
51684
|
+
};
|
|
51685
|
+
}, [tooltipOpen]);
|
|
51686
|
+
|
|
51687
|
+
/**
|
|
51688
|
+
* Cleans up the timeout when the component unmounts.
|
|
51689
|
+
*/
|
|
51690
|
+
React.useEffect(function () {
|
|
51691
|
+
return function () {
|
|
51692
|
+
if (closeTimeoutRef !== null && closeTimeoutRef !== void 0 && closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current);
|
|
51693
|
+
};
|
|
51694
|
+
}, []);
|
|
51614
51695
|
return /*#__PURE__*/React__default.createElement(Box, {
|
|
51696
|
+
ref: containerRef,
|
|
51615
51697
|
padding: "0",
|
|
51616
51698
|
extraStyles: "position: relative; ".concat(containerExtraStyles),
|
|
51617
51699
|
onMouseEnter: handleMouseEnter,
|
|
@@ -51629,9 +51711,9 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
51629
51711
|
borderRadius: "4px",
|
|
51630
51712
|
minWidth: minWidth,
|
|
51631
51713
|
maxWidth: maxWidth
|
|
51632
|
-
}, typeof content === "string" ? /*#__PURE__*/React__default.createElement(Text$1, {
|
|
51714
|
+
}, typeof content === "string" && content !== "" ? /*#__PURE__*/React__default.createElement(Text$1, {
|
|
51633
51715
|
color: themeValues.textColor
|
|
51634
|
-
}, content) : content, /*#__PURE__*/React__default.createElement(Box, {
|
|
51716
|
+
}, content) : content !== undefined && content !== null ? content : null, /*#__PURE__*/React__default.createElement(Box, {
|
|
51635
51717
|
padding: "0",
|
|
51636
51718
|
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
51719
|
})));
|