@spscommerce/ds-react 5.10.0 → 5.10.1
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/index.cjs.js +45 -45
- package/lib/index.es.js +32 -1
- package/package.json +9 -9
package/lib/index.es.js
CHANGED
|
@@ -21878,6 +21878,7 @@ function SpsTooltip({
|
|
|
21878
21878
|
const [shown, setShown] = React.useState(false);
|
|
21879
21879
|
const rootElement = React.useRef(null);
|
|
21880
21880
|
const forElementRef = typeof forProp === "string" ? React.useRef(document.getElementById(forProp)) : forProp;
|
|
21881
|
+
const caretRef = React.useRef(null);
|
|
21881
21882
|
const clearHideDelay = React.useCallback(() => {
|
|
21882
21883
|
if (iref.current.hideTimer) {
|
|
21883
21884
|
window.clearTimeout(iref.current.hideTimer);
|
|
@@ -21927,6 +21928,35 @@ function SpsTooltip({
|
|
|
21927
21928
|
clearHideDelay();
|
|
21928
21929
|
iref.current.hideTimer = window.setTimeout(hide2, hideDelay);
|
|
21929
21930
|
}, []);
|
|
21931
|
+
const getSecondaryOffset = React.useCallback((pos) => {
|
|
21932
|
+
var _a, _b, _c, _d, _e, _f;
|
|
21933
|
+
const [primaryPosition, secondaryPosition] = pos.split(" ");
|
|
21934
|
+
const forElementBounds = (_a = forElementRef == null ? void 0 : forElementRef.current) == null ? void 0 : _a.getBoundingClientRect();
|
|
21935
|
+
const caretWidth = caretRef.current ? parseInt(((_b = getComputedStyle(caretRef.current)) == null ? void 0 : _b.width) || "0", 10) : 0;
|
|
21936
|
+
const caretDiagonal = caretWidth * Math.sqrt(2);
|
|
21937
|
+
const caretTransformationMargin = (caretDiagonal - caretWidth) / 2;
|
|
21938
|
+
if (["top", "bottom"].includes(primaryPosition) && secondaryPosition !== "middle") {
|
|
21939
|
+
if (!(forElementBounds == null ? void 0 : forElementBounds.width) || forElementBounds.width > 50) {
|
|
21940
|
+
return 0;
|
|
21941
|
+
}
|
|
21942
|
+
const caretLeft = caretRef.current ? parseInt(((_c = getComputedStyle(caretRef.current)) == null ? void 0 : _c.left) || "0", 10) : 0;
|
|
21943
|
+
const caretRight = caretRef.current ? parseInt(((_d = getComputedStyle(caretRef.current)) == null ? void 0 : _d.right) || "0", 10) : 0;
|
|
21944
|
+
const caretOffsetStart = caretLeft < caretRight ? caretLeft : caretRight;
|
|
21945
|
+
const caretOffsetToMiddle = caretOffsetStart - caretTransformationMargin + caretDiagonal / 2;
|
|
21946
|
+
return forElementBounds.width / 2 - caretOffsetToMiddle;
|
|
21947
|
+
} else if (["left", "right"].includes(primaryPosition) && secondaryPosition !== "middle") {
|
|
21948
|
+
if ((forElementBounds == null ? void 0 : forElementBounds.height) && forElementBounds.height > 50) {
|
|
21949
|
+
return 0;
|
|
21950
|
+
}
|
|
21951
|
+
const caretTop = caretRef.current ? parseInt(((_e = getComputedStyle(caretRef.current)) == null ? void 0 : _e.top) || "0", 10) : 0;
|
|
21952
|
+
const caretBottom = caretRef.current ? parseInt(((_f = getComputedStyle(caretRef.current)) == null ? void 0 : _f.bottom) || "0", 10) : 0;
|
|
21953
|
+
const caretOffsetStart = caretTop < caretBottom ? caretTop : caretBottom;
|
|
21954
|
+
const caretOffsetToMiddle = caretOffsetStart - caretTransformationMargin + caretDiagonal / 2;
|
|
21955
|
+
return forElementBounds.height / 2 - caretOffsetToMiddle;
|
|
21956
|
+
} else {
|
|
21957
|
+
return 0;
|
|
21958
|
+
}
|
|
21959
|
+
}, []);
|
|
21930
21960
|
React.useEffect(() => {
|
|
21931
21961
|
if (typeof forProp === "string") {
|
|
21932
21962
|
forElementRef.current = document.getElementById(forProp);
|
|
@@ -21997,7 +22027,7 @@ function SpsTooltip({
|
|
|
21997
22027
|
const [posStyle, altPositionUsed] = shown ? getPosition(rootElement, forElementRef, position3, __spreadValues({
|
|
21998
22028
|
altPosition,
|
|
21999
22029
|
setMinWidth: false,
|
|
22000
|
-
offsets: [offsets[0] - CARET_SPACING_PX, offsets[1]]
|
|
22030
|
+
offsets: [offsets[0] - CARET_SPACING_PX, offsets[1] + getSecondaryOffset(position3)]
|
|
22001
22031
|
}, portalContext)) : [{}, false];
|
|
22002
22032
|
const classes = clsx(unsafelyReplaceClassName || "sps-tooltip", "z-stratum-tip", `sps-tooltip--${kind}`, `sps-tooltip--pos-${(altPositionUsed ? altPosition : position3).replace(" ", "-")}`, shown && "sps-tooltip--shown", className);
|
|
22003
22033
|
return portal(/* @__PURE__ */ React.createElement("div", {
|
|
@@ -22013,6 +22043,7 @@ function SpsTooltip({
|
|
|
22013
22043
|
}, title) : title), /* @__PURE__ */ React.createElement("span", {
|
|
22014
22044
|
className: "sps-tooltip__body d-block"
|
|
22015
22045
|
}, children), /* @__PURE__ */ React.createElement("span", {
|
|
22046
|
+
ref: caretRef,
|
|
22016
22047
|
className: "sps-tooltip__caret"
|
|
22017
22048
|
})));
|
|
22018
22049
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/ds-react",
|
|
3
3
|
"description": "SPS Design System React components",
|
|
4
|
-
"version": "5.10.
|
|
4
|
+
"version": "5.10.1",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/ds-react",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@react-stately/collections": "^3.3.3",
|
|
31
|
-
"@spscommerce/ds-colors": "5.10.
|
|
32
|
-
"@spscommerce/ds-shared": "5.10.
|
|
33
|
-
"@spscommerce/positioning": "5.10.
|
|
34
|
-
"@spscommerce/utils": "5.10.
|
|
31
|
+
"@spscommerce/ds-colors": "5.10.1",
|
|
32
|
+
"@spscommerce/ds-shared": "5.10.1",
|
|
33
|
+
"@spscommerce/positioning": "5.10.1",
|
|
34
|
+
"@spscommerce/utils": "5.10.1",
|
|
35
35
|
"moment": "^2.25.3",
|
|
36
36
|
"moment-timezone": "^0.5.28",
|
|
37
37
|
"react": "^16.9.0",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@react-stately/collections": "^3.3.3",
|
|
42
|
-
"@spscommerce/ds-colors": "5.10.
|
|
43
|
-
"@spscommerce/ds-shared": "5.10.
|
|
44
|
-
"@spscommerce/positioning": "5.10.
|
|
45
|
-
"@spscommerce/utils": "5.10.
|
|
42
|
+
"@spscommerce/ds-colors": "5.10.1",
|
|
43
|
+
"@spscommerce/ds-shared": "5.10.1",
|
|
44
|
+
"@spscommerce/positioning": "5.10.1",
|
|
45
|
+
"@spscommerce/utils": "5.10.1",
|
|
46
46
|
"@testing-library/react": "^9.3.2",
|
|
47
47
|
"@types/prop-types": "^15.7.1",
|
|
48
48
|
"@types/react": "^16.9.0",
|