@swan-io/lake 13.7.0 → 13.7.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/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { Option } from "@swan-io/boxed";
|
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { match } from "ts-pattern";
|
|
4
4
|
const MAX_OFFSET_FOR_CENTER_PLACEMENT = 100;
|
|
5
|
+
const HORIZONTAL_SAFETY_MARGIN = 16;
|
|
5
6
|
export const useContextualLayer = ({ placement, visible, matchReferenceWidth = false, matchReferenceMinWidth = false, referenceRef: externalReferenceRef, }) => {
|
|
6
7
|
const referenceRef = useRef(null);
|
|
7
8
|
const usedRef = externalReferenceRef !== null && externalReferenceRef !== void 0 ? externalReferenceRef : referenceRef;
|
|
@@ -51,10 +52,16 @@ export const useContextualLayer = ({ placement, visible, matchReferenceWidth = f
|
|
|
51
52
|
height: "100vh",
|
|
52
53
|
pointerEvents: "none",
|
|
53
54
|
};
|
|
55
|
+
const maxWidth = match(inferedPlacement)
|
|
56
|
+
.with("left", () => viewportWidth - rect.left - HORIZONTAL_SAFETY_MARGIN)
|
|
57
|
+
.with("right", () => rect.right - HORIZONTAL_SAFETY_MARGIN)
|
|
58
|
+
.with("center", () => Math.min(availableSpaceBefore + width / 2, availableSpaceAfter + width / 2) * 2 - HORIZONTAL_SAFETY_MARGIN)
|
|
59
|
+
.exhaustive();
|
|
54
60
|
const style = {
|
|
55
61
|
...verticalPosition,
|
|
56
62
|
...horizontalPosition,
|
|
57
63
|
maxHeight,
|
|
64
|
+
maxWidth,
|
|
58
65
|
...(matchReferenceWidth === true ? { width } : undefined),
|
|
59
66
|
...(matchReferenceMinWidth === true ? { minWidth: width } : undefined),
|
|
60
67
|
pointerEvents: "auto",
|