react-modal-sheet 5.6.0 → 5.7.0

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.mjs CHANGED
@@ -402,12 +402,7 @@ function useModalEffect({
402
402
  }
403
403
  }
404
404
  progress = Math.max(0, Math.min(1, progress));
405
- const pageWidth = window.innerWidth;
406
- updateModalEffect(rootId, {
407
- scale: transform(progress, [0, 1], [1, (pageWidth - 16) / pageWidth]),
408
- translateY: transform(progress, [0, 1], [0, 24 + insetTop]),
409
- borderRadius: transform(progress, [0, 1], [0, 10])
410
- });
405
+ updateModalEffect(rootId, { progress, insetTop });
411
406
  });
412
407
  const handleYComplete = useStableCallback(() => {
413
408
  if (!rootId) return;
@@ -435,8 +430,14 @@ function useModalEffect({
435
430
  }, [rootId]);
436
431
  }
437
432
  function setupModalEffect(rootId) {
438
- const root = document.querySelector(`#${rootId}`);
439
- if (!root) return;
433
+ const target = getModalEffectTarget(rootId);
434
+ if (!target) return;
435
+ if (target.type === "sheet") {
436
+ const sheet = target.element;
437
+ sheet.style.transformOrigin = "center top";
438
+ return;
439
+ }
440
+ const root = target.element;
440
441
  const body = document.querySelector("body");
441
442
  body.style.backgroundColor = "#000000";
442
443
  root.style.overflow = "hidden";
@@ -446,16 +447,42 @@ function setupModalEffect(rootId) {
446
447
  root.style.transformOrigin = "center top";
447
448
  }
448
449
  function updateModalEffect(rootId, opts) {
449
- const root = document.querySelector(`#${rootId}`);
450
- if (!root) return;
451
- const { scale, translateY, borderRadius } = opts;
450
+ const target = getModalEffectTarget(rootId);
451
+ if (!target) return;
452
+ const { progress, insetTop } = opts;
453
+ if (target.type === "sheet") {
454
+ const sheet = target.element;
455
+ const sheetWidth = sheet.offsetWidth;
456
+ const sheetTop = sheet.offsetTop;
457
+ const scaleEnd2 = (sheetWidth - 16) / sheetWidth;
458
+ const scale2 = transform(progress, [0, 1], [1, scaleEnd2]);
459
+ const translateYEnd = clamp(scaleEnd2 * (24 + insetTop) - sheetTop, -10, 0);
460
+ const translateY2 = transform(progress, [0, 1], [0, translateYEnd]);
461
+ sheet.style.scale = `${scale2}`;
462
+ sheet.style.translate = `0 ${translateY2}px`;
463
+ return;
464
+ }
465
+ const root = target.element;
466
+ const pageWidth = window.innerWidth;
467
+ const scaleEnd = (pageWidth - 16) / pageWidth;
468
+ const scale = transform(progress, [0, 1], [1, scaleEnd]);
469
+ const translateY = transform(progress, [0, 1], [0, 24 + insetTop]);
470
+ const borderRadius = transform(progress, [0, 1], [0, 10]);
452
471
  root.style.transform = `scale(${scale}) translate3d(0, ${translateY}px, 0)`;
453
472
  root.style.borderTopRightRadius = `${borderRadius}px`;
454
473
  root.style.borderTopLeftRadius = `${borderRadius}px`;
455
474
  }
456
475
  function cleanupModalEffect(rootId) {
457
- const root = document.querySelector(`#${rootId}`);
458
- if (!root) return;
476
+ const target = getModalEffectTarget(rootId);
477
+ if (!target) return;
478
+ if (target.type === "sheet") {
479
+ const sheet = target.element;
480
+ sheet.style.removeProperty("transform-origin");
481
+ sheet.style.removeProperty("scale");
482
+ sheet.style.removeProperty("translate");
483
+ return;
484
+ }
485
+ const root = target.element;
459
486
  const body = document.querySelector("body");
460
487
  body.style.removeProperty("background-color");
461
488
  root.style.removeProperty("overflow");
@@ -467,6 +494,19 @@ function cleanupModalEffect(rootId) {
467
494
  root.style.removeProperty("border-top-right-radius");
468
495
  root.style.removeProperty("border-top-left-radius");
469
496
  }
497
+ function getModalEffectTarget(rootId) {
498
+ const root = document.getElementById(rootId);
499
+ if (!root) return null;
500
+ const sheetRoot = root.closest(".react-modal-sheet-root");
501
+ if (sheetRoot) {
502
+ const container = sheetRoot.querySelector(
503
+ ".react-modal-sheet-container"
504
+ );
505
+ if (!container) return null;
506
+ return { type: "sheet", element: container };
507
+ }
508
+ return { type: "root", element: root };
509
+ }
470
510
 
471
511
  // src/hooks/use-prevent-scroll.ts
472
512
  var KEYBOARD_BUFFER = 24;
@@ -1044,7 +1084,7 @@ var Sheet = forwardRef(
1044
1084
  onDragEnd: onDragEndProp,
1045
1085
  ...rest
1046
1086
  }, ref) => {
1047
- const [sheetBoundsRef, sheetBounds] = useMeasure();
1087
+ const [sheetBoundsRef, sheetBounds] = useMeasure({ offsetSize: true });
1048
1088
  const sheetRef = useRef(null);
1049
1089
  const sheetHeight = Math.round(sheetBounds.height);
1050
1090
  const [currentSnap, setCurrentSnap] = useState(initialSnap);