@deque/cauldron-react 6.16.0-canary.cd6c09d5 → 6.16.0-canary.d7ad0332

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.
@@ -1,4 +1,4 @@
1
- import { type Placement } from '@floating-ui/dom';
1
+ import { type Placement, type Coords } from '@floating-ui/dom';
2
2
  import React from 'react';
3
3
  import useFocusTrap from '../../utils/useFocusTrap';
4
4
  declare const AnchoredOverlay: React.ForwardRefExoticComponent<{
@@ -12,6 +12,8 @@ declare const AnchoredOverlay: React.ForwardRefExoticComponent<{
12
12
  onOpenChange?: ((open: boolean) => void) | undefined;
13
13
  /** A callback function that is called when the placement of the overlay changes. */
14
14
  onPlacementChange?: ((placement: Placement) => void) | undefined;
15
+ /** A callback function that is called when the shift of the overlay changes. */
16
+ onShiftChange?: ((coords: Coords) => void) | undefined;
15
17
  /** An optional offset number to position the anchor element from its anchored target. */
16
18
  offset?: number | undefined;
17
19
  /** When set, traps focus within the AnchoredOverlay. */
package/lib/index.js CHANGED
@@ -1782,10 +1782,11 @@ function getAutoAlignment(placement) {
1782
1782
  }
1783
1783
  }
1784
1784
  var AnchoredOverlay = React.forwardRef(function (_a, refProp) {
1785
- var as = _a.as, _b = _a.placement, initialPlacement = _b === void 0 ? 'auto' : _b, target = _a.target, children = _a.children, style = _a.style, _c = _a.open, open = _c === void 0 ? false : _c, offset = _a.offset, focusTrap = _a.focusTrap, focusTrapOptions = _a.focusTrapOptions, onOpenChange = _a.onOpenChange, onPlacementChange = _a.onPlacementChange, props = tslib.__rest(_a, ["as", "placement", "target", "children", "style", "open", "offset", "focusTrap", "focusTrapOptions", "onOpenChange", "onPlacementChange"]);
1785
+ var _b, _c;
1786
+ var as = _a.as, _d = _a.placement, initialPlacement = _d === void 0 ? 'auto' : _d, target = _a.target, children = _a.children, style = _a.style, _e = _a.open, open = _e === void 0 ? false : _e, offset = _a.offset, focusTrap = _a.focusTrap, focusTrapOptions = _a.focusTrapOptions, onOpenChange = _a.onOpenChange, onPlacementChange = _a.onPlacementChange, onShiftChange = _a.onShiftChange, props = tslib.__rest(_a, ["as", "placement", "target", "children", "style", "open", "offset", "focusTrap", "focusTrapOptions", "onOpenChange", "onPlacementChange", "onShiftChange"]);
1786
1787
  var ref = useSharedRef(refProp);
1787
1788
  var Component = as || 'div';
1788
- var _d = reactDom$1.useFloating({
1789
+ var _f = reactDom$1.useFloating({
1789
1790
  open: open,
1790
1791
  // default to initial placement on top when placement is auto
1791
1792
  // @ts-expect-error auto placement is not a valid placement for floating-ui
@@ -1796,14 +1797,15 @@ var AnchoredOverlay = React.forwardRef(function (_a, refProp) {
1796
1797
  ? reactDom$1.autoPlacement({
1797
1798
  alignment: getAutoAlignment(initialPlacement)
1798
1799
  })
1799
- : reactDom$1.flip()
1800
+ : reactDom$1.flip(),
1801
+ reactDom$1.shift({ crossAxis: false })
1800
1802
  ].filter(Boolean),
1801
1803
  elements: {
1802
1804
  reference: resolveElement(target),
1803
1805
  floating: ref.current
1804
1806
  },
1805
1807
  whileElementsMounted: dom.autoUpdate
1806
- }), floatingStyles = _d.floatingStyles, placement = _d.placement;
1808
+ }), floatingStyles = _f.floatingStyles, placement = _f.placement, middlewareData = _f.middlewareData;
1807
1809
  useEscapeKey({
1808
1810
  active: open,
1809
1811
  capture: true,
@@ -1823,7 +1825,16 @@ var AnchoredOverlay = React.forwardRef(function (_a, refProp) {
1823
1825
  if (typeof onPlacementChange === 'function') {
1824
1826
  onPlacementChange(placement);
1825
1827
  }
1826
- }, [placement]);
1828
+ }, [onPlacementChange, placement]);
1829
+ React.useEffect(function () {
1830
+ var _a, _b;
1831
+ if (typeof onShiftChange === 'function') {
1832
+ onShiftChange({
1833
+ x: ((_a = middlewareData.shift) === null || _a === void 0 ? void 0 : _a.x) || 0,
1834
+ y: ((_b = middlewareData.shift) === null || _b === void 0 ? void 0 : _b.y) || 0
1835
+ });
1836
+ }
1837
+ }, [onShiftChange, (_b = middlewareData.shift) === null || _b === void 0 ? void 0 : _b.x, (_c = middlewareData.shift) === null || _c === void 0 ? void 0 : _c.y]);
1827
1838
  return (React__default["default"].createElement(Component, tslib.__assign({ ref: ref }, props, { style: tslib.__assign(tslib.__assign({}, floatingStyles), style) }), children));
1828
1839
  });
1829
1840
  AnchoredOverlay.displayName = 'AnchoredOverlay';
@@ -1885,6 +1896,7 @@ function Tooltip(_a) {
1885
1896
  var _h = tslib.__read(React.useState(!!showProp || defaultShow), 2), showTooltip = _h[0], setShowTooltip = _h[1];
1886
1897
  var _j = tslib.__read(React.useState(null), 2), tooltipElement = _j[0], setTooltipElement = _j[1];
1887
1898
  var _k = tslib.__read(React.useState(initialPlacement), 2), placement = _k[0], setPlacement = _k[1];
1899
+ var _l = tslib.__read(React.useState(), 2), arrowShift = _l[0], setArrowShift = _l[1];
1888
1900
  var hasAriaAssociation = association !== 'none';
1889
1901
  // Show the tooltip
1890
1902
  var show = React.useCallback(function () { return tslib.__awaiter(_this, void 0, void 0, function () {
@@ -1963,13 +1975,23 @@ function Tooltip(_a) {
1963
1975
  }
1964
1976
  };
1965
1977
  }, [target, id, association]);
1978
+ var updateArrowShiftPosition = React.useCallback(function (_a) {
1979
+ var x = _a.x;
1980
+ if (variant === 'big' || x === 0) {
1981
+ setArrowShift(null);
1982
+ return;
1983
+ }
1984
+ // The tooltip shift position is inversely related to the direction
1985
+ // that the arrow needs to shift
1986
+ setArrowShift(x * -1);
1987
+ }, [variant]);
1966
1988
  return (React__default["default"].createElement(React__default["default"].Fragment, null, (showTooltip || hideElementOnHidden) && isBrowser()
1967
- ? reactDom.createPortal(React__default["default"].createElement(AnchoredOverlay, tslib.__assign({ id: id, target: target, placement: initialPlacement, onPlacementChange: setPlacement, open: showTooltip && typeof showProp !== 'boolean', onOpenChange: setShowTooltip, className: classNames__default["default"]('Tooltip', "Tooltip--".concat(placement), className, {
1989
+ ? reactDom.createPortal(React__default["default"].createElement(AnchoredOverlay, tslib.__assign({ id: id, target: target, placement: initialPlacement, onPlacementChange: setPlacement, open: showTooltip && typeof showProp !== 'boolean', onOpenChange: setShowTooltip, onShiftChange: updateArrowShiftPosition, className: classNames__default["default"]('Tooltip', "Tooltip--".concat(placement), className, {
1968
1990
  TooltipInfo: variant === 'info',
1969
1991
  'Tooltip--hidden': !showTooltip && hideElementOnHidden,
1970
1992
  'Tooltip--big': variant === 'big'
1971
1993
  }), ref: setTooltipElement, role: "tooltip", offset: 8 }, props),
1972
- variant !== 'big' && React__default["default"].createElement("div", { className: "TooltipArrow" }),
1994
+ variant !== 'big' && React__default["default"].createElement("div", { className: "TooltipArrow", style: arrowShift ? { transform: "translateX(".concat(arrowShift, "px)") } : undefined }),
1973
1995
  children), (portal && 'current' in portal ? portal.current : portal) ||
1974
1996
  (
1975
1997
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-react-fc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "6.16.0-canary.cd6c09d5",
3
+ "version": "6.16.0-canary.d7ad0332",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Fully accessible react components library for Deque Cauldron",
6
6
  "homepage": "https://cauldron.dequelabs.com/",