react-modal-sheet 5.1.0 → 5.1.2
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/README.md +38 -0
- package/dist/index.d.mts +7 -9
- package/dist/index.d.ts +7 -9
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/SheetBackdrop.tsx +1 -1
- package/src/index.tsx +2 -0
- package/src/sheet.tsx +10 -3
- package/src/snap.ts +17 -1
- package/src/types.tsx +7 -8
- package/src/utils.ts +21 -0
package/README.md
CHANGED
|
@@ -778,3 +778,41 @@ If you're experiencing issues after upgrading, check the "What's new in v5" sect
|
|
|
778
778
|
1. **Snap points not working**: Ensure your snap points are in ascending order (`[0, 0.5, 1]` instead of `[1, 0.5, 0]`)
|
|
779
779
|
2. **Scrolling issues**: Remove `Sheet.Scroller` components as scrolling is now handled by `Sheet.Content`
|
|
780
780
|
3. **Detent errors**: Update detent prop values (`"full-height"` → `"default"`, `"content-height"` → `"content"`)
|
|
781
|
+
|
|
782
|
+
## 🤝 Contributing
|
|
783
|
+
|
|
784
|
+
If you find a bug or have a feature request please open an issue. If you want to contribute code please open a pull request.
|
|
785
|
+
|
|
786
|
+
You can build and run the library and the example app locally like this:
|
|
787
|
+
|
|
788
|
+
1. First install [yalc](https://github.com/wclr/yalc) globally for managing local package dependencies.
|
|
789
|
+
|
|
790
|
+
```sh
|
|
791
|
+
npm i yalc -g
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
2. Install deps + configure yalc.
|
|
795
|
+
|
|
796
|
+
```sh
|
|
797
|
+
npm install
|
|
798
|
+
npm run build
|
|
799
|
+
npm run link
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
3. Start a watcher for building the library.
|
|
803
|
+
|
|
804
|
+
```sh
|
|
805
|
+
npm run dev
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
4. Run dev server for the example app (do this in another terminal).
|
|
809
|
+
|
|
810
|
+
```sh
|
|
811
|
+
cd example
|
|
812
|
+
npm run dev
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
5. Open http://localhost:5173/ to see the examples. Now if you make edits to the library code the example app will automatically refresh.
|
|
816
|
+
|
|
817
|
+
> [!TIP]
|
|
818
|
+
> If you want to test the example app on your phone you can run the example app with `npm run dev:host` and then open your computer's local IP address in your phone's browser. Make sure your phone is on the same network as your computer.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { EasingDefinition, motion,
|
|
2
|
-
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes,
|
|
1
|
+
import { EasingDefinition, motion, MotionValue } from 'motion/react';
|
|
2
|
+
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes, FunctionComponent, HTMLAttributes, RefObject } from 'react';
|
|
3
3
|
|
|
4
4
|
type SheetDetent = 'default' | 'full' | 'content';
|
|
5
5
|
type CommonProps = {
|
|
6
6
|
className?: string;
|
|
7
|
-
style?: CSSProperties;
|
|
8
7
|
unstyled?: boolean;
|
|
9
8
|
};
|
|
10
|
-
type MotionCommonProps = Omit<
|
|
11
|
-
type MotionDivProps = ComponentPropsWithoutRef<typeof motion.div>;
|
|
9
|
+
type MotionCommonProps = Omit<ComponentPropsWithoutRef<typeof motion.div>, 'initial' | 'animate' | 'exit'>;
|
|
12
10
|
interface SheetTweenConfig {
|
|
13
11
|
ease: EasingDefinition;
|
|
14
12
|
duration: number;
|
|
@@ -37,15 +35,15 @@ type SheetProps = {
|
|
|
37
35
|
onOpenEnd?: () => void;
|
|
38
36
|
onOpenStart?: () => void;
|
|
39
37
|
onSnap?: (index: number) => void;
|
|
40
|
-
} &
|
|
38
|
+
} & MotionCommonProps;
|
|
41
39
|
type SheetContainerProps = MotionCommonProps & CommonProps & {
|
|
42
40
|
children: ReactNode;
|
|
43
41
|
};
|
|
44
|
-
type SheetHeaderProps =
|
|
42
|
+
type SheetHeaderProps = MotionCommonProps & CommonProps & {
|
|
45
43
|
children?: ReactNode;
|
|
46
44
|
disableDrag?: boolean;
|
|
47
45
|
};
|
|
48
|
-
type SheetContentProps =
|
|
46
|
+
type SheetContentProps = MotionCommonProps & CommonProps & {
|
|
49
47
|
disableDrag?: boolean | ((args: SheetStateInfo) => boolean);
|
|
50
48
|
disableScroll?: boolean | ((args: SheetStateInfo) => boolean);
|
|
51
49
|
scrollRef?: RefObject<HTMLDivElement | null>;
|
|
@@ -83,4 +81,4 @@ interface SheetRef {
|
|
|
83
81
|
}
|
|
84
82
|
declare const Sheet: SheetCompound;
|
|
85
83
|
|
|
86
|
-
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetDragIndicatorProps, type SheetHeaderProps, type SheetProps, type SheetRef, type SheetSnapPoint, type SheetStateInfo };
|
|
84
|
+
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetDetent, type SheetDragIndicatorProps, type SheetHeaderProps, type SheetProps, type SheetRef, type SheetSnapPoint, type SheetStateInfo, type SheetTweenConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { EasingDefinition, motion,
|
|
2
|
-
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes,
|
|
1
|
+
import { EasingDefinition, motion, MotionValue } from 'motion/react';
|
|
2
|
+
import { ForwardRefExoticComponent, ReactNode, ComponentPropsWithoutRef, RefAttributes, FunctionComponent, HTMLAttributes, RefObject } from 'react';
|
|
3
3
|
|
|
4
4
|
type SheetDetent = 'default' | 'full' | 'content';
|
|
5
5
|
type CommonProps = {
|
|
6
6
|
className?: string;
|
|
7
|
-
style?: CSSProperties;
|
|
8
7
|
unstyled?: boolean;
|
|
9
8
|
};
|
|
10
|
-
type MotionCommonProps = Omit<
|
|
11
|
-
type MotionDivProps = ComponentPropsWithoutRef<typeof motion.div>;
|
|
9
|
+
type MotionCommonProps = Omit<ComponentPropsWithoutRef<typeof motion.div>, 'initial' | 'animate' | 'exit'>;
|
|
12
10
|
interface SheetTweenConfig {
|
|
13
11
|
ease: EasingDefinition;
|
|
14
12
|
duration: number;
|
|
@@ -37,15 +35,15 @@ type SheetProps = {
|
|
|
37
35
|
onOpenEnd?: () => void;
|
|
38
36
|
onOpenStart?: () => void;
|
|
39
37
|
onSnap?: (index: number) => void;
|
|
40
|
-
} &
|
|
38
|
+
} & MotionCommonProps;
|
|
41
39
|
type SheetContainerProps = MotionCommonProps & CommonProps & {
|
|
42
40
|
children: ReactNode;
|
|
43
41
|
};
|
|
44
|
-
type SheetHeaderProps =
|
|
42
|
+
type SheetHeaderProps = MotionCommonProps & CommonProps & {
|
|
45
43
|
children?: ReactNode;
|
|
46
44
|
disableDrag?: boolean;
|
|
47
45
|
};
|
|
48
|
-
type SheetContentProps =
|
|
46
|
+
type SheetContentProps = MotionCommonProps & CommonProps & {
|
|
49
47
|
disableDrag?: boolean | ((args: SheetStateInfo) => boolean);
|
|
50
48
|
disableScroll?: boolean | ((args: SheetStateInfo) => boolean);
|
|
51
49
|
scrollRef?: RefObject<HTMLDivElement | null>;
|
|
@@ -83,4 +81,4 @@ interface SheetRef {
|
|
|
83
81
|
}
|
|
84
82
|
declare const Sheet: SheetCompound;
|
|
85
83
|
|
|
86
|
-
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetDragIndicatorProps, type SheetHeaderProps, type SheetProps, type SheetRef, type SheetSnapPoint, type SheetStateInfo };
|
|
84
|
+
export { Sheet, type SheetBackdropProps, type SheetContainerProps, type SheetContentProps, type SheetDetent, type SheetDragIndicatorProps, type SheetHeaderProps, type SheetProps, type SheetRef, type SheetSnapPoint, type SheetStateInfo, type SheetTweenConfig };
|
package/dist/index.js
CHANGED
|
@@ -188,6 +188,21 @@ var isIPad = cached(function() {
|
|
|
188
188
|
var isIOS = cached(function() {
|
|
189
189
|
return isIPhone() || isIPad();
|
|
190
190
|
});
|
|
191
|
+
function waitForElement(className, interval = 50, maxAttempts = 20) {
|
|
192
|
+
return new Promise((resolve) => {
|
|
193
|
+
let attempts = 0;
|
|
194
|
+
const timer = setInterval(() => {
|
|
195
|
+
const element = document.getElementsByClassName(
|
|
196
|
+
className
|
|
197
|
+
)[0];
|
|
198
|
+
attempts++;
|
|
199
|
+
if (element || attempts >= maxAttempts) {
|
|
200
|
+
clearInterval(timer);
|
|
201
|
+
resolve(element);
|
|
202
|
+
}
|
|
203
|
+
}, interval);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
191
206
|
|
|
192
207
|
// src/SheetBackdrop.tsx
|
|
193
208
|
var isClickable = (props) => !!props.onClick || !!props.onTap;
|
|
@@ -968,8 +983,20 @@ function computeSnapPoints({
|
|
|
968
983
|
snapPointsProp,
|
|
969
984
|
sheetHeight
|
|
970
985
|
}) {
|
|
986
|
+
if (snapPointsProp[0] !== 0) {
|
|
987
|
+
console.error(
|
|
988
|
+
`First snap point should be 0 to ensure the sheet can be fully closed. Got: [${snapPointsProp.join(", ")}]`
|
|
989
|
+
);
|
|
990
|
+
snapPointsProp.unshift(0);
|
|
991
|
+
}
|
|
992
|
+
if (snapPointsProp[snapPointsProp.length - 1] !== 1) {
|
|
993
|
+
console.error(
|
|
994
|
+
`Last snap point should be 1 to ensure the sheet can be fully opened. Got: [${snapPointsProp.join(", ")}]`
|
|
995
|
+
);
|
|
996
|
+
snapPointsProp.push(1);
|
|
997
|
+
}
|
|
971
998
|
if (sheetHeight <= 0) {
|
|
972
|
-
console.
|
|
999
|
+
console.error(
|
|
973
1000
|
`Sheet height is ${sheetHeight}, cannot compute snap points. Make sure the sheet is mounted and has a valid height.`
|
|
974
1001
|
);
|
|
975
1002
|
return [];
|
|
@@ -1263,6 +1290,7 @@ var Sheet = React4.forwardRef(
|
|
|
1263
1290
|
isOpen,
|
|
1264
1291
|
onOpen: async () => {
|
|
1265
1292
|
onOpenStart == null ? void 0 : onOpenStart();
|
|
1293
|
+
await waitForElement("react-modal-sheet-container");
|
|
1266
1294
|
const initialSnapPoint = initialSnap !== void 0 ? getSnapPoint(initialSnap) : null;
|
|
1267
1295
|
const yTo = (initialSnapPoint == null ? void 0 : initialSnapPoint.snapValueY) ?? 0;
|
|
1268
1296
|
await react.animate(y, yTo, animationOptions);
|