@canvas-components/react-components 0.3.6 → 0.3.7
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/dist/index.cjs +24 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -319,6 +319,7 @@ function ReactPopup(props) {
|
|
|
319
319
|
style,
|
|
320
320
|
surfaceClassName,
|
|
321
321
|
surfaceStyle,
|
|
322
|
+
constrainHeight = false,
|
|
322
323
|
zIndex = 1200
|
|
323
324
|
} = props;
|
|
324
325
|
const { scale: contentScale } = useReactContentScale();
|
|
@@ -340,6 +341,7 @@ function ReactPopup(props) {
|
|
|
340
341
|
return;
|
|
341
342
|
}
|
|
342
343
|
const nextPosition = resolvePopupPosition({
|
|
344
|
+
constrainHeight,
|
|
343
345
|
anchor: nextAnchor,
|
|
344
346
|
contentScale,
|
|
345
347
|
matchAnchorWidth,
|
|
@@ -349,7 +351,7 @@ function ReactPopup(props) {
|
|
|
349
351
|
popupRect: resolvePopupSurfaceRect(surfaceRef.current, contentScale)
|
|
350
352
|
});
|
|
351
353
|
setPosition((prev) => {
|
|
352
|
-
if (prev?.placement === nextPosition.placement && prev?.style.left === nextPosition.style.left && prev?.style.top === nextPosition.style.top && prev?.style.width === nextPosition.style.width && prev?.style.minWidth === nextPosition.style.minWidth) {
|
|
354
|
+
if (prev?.placement === nextPosition.placement && prev?.style.left === nextPosition.style.left && prev?.style.top === nextPosition.style.top && prev?.style.width === nextPosition.style.width && prev?.style.minWidth === nextPosition.style.minWidth && prev?.style.maxHeight === nextPosition.style.maxHeight) {
|
|
353
355
|
return prev;
|
|
354
356
|
}
|
|
355
357
|
return nextPosition;
|
|
@@ -376,6 +378,7 @@ function ReactPopup(props) {
|
|
|
376
378
|
anchorRect,
|
|
377
379
|
anchorRef,
|
|
378
380
|
contentScale,
|
|
381
|
+
constrainHeight,
|
|
379
382
|
matchAnchorWidth,
|
|
380
383
|
minWidth,
|
|
381
384
|
offset,
|
|
@@ -392,6 +395,7 @@ function ReactPopup(props) {
|
|
|
392
395
|
return;
|
|
393
396
|
}
|
|
394
397
|
const nextPosition = resolvePopupPosition({
|
|
398
|
+
constrainHeight,
|
|
395
399
|
anchor: nextAnchor,
|
|
396
400
|
contentScale,
|
|
397
401
|
matchAnchorWidth,
|
|
@@ -401,7 +405,7 @@ function ReactPopup(props) {
|
|
|
401
405
|
popupRect: resolvePopupSurfaceRect(surfaceRef.current, contentScale)
|
|
402
406
|
});
|
|
403
407
|
setPosition((prev) => {
|
|
404
|
-
if (prev?.placement === nextPosition.placement && prev?.style.left === nextPosition.style.left && prev?.style.top === nextPosition.style.top && prev?.style.width === nextPosition.style.width && prev?.style.minWidth === nextPosition.style.minWidth) {
|
|
408
|
+
if (prev?.placement === nextPosition.placement && prev?.style.left === nextPosition.style.left && prev?.style.top === nextPosition.style.top && prev?.style.width === nextPosition.style.width && prev?.style.minWidth === nextPosition.style.minWidth && prev?.style.maxHeight === nextPosition.style.maxHeight) {
|
|
405
409
|
return prev;
|
|
406
410
|
}
|
|
407
411
|
return nextPosition;
|
|
@@ -419,6 +423,7 @@ function ReactPopup(props) {
|
|
|
419
423
|
anchorRect,
|
|
420
424
|
anchorRef,
|
|
421
425
|
contentScale,
|
|
426
|
+
constrainHeight,
|
|
422
427
|
matchAnchorWidth,
|
|
423
428
|
minWidth,
|
|
424
429
|
offset,
|
|
@@ -484,7 +489,7 @@ function ReactPopup(props) {
|
|
|
484
489
|
transition.className,
|
|
485
490
|
surfaceClassName
|
|
486
491
|
),
|
|
487
|
-
style: surfaceStyle,
|
|
492
|
+
style: resolvePopupSurfaceStyle(surfaceStyle, position.style.maxHeight),
|
|
488
493
|
children
|
|
489
494
|
}
|
|
490
495
|
)
|
|
@@ -513,7 +518,8 @@ function resolvePopupPosition(params) {
|
|
|
513
518
|
matchAnchorWidth ? anchor.width : 0
|
|
514
519
|
);
|
|
515
520
|
const popupWidth = preferredVisualWidth;
|
|
516
|
-
const
|
|
521
|
+
const maxVisualHeight = Math.max(0, viewportHeight - margin * 2);
|
|
522
|
+
const popupHeight = params.constrainHeight ? Math.min(popupRect?.height ?? 0, maxVisualHeight) : popupRect?.height ?? 0;
|
|
517
523
|
const isHorizontalPlacement = placement.startsWith("left") || placement.startsWith("right");
|
|
518
524
|
const preferredVertical = placement.startsWith("top") ? "top" : placement.endsWith("Top") ? "top" : "bottom";
|
|
519
525
|
const preferredTop = resolveRawTop({
|
|
@@ -558,6 +564,7 @@ function resolvePopupPosition(params) {
|
|
|
558
564
|
vertical: resolvedVertical
|
|
559
565
|
}),
|
|
560
566
|
style: {
|
|
567
|
+
...params.constrainHeight ? { maxHeight: toContentLayoutSize(maxVisualHeight, contentScale) } : {},
|
|
561
568
|
left,
|
|
562
569
|
top,
|
|
563
570
|
width: matchAnchorWidth ? layoutAnchorWidth : void 0,
|
|
@@ -565,6 +572,19 @@ function resolvePopupPosition(params) {
|
|
|
565
572
|
}
|
|
566
573
|
};
|
|
567
574
|
}
|
|
575
|
+
function resolvePopupSurfaceStyle(style, viewportMaxHeight) {
|
|
576
|
+
if (typeof viewportMaxHeight !== "number") return style;
|
|
577
|
+
const custom = style?.maxHeight;
|
|
578
|
+
const maxHeight = typeof custom === "number" ? Math.min(custom, viewportMaxHeight) : typeof custom === "string" && custom !== "none" ? `min(${custom}, ${viewportMaxHeight}px)` : viewportMaxHeight;
|
|
579
|
+
return {
|
|
580
|
+
...style,
|
|
581
|
+
boxSizing: "border-box",
|
|
582
|
+
minHeight: 0,
|
|
583
|
+
maxHeight,
|
|
584
|
+
overflowY: "auto",
|
|
585
|
+
overscrollBehaviorY: "contain"
|
|
586
|
+
};
|
|
587
|
+
}
|
|
568
588
|
function resolvePlacement(params) {
|
|
569
589
|
const { horizontal, isHorizontalPlacement, vertical } = params;
|
|
570
590
|
if (isHorizontalPlacement) {
|