@deque/cauldron-react 4.1.0-canary.50e983d0 → 4.1.0-canary.a93171df
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/lib/cauldron.css +2 -1
- package/lib/components/Link/index.d.ts +1 -1
- package/lib/components/Tooltip/index.d.ts +1 -1
- package/lib/index.js +48 -57
- package/package.json +1 -1
package/lib/cauldron.css
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
4
4
|
linkRef?: React.Ref<HTMLAnchorElement>;
|
|
5
|
-
variant?: 'button';
|
|
5
|
+
variant?: 'button' | 'button-secondary';
|
|
6
6
|
}
|
|
7
7
|
declare const Link: {
|
|
8
8
|
({ children, linkRef, className, variant, ...other }: LinkProps): JSX.Element;
|
|
@@ -11,7 +11,7 @@ export interface TooltipProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
11
11
|
portal?: React.RefObject<HTMLElement> | HTMLElement;
|
|
12
12
|
hideElementOnHidden?: boolean;
|
|
13
13
|
}
|
|
14
|
-
declare function Tooltip({ id: propId, placement: initialPlacement, children, portal, target, association, variant, show:
|
|
14
|
+
declare function Tooltip({ id: propId, placement: initialPlacement, children, portal, target, association, variant, show: initialShow, hideElementOnHidden, className, ...props }: TooltipProps): React.ReactPortal | null;
|
|
15
15
|
declare namespace Tooltip {
|
|
16
16
|
var displayName: string;
|
|
17
17
|
var propTypes: {
|
package/lib/index.js
CHANGED
|
@@ -1475,15 +1475,14 @@ var fireCustomEvent = function (show, button) {
|
|
|
1475
1475
|
};
|
|
1476
1476
|
function Tooltip(_a) {
|
|
1477
1477
|
var _this = this;
|
|
1478
|
-
var propId = _a.id, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, children = _a.children, portal = _a.portal, target = _a.target, _c = _a.association, association = _c === void 0 ? 'aria-describedby' : _c, _d = _a.variant, variant = _d === void 0 ? 'text' : _d, _e = _a.show,
|
|
1478
|
+
var propId = _a.id, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, children = _a.children, portal = _a.portal, target = _a.target, _c = _a.association, association = _c === void 0 ? 'aria-describedby' : _c, _d = _a.variant, variant = _d === void 0 ? 'text' : _d, _e = _a.show, initialShow = _e === void 0 ? false : _e, _f = _a.hideElementOnHidden, hideElementOnHidden = _f === void 0 ? false : _f, className = _a.className, props = tslib.__rest(_a, ["id", "placement", "children", "portal", "target", "association", "variant", "show", "hideElementOnHidden", "className"]);
|
|
1479
1479
|
var _g = tslib.__read(propId ? [propId] : nextId.useId(1, 'tooltip'), 1), id = _g[0];
|
|
1480
|
-
var
|
|
1481
|
-
var _h = tslib.__read(React.useState(
|
|
1482
|
-
var _j = tslib.__read(React.useState(
|
|
1483
|
-
var _k = tslib.__read(React.useState(null), 2),
|
|
1484
|
-
var _l = tslib.__read(React.useState(null), 2),
|
|
1485
|
-
var _m =
|
|
1486
|
-
var _o = reactPopper.usePopper(targetElement, tooltipElement, {
|
|
1480
|
+
var hideTimeoutRef = React.useRef(null);
|
|
1481
|
+
var _h = tslib.__read(React.useState(!!initialShow), 2), showTooltip = _h[0], setShowTooltip = _h[1];
|
|
1482
|
+
var _j = tslib.__read(React.useState(null), 2), targetElement = _j[0], setTargetElement = _j[1];
|
|
1483
|
+
var _k = tslib.__read(React.useState(null), 2), tooltipElement = _k[0], setTooltipElement = _k[1];
|
|
1484
|
+
var _l = tslib.__read(React.useState(null), 2), arrowElement = _l[0], setArrowElement = _l[1];
|
|
1485
|
+
var _m = reactPopper.usePopper(targetElement, tooltipElement, {
|
|
1487
1486
|
placement: initialPlacement,
|
|
1488
1487
|
modifiers: [
|
|
1489
1488
|
{ name: 'preventOverflow', options: { padding: 8 } },
|
|
@@ -1491,11 +1490,17 @@ function Tooltip(_a) {
|
|
|
1491
1490
|
{ name: 'offset', options: { offset: [0, 8] } },
|
|
1492
1491
|
{ name: 'arrow', options: { padding: 5, element: arrowElement } }
|
|
1493
1492
|
]
|
|
1494
|
-
}), styles =
|
|
1495
|
-
|
|
1493
|
+
}), styles = _m.styles, attributes = _m.attributes, update = _m.update;
|
|
1494
|
+
// Show the tooltip
|
|
1495
|
+
var show = React.useCallback(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
1496
1496
|
return tslib.__generator(this, function (_a) {
|
|
1497
1497
|
switch (_a.label) {
|
|
1498
1498
|
case 0:
|
|
1499
|
+
// Clear the hide timeout if there was one pending
|
|
1500
|
+
if (hideTimeoutRef.current) {
|
|
1501
|
+
clearTimeout(hideTimeoutRef.current);
|
|
1502
|
+
hideTimeoutRef.current = null;
|
|
1503
|
+
}
|
|
1499
1504
|
if (!update) return [3 /*break*/, 2];
|
|
1500
1505
|
return [4 /*yield*/, update()];
|
|
1501
1506
|
case 1:
|
|
@@ -1507,45 +1512,31 @@ function Tooltip(_a) {
|
|
|
1507
1512
|
return [2 /*return*/];
|
|
1508
1513
|
}
|
|
1509
1514
|
});
|
|
1510
|
-
}); }
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1515
|
+
}); }, [
|
|
1516
|
+
targetElement,
|
|
1517
|
+
// update starts off as null
|
|
1518
|
+
update
|
|
1519
|
+
]);
|
|
1520
|
+
// Hide the tooltip
|
|
1521
|
+
var hide = React.useCallback(function () {
|
|
1522
|
+
if (!hideTimeoutRef.current) {
|
|
1523
|
+
hideTimeoutRef.current = setTimeout(function () {
|
|
1524
|
+
hideTimeoutRef.current = null;
|
|
1525
|
+
setShowTooltip(false);
|
|
1526
|
+
fireCustomEvent(false, targetElement);
|
|
1519
1527
|
}, TIP_HIDE_DELAY);
|
|
1520
1528
|
}
|
|
1521
|
-
};
|
|
1522
|
-
|
|
1523
|
-
hovering.current = true;
|
|
1524
|
-
show();
|
|
1525
|
-
};
|
|
1526
|
-
var handleTriggerMouseLeave = function (e) {
|
|
1527
|
-
hovering.current = false;
|
|
1528
|
-
hide(e);
|
|
1529
|
-
};
|
|
1530
|
-
var handleTipMouseEnter = function () {
|
|
1531
|
-
hovering.current = true;
|
|
1532
|
-
};
|
|
1533
|
-
var handleTipMouseLeave = function (e) {
|
|
1534
|
-
hovering.current = false;
|
|
1535
|
-
hide(e);
|
|
1536
|
-
};
|
|
1529
|
+
}, [targetElement]);
|
|
1530
|
+
// Keep targetElement in sync with target prop
|
|
1537
1531
|
React.useEffect(function () {
|
|
1538
1532
|
var targetElement = target && 'current' in target ? target.current : target;
|
|
1539
1533
|
setTargetElement(targetElement);
|
|
1540
1534
|
}, [target]);
|
|
1541
|
-
|
|
1535
|
+
// Get popper placement
|
|
1536
|
+
var placement = (attributes.popper &&
|
|
1542
1537
|
attributes.popper['data-popper-placement']) ||
|
|
1543
1538
|
initialPlacement;
|
|
1544
|
-
|
|
1545
|
-
if (popperPlacement) {
|
|
1546
|
-
setPlacement(popperPlacement);
|
|
1547
|
-
}
|
|
1548
|
-
}, [popperPlacement]);
|
|
1539
|
+
// Only listen to key ups when the tooltip is visible
|
|
1549
1540
|
React.useEffect(function () {
|
|
1550
1541
|
var handleEscape = function (event) {
|
|
1551
1542
|
if (event.key === 'Escape' ||
|
|
@@ -1564,31 +1555,30 @@ function Tooltip(_a) {
|
|
|
1564
1555
|
return function () {
|
|
1565
1556
|
targetElement.removeEventListener('keyup', handleEscape);
|
|
1566
1557
|
};
|
|
1567
|
-
}, [
|
|
1558
|
+
}, [showTooltip]);
|
|
1559
|
+
// Handle hover and focus events for the targetElement
|
|
1568
1560
|
React.useEffect(function () {
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('focusout', hide);
|
|
1574
|
-
}
|
|
1561
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('mouseenter', show);
|
|
1562
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('mouseleave', hide);
|
|
1563
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('focusin', show);
|
|
1564
|
+
targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('focusout', hide);
|
|
1575
1565
|
return function () {
|
|
1576
1566
|
targetElement === null || targetElement === void 0 ? void 0 : targetElement.removeEventListener('mouseenter', show);
|
|
1577
1567
|
targetElement === null || targetElement === void 0 ? void 0 : targetElement.removeEventListener('mouseleave', hide);
|
|
1578
1568
|
targetElement === null || targetElement === void 0 ? void 0 : targetElement.removeEventListener('focusin', show);
|
|
1579
1569
|
targetElement === null || targetElement === void 0 ? void 0 : targetElement.removeEventListener('focusout', hide);
|
|
1580
1570
|
};
|
|
1581
|
-
}, [targetElement,
|
|
1571
|
+
}, [targetElement, show, hide]);
|
|
1572
|
+
// Handle hover events for the tooltipElement
|
|
1582
1573
|
React.useEffect(function () {
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.addEventListener('mouseleave', handleTipMouseLeave);
|
|
1586
|
-
}
|
|
1574
|
+
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.addEventListener('mouseenter', show);
|
|
1575
|
+
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.addEventListener('mouseleave', hide);
|
|
1587
1576
|
return function () {
|
|
1588
|
-
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseenter',
|
|
1589
|
-
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseleave',
|
|
1577
|
+
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseenter', show);
|
|
1578
|
+
tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseleave', hide);
|
|
1590
1579
|
};
|
|
1591
|
-
}, [tooltipElement]);
|
|
1580
|
+
}, [tooltipElement, show, hide]);
|
|
1581
|
+
// Keep the target's id in sync
|
|
1592
1582
|
React.useEffect(function () {
|
|
1593
1583
|
var attrText = targetElement === null || targetElement === void 0 ? void 0 : targetElement.getAttribute(association);
|
|
1594
1584
|
if (!(attrText === null || attrText === void 0 ? void 0 : attrText.includes(id || ''))) {
|
|
@@ -2196,7 +2186,8 @@ var Link = function (_a) {
|
|
|
2196
2186
|
var children = _a.children, linkRef = _a.linkRef, className = _a.className, variant = _a.variant, other = tslib.__rest(_a, ["children", "linkRef", "className", "variant"]);
|
|
2197
2187
|
return (React__default.createElement("a", tslib.__assign({ ref: linkRef, className: classNames(className, {
|
|
2198
2188
|
Link: !variant,
|
|
2199
|
-
'Button--primary': variant === 'button'
|
|
2189
|
+
'Button--primary': variant === 'button',
|
|
2190
|
+
'Button--secondary': variant === 'button-secondary'
|
|
2200
2191
|
}) }, other), children));
|
|
2201
2192
|
};
|
|
2202
2193
|
Link.propTypes = {
|