react-modal-sheet 5.2.2 → 5.3.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.
@@ -14,7 +14,6 @@ export const SheetBackdrop = forwardRef<any, SheetBackdropProps>(
14
14
  const clickable = isClickable(rest);
15
15
  const Comp = clickable ? motion.button : motion.div;
16
16
  const pointerEvents = clickable ? 'auto' : 'none';
17
-
18
17
  const isUnstyled = unstyled ?? sheetContext.unstyled;
19
18
 
20
19
  const backdropStyle: MotionStyle = {
@@ -25,14 +24,14 @@ export const SheetBackdrop = forwardRef<any, SheetBackdropProps>(
25
24
 
26
25
  return (
27
26
  <Comp
28
- {...(rest as any)}
29
- ref={ref}
30
- className={`react-modal-sheet-backdrop ${className}`}
31
- style={backdropStyle}
32
27
  initial={{ opacity: 0 }}
33
28
  animate={{ opacity: 1 }}
34
29
  exit={{ opacity: 0 }}
35
30
  transition={{ duration: 1 }}
31
+ {...(rest as any)}
32
+ ref={ref}
33
+ className={`react-modal-sheet-backdrop ${className}`}
34
+ style={backdropStyle}
36
35
  />
37
36
  );
38
37
  }
@@ -1,9 +1,9 @@
1
1
  import { motion } from 'motion/react';
2
2
  import React, { forwardRef } from 'react';
3
3
 
4
- import { SheetDragIndicator } from './SheetDragIndicator';
5
4
  import { useSheetContext } from './context';
6
5
  import { useDragConstraints } from './hooks/use-drag-constraints';
6
+ import { SheetDragIndicator } from './SheetDragIndicator';
7
7
  import { styles } from './styles';
8
8
  import { type SheetHeaderProps } from './types';
9
9
  import { applyStyles, mergeRefs } from './utils';
package/src/debug.ts CHANGED
@@ -4,14 +4,14 @@
4
4
  * and hide it when that element is clicked. Create the element if it doesn't exist,
5
5
  * and update its content with the payload (any JSON data).
6
6
  */
7
- export function debug(payload: any) {
7
+ export function debug(payload: any, placement: 'top' | 'bottom' = 'bottom') {
8
8
  let debugElement = document.getElementById('debug-element');
9
9
 
10
10
  if (!debugElement) {
11
11
  debugElement = document.createElement('div');
12
12
  debugElement.id = 'debug-element';
13
13
  debugElement.style.position = 'fixed';
14
- debugElement.style.bottom = '0';
14
+ debugElement.style[placement] = '0';
15
15
  debugElement.style.left = '0';
16
16
  debugElement.style.width = '100%';
17
17
  debugElement.style.maxHeight = '50%';
package/src/sheet.tsx CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  } from 'motion/react';
10
10
  import React, {
11
11
  forwardRef,
12
+ useEffect,
12
13
  useImperativeHandle,
13
14
  useRef,
14
15
  useState,
@@ -276,6 +277,39 @@ export const Sheet = forwardRef<any, SheetProps>(
276
277
  snapTo,
277
278
  }));
278
279
 
280
+ /**
281
+ * If the keyboard is opened while we are in a snap point we need to ensure
282
+ * the sheet content is not covered by the keyboard due to being at a lower
283
+ * snap point. We move the sheet up enough to ensure the content is visible
284
+ * and move it back down when the keyboard closes.
285
+ */
286
+ useEffect(() => {
287
+ if (
288
+ isOpen &&
289
+ snapPoints.length > 0 &&
290
+ avoidKeyboard &&
291
+ keyboard.isKeyboardOpen
292
+ ) {
293
+ const visibleSheetHeight = yInverted.get() - keyboard.keyboardHeight;
294
+
295
+ if (visibleSheetHeight <= 0) {
296
+ const currentY = y.get();
297
+ const adjustedY = Math.max(
298
+ // 50 for some extra spacing between keyboard and sheet content
299
+ currentY - Math.abs(visibleSheetHeight) - 50,
300
+ 0
301
+ );
302
+
303
+ animate(y, adjustedY, animationOptions);
304
+
305
+ // When keyboard closes animate back to the original snap point
306
+ return () => {
307
+ animate(y, currentY, animationOptions);
308
+ };
309
+ }
310
+ }
311
+ }, [isOpen, keyboard.isKeyboardOpen]);
312
+
279
313
  useModalEffect({
280
314
  y,
281
315
  detent,
package/src/types.tsx CHANGED
@@ -23,10 +23,9 @@ type CommonProps = {
23
23
  unstyled?: boolean;
24
24
  };
25
25
 
26
- type MotionCommonProps = Omit<
27
- ComponentPropsWithoutRef<typeof motion.div>,
28
- 'initial' | 'animate' | 'exit'
29
- >;
26
+ type MotionDivProps = ComponentPropsWithoutRef<typeof motion.div>;
27
+
28
+ type MotionCommonProps = Omit<MotionDivProps, 'initial' | 'animate' | 'exit'>;
30
29
 
31
30
  export interface SheetTweenConfig {
32
31
  ease: EasingDefinition;
@@ -79,7 +78,7 @@ export type SheetContentProps = MotionCommonProps &
79
78
  scrollStyle?: MotionProps['style'];
80
79
  };
81
80
 
82
- export type SheetBackdropProps = MotionCommonProps & CommonProps;
81
+ export type SheetBackdropProps = MotionDivProps & CommonProps;
83
82
 
84
83
  export type SheetDragIndicatorProps = HTMLAttributes<HTMLDivElement> &
85
84
  CommonProps;