@deque/cauldron-react 4.1.0-canary.e368ef0b → 4.1.0-canary.f7123dc9

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 CHANGED
@@ -34,7 +34,8 @@
34
34
  --expandcollapse-panel-color: var(--accent-light);
35
35
  }
36
36
 
37
- a.Button--primary {
37
+ a.Button--primary,
38
+ a.Button--secondary {
38
39
  text-decoration: none;
39
40
  padding: 9px 18px;
40
41
  }
@@ -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;
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- interface BaseStepProps {
3
+ interface BaseStepProps extends React.LiHTMLAttributes<HTMLLIElement> {
4
4
  status: 'current' | 'complete' | 'future';
5
- className?: string;
6
5
  }
7
6
  interface StepWithChildren extends BaseStepProps {
8
7
  children: React.ReactNode;
@@ -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: showProp, hideElementOnHidden, className, ...props }: TooltipProps): React.ReactPortal | null;
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, showProp = _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"]);
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 hovering = React.useRef(false);
1481
- var _h = tslib.__read(React.useState(initialPlacement), 2), placement = _h[0], setPlacement = _h[1];
1482
- var _j = tslib.__read(React.useState(!!showProp), 2), showTooltip = _j[0], setShowTooltip = _j[1];
1483
- var _k = tslib.__read(React.useState(null), 2), targetElement = _k[0], setTargetElement = _k[1];
1484
- var _l = tslib.__read(React.useState(null), 2), tooltipElement = _l[0], setTooltipElement = _l[1];
1485
- var _m = tslib.__read(React.useState(null), 2), arrowElement = _m[0], setArrowElement = _m[1];
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 = _o.styles, attributes = _o.attributes, update = _o.update;
1495
- var show = function () { return tslib.__awaiter(_this, void 0, void 0, function () {
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
- var hide = function (_a) {
1512
- var target = _a.target;
1513
- if (document.activeElement !== target) {
1514
- setTimeout(function () {
1515
- if (!hovering.current) {
1516
- setShowTooltip(false);
1517
- fireCustomEvent(false, targetElement);
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
- var handleTriggerMouseEnter = function () {
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
- var popperPlacement = (attributes.popper &&
1535
+ // Get popper placement
1536
+ var placement = (attributes.popper &&
1542
1537
  attributes.popper['data-popper-placement']) ||
1543
1538
  initialPlacement;
1544
- React.useEffect(function () {
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
- }, [showProp]);
1558
+ }, [showTooltip]);
1559
+ // Handle hover and focus events for the targetElement
1568
1560
  React.useEffect(function () {
1569
- if (typeof showProp !== undefined) {
1570
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('mouseenter', handleTriggerMouseEnter);
1571
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('mouseleave', handleTriggerMouseLeave);
1572
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.addEventListener('focusin', show);
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, showProp]);
1571
+ }, [targetElement, show, hide]);
1572
+ // Handle hover events for the tooltipElement
1582
1573
  React.useEffect(function () {
1583
- if (tooltipElement) {
1584
- tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.addEventListener('mouseenter', handleTipMouseEnter);
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', handleTipMouseEnter);
1589
- tooltipElement === null || tooltipElement === void 0 ? void 0 : tooltipElement.removeEventListener('mouseleave', handleTipMouseLeave);
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 = {
@@ -8275,23 +8266,34 @@ var DescriptionDetails = function (_a) {
8275
8266
  DescriptionDetails.displayName = 'DescriptionDetails';
8276
8267
  DescriptionDetails.propTypes = commonPropTypes;
8277
8268
 
8278
- var isTooltip = function (props) {
8269
+ var isTooltipProps = function (props) {
8279
8270
  return !!props.tooltip;
8280
8271
  };
8281
8272
  var Step = function (props) {
8282
- var status = props.status, className = props.className, other = tslib.__rest(props, ["status", "className"]);
8283
- return (React__default.createElement("li", tslib.__assign({ className: classNames('Stepper__step', "Stepper__step--" + status, className), "aria-current": status === 'current' ? 'step' : 'false' }, other),
8273
+ var _a;
8274
+ var children = props.children, status = props.status, className = props.className, other = tslib.__rest(props, ["children", "status", "className"]);
8275
+ var tooltip;
8276
+ var tooltipText;
8277
+ var liProps;
8278
+ var isTooltip = isTooltipProps(other);
8279
+ if (isTooltip) {
8280
+ (_a = other, (tooltip = _a.tooltip, tooltipText = _a.tooltipText, _a), liProps = tslib.__rest(_a, ["tooltip", "tooltipText"]));
8281
+ }
8282
+ else {
8283
+ liProps = other;
8284
+ }
8285
+ return (React__default.createElement("li", tslib.__assign({ className: classNames('Stepper__step', "Stepper__step--" + status, className), "aria-current": status === 'current' ? 'step' : 'false' }, liProps),
8284
8286
  React__default.createElement("div", { className: "Stepper__step-line" }),
8285
- React__default.createElement("div", { className: "Stepper__step-content" }, isTooltip(props) ? (React__default.createElement(TooltipTabstop, { placement: "bottom", tooltip: props.tooltip,
8287
+ React__default.createElement("div", { className: "Stepper__step-content" }, isTooltip ? (React__default.createElement(TooltipTabstop, { placement: "bottom", tooltip: tooltip,
8286
8288
  // the pseudo content (ex: "1") is conveyed
8287
8289
  // by the list item's position in the set of
8288
8290
  // list items, therefore it is safe to clobber
8289
8291
  // it with the contents of the tooltip in the
8290
8292
  // tab stop's accessible name.
8291
- association: "aria-labelledby", "aria-label": isTooltip(props) ? props.tooltipText : undefined },
8293
+ association: "aria-labelledby", "aria-label": tooltipText },
8292
8294
  React__default.createElement("div", { className: "Stepper__step-indicator" }))) : (React__default.createElement(React__default.Fragment, null,
8293
8295
  React__default.createElement("div", { className: "Stepper__step-indicator" }),
8294
- 'children' in props && (React__default.createElement("div", { className: "Stepper__step-label" }, props.children)))))));
8296
+ children ? (React__default.createElement("div", { className: "Stepper__step-label" }, children)) : null)))));
8295
8297
  };
8296
8298
  Step.displayName = 'Step';
8297
8299
  Step.propTypes = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "4.1.0-canary.e368ef0b",
3
+ "version": "4.1.0-canary.f7123dc9",
4
4
  "description": "Fully accessible react components library for Deque Cauldron",
5
5
  "publishConfig": {
6
6
  "access": "public"